Skip to content

Commit

Permalink
Add support for gpt-4o-mini and o1-mini (SakanaAI#139)
Browse files Browse the repository at this point in the history
* update to the latest and add o1-mini models

* update o1 models to versioned names
  • Loading branch information
Godwinh19 authored Oct 21, 2024
1 parent e5b3d22 commit ca7a0c9
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions ai_scientist/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
"gpt-4o-mini-2024-07-18",
"gpt-4o-2024-05-13",
"gpt-4o-2024-08-06",
"o1-preview-2024-09-12",
"o1-mini-2024-09-12",
"deepseek-coder-v2-0724",
"llama3.1-405b",
# Anthropic Claude models via Amazon Bedrock
Expand Down Expand Up @@ -65,6 +67,24 @@ def get_batch_responses_from_llm(
new_msg_history = [
new_msg_history + [{"role": "assistant", "content": c}] for c in content
]
elif model in ["o1-preview-2024-09-12", "o1-mini-2024-09-12"]:
new_msg_history = msg_history + [{"role": "user", "content": msg}]
response = client.chat.completions.create(
model=model,
messages=[
{"role": "user", "content": system_message},
*new_msg_history,
],
temperature=1, #o1 only support temperature=1 at this time
max_completion_tokens=MAX_NUM_TOKENS, #max token is replaced by max completion tokens
n=n_responses,
#stop=None,
seed=0,
)
content = [r.message.content for r in response.choices]
new_msg_history = [
new_msg_history + [{"role": "assistant", "content": c}] for c in content
]
elif model == "deepseek-coder-v2-0724":
new_msg_history = msg_history + [{"role": "user", "content": msg}]
response = client.chat.completions.create(
Expand Down Expand Up @@ -191,6 +211,22 @@ def get_response_from_llm(
)
content = response.choices[0].message.content
new_msg_history = new_msg_history + [{"role": "assistant", "content": content}]
elif model in ["o1-preview-2024-09-12", "o1-mini-2024-09-12"]:
new_msg_history = msg_history + [{"role": "user", "content": msg}]
response = client.chat.completions.create(
model=model,
messages=[
{"role": "user", "content": system_message},
*new_msg_history,
],
temperature=1,
max_completion_tokens=MAX_NUM_TOKENS,
n=1,
#stop=None,
seed=0,
)
content = response.choices[0].message.content
new_msg_history = new_msg_history + [{"role": "assistant", "content": content}]
elif model == "deepseek-coder-v2-0724":
new_msg_history = msg_history + [{"role": "user", "content": msg}]
response = client.chat.completions.create(
Expand Down Expand Up @@ -279,6 +315,9 @@ def create_client(model):
elif 'gpt' in model:
print(f"Using OpenAI API with model {model}.")
return openai.OpenAI(), model
elif model in ["o1-preview-2024-09-12", "o1-mini-2024-09-12"]:
print(f"Using OpenAI API with model {model}.")
return openai.OpenAI(), model
elif model == "deepseek-coder-v2-0724":
print(f"Using OpenAI API with {model}.")
return openai.OpenAI(
Expand Down

0 comments on commit ca7a0c9

Please sign in to comment.