Skip to content

Commit 00a0020

Browse files
fix: o1 model KeyError (#1046)
Co-authored-by: Guohao Li <lightaime@gmail.com>
1 parent 439fd63 commit 00a0020

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

camel/models/openai_model.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# limitations under the License.
1313
# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
1414
import os
15+
import warnings
1516
from typing import Any, Dict, List, Optional, Union
1617

1718
from openai import OpenAI, Stream
@@ -96,13 +97,23 @@ def run(
9697
# o1-preview and o1-mini have Beta limitations
9798
# reference: https://platform.openai.com/docs/guides/reasoning
9899
if self.model_type in [ModelType.O1_MINI, ModelType.O1_PREVIEW]:
100+
warnings.warn(
101+
"Warning: You are using an O1 model (O1_MINI or O1_PREVIEW), "
102+
"which has certain limitations, reference: "
103+
"`https://platform.openai.com/docs/guides/reasoning`.",
104+
UserWarning,
105+
)
106+
99107
# Remove system message that is not supported in o1 model.
100108
messages = [msg for msg in messages if msg.get("role") != "system"]
101109

102-
# Remove unsupported parameters and reset the fixed parameters
103-
del self.model_config_dict["stream"]
104-
del self.model_config_dict["tools"]
105-
del self.model_config_dict["tool_choice"]
110+
# Check and remove unsupported parameters and reset the fixed
111+
# parameters
112+
unsupported_keys = ["stream", "tools", "tool_choice"]
113+
for key in unsupported_keys:
114+
if key in self.model_config_dict:
115+
del self.model_config_dict[key]
116+
106117
self.model_config_dict["temperature"] = 1.0
107118
self.model_config_dict["top_p"] = 1.0
108119
self.model_config_dict["n"] = 1.0

docs/CNAME

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)