Skip to content

Commit

Permalink
fix: o1 model KeyError (#1046)
Browse files Browse the repository at this point in the history
Co-authored-by: Guohao Li <[email protected]>
  • Loading branch information
Wendong-Fan and lightaime authored Oct 15, 2024
1 parent 439fd63 commit 00a0020
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
19 changes: 15 additions & 4 deletions camel/models/openai_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# limitations under the License.
# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
import os
import warnings
from typing import Any, Dict, List, Optional, Union

from openai import OpenAI, Stream
Expand Down Expand Up @@ -96,13 +97,23 @@ def run(
# 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]:
warnings.warn(
"Warning: You are using an O1 model (O1_MINI or O1_PREVIEW), "
"which has certain limitations, reference: "
"`https://platform.openai.com/docs/guides/reasoning`.",
UserWarning,
)

# 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"]
# Check and remove unsupported parameters and reset the fixed
# parameters
unsupported_keys = ["stream", "tools", "tool_choice"]
for key in unsupported_keys:
if key in self.model_config_dict:
del self.model_config_dict[key]

self.model_config_dict["temperature"] = 1.0
self.model_config_dict["top_p"] = 1.0
self.model_config_dict["n"] = 1.0
Expand Down
1 change: 0 additions & 1 deletion docs/CNAME

This file was deleted.

0 comments on commit 00a0020

Please sign in to comment.