Skip to content

armgit / camel

Public Imported from GitHub
0

🐫 CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org

chore: reset and remove unsupported parameters in o1 model (#945)

mrsbeep966b6c573203
diff --git a/camel/models/openai_model.py b/camel/models/openai_model.py
index 9edd2f190..f6185cb45 100644
--- a/camel/models/openai_model.py
+++ b/camel/models/openai_model.py
@@ -93,6 +93,22 @@ class OpenAIModel(BaseModelBackend):
`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,
diff --git a/camel/utils/token_counting.py b/camel/utils/token_counting.py
index 1cc243989..70bbc2c7b 100644
--- a/camel/utils/token_counting.py
+++ b/camel/utils/token_counting.py
@@ -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