Skip to content

Commit

Permalink
Refactor the OpenAI integration
Browse files Browse the repository at this point in the history
  • Loading branch information
rlouf committed Nov 20, 2023
1 parent 76cfc61 commit 0409e15
Show file tree
Hide file tree
Showing 9 changed files with 379 additions and 247 deletions.
2 changes: 1 addition & 1 deletion examples/math_generate_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ def execute_code(code):


prompt = answer_with_code_prompt(question, examples)
answer = models.openai("text-davinci-003")(prompt)
answer = models.openai("gpt-4")(prompt)
result = execute_code(answer)
print(f"It takes Carla {result:.0f} minutes to download the file.")
2 changes: 1 addition & 1 deletion examples/pick_odd_one_out.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def build_ooo_prompt(options):
"""


model = models.openai("text-davinci-003")
model = models.openai("gpt-3.5-turbo")

options = ["sea", "mountains", "plains", "sock"]
prompt = build_ooo_prompt(options)
Expand Down
8 changes: 5 additions & 3 deletions examples/react.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,19 @@ def search_wikipedia(query: str):


prompt = build_reAct_prompt("Where is Apple Computers headquarted? ")
complete = models.openai("gpt-3.5-turbo", temperature=1.0)
complete = models.openai("gpt-3.5-turbo")

for i in range(1, 10):
mode = complete(prompt, is_in=["Tho", "Act"], max_tokens=128)
mode = complete.generate_choice(prompt, choices=["Tho", "Act"], max_tokens=128)
prompt = add_mode(i, mode, "", prompt)

if mode == "Tho":
thought = complete(prompt, stop_at="\n", max_tokens=128)
prompt += f"{thought}"
elif mode == "Act":
action = complete(prompt, is_in=["Search", "Finish"], max_tokens=128)
action = complete.generate_choice(
prompt, choices=["Search", "Finish"], max_tokens=128
)
prompt += f"{action} '"

subject = complete(
Expand Down
2 changes: 1 addition & 1 deletion examples/self_consistency.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def few_shots(question, examples):
"""


model = models.openai("text-davinci-003")
model = models.openai("gpt-3.5-turbo")
prompt = few_shots(question, examples)
answers = model(prompt, samples=100)

Expand Down
2 changes: 1 addition & 1 deletion outlines/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
codebase.
"""
from .openai import OpenAIAPI, openai
from .openai import OpenAI, openai
from .transformers import Transformers, transformers
Loading

0 comments on commit 0409e15

Please sign in to comment.