Skip to content

Commit

Permalink
chore: reset and remove unsupported parameters in o1 model (#945)
Browse files Browse the repository at this point in the history
Co-authored-by: Wendong-Fan <133094783+Wendong-Fan@users.noreply.github.com>
  • Loading branch information
mrsbeep and Wendong-Fan authored Sep 14, 2024
1 parent 0a4fcaa commit 966b6c5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
16 changes: 16 additions & 0 deletions camel/models/openai_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,22 @@ def run(
`ChatCompletion` in the non-stream mode, or
`Stream[ChatCompletionChunk]` in the stream mode.
"""
# o1-preview and o1-mini have Beta limitations
# reference: https://platform.openai.com/docs/guides/reasoning
if self.model_type in [ModelType.O1_MINI, ModelType.O1_PREVIEW]:
# Remove system message that is not supported in o1 model.
messages = [msg for msg in messages if msg.get("role") != "system"]

# Remove unsupported parameters and reset the fixed parameters
del self.model_config_dict["stream"]
del self.model_config_dict["tools"]
del self.model_config_dict["tool_choice"]
self.model_config_dict["temperature"] = 1.0
self.model_config_dict["top_p"] = 1.0
self.model_config_dict["n"] = 1.0
self.model_config_dict["presence_penalty"] = 0.0
self.model_config_dict["frequency_penalty"] = 0.0

response = self._client.chat.completions.create(
messages=messages,
model=self.model_type.value,
Expand Down
10 changes: 8 additions & 2 deletions camel/utils/token_counting.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,14 @@ def get_model_encoding(value_for_tiktoken: str):
try:
encoding = tiktoken.encoding_for_model(value_for_tiktoken)
except KeyError:
print("Model not found. Using cl100k_base encoding.")
encoding = tiktoken.get_encoding("cl100k_base")
if value_for_tiktoken in [
ModelType.O1_MINI.value,
ModelType.O1_PREVIEW.value,
]:
encoding = tiktoken.get_encoding("o200k_base")
else:
print("Model not found. Using cl100k_base encoding.")
encoding = tiktoken.get_encoding("cl100k_base")
return encoding


Expand Down

0 comments on commit 966b6c5

Please sign in to comment.