File tree Expand file tree Collapse file tree 2 files changed +24
-2
lines changed Expand file tree Collapse file tree 2 files changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -93,6 +93,22 @@ def run(
93
93
`ChatCompletion` in the non-stream mode, or
94
94
`Stream[ChatCompletionChunk]` in the stream mode.
95
95
"""
96
+ # o1-preview and o1-mini have Beta limitations
97
+ # reference: https://platform.openai.com/docs/guides/reasoning
98
+ if self .model_type in [ModelType .O1_MINI , ModelType .O1_PREVIEW ]:
99
+ # Remove system message that is not supported in o1 model.
100
+ messages = [msg for msg in messages if msg .get ("role" ) != "system" ]
101
+
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" ]
106
+ self .model_config_dict ["temperature" ] = 1.0
107
+ self .model_config_dict ["top_p" ] = 1.0
108
+ self .model_config_dict ["n" ] = 1.0
109
+ self .model_config_dict ["presence_penalty" ] = 0.0
110
+ self .model_config_dict ["frequency_penalty" ] = 0.0
111
+
96
112
response = self ._client .chat .completions .create (
97
113
messages = messages ,
98
114
model = self .model_type .value ,
Original file line number Diff line number Diff line change @@ -193,8 +193,14 @@ def get_model_encoding(value_for_tiktoken: str):
193
193
try :
194
194
encoding = tiktoken .encoding_for_model (value_for_tiktoken )
195
195
except KeyError :
196
- print ("Model not found. Using cl100k_base encoding." )
197
- encoding = tiktoken .get_encoding ("cl100k_base" )
196
+ if value_for_tiktoken in [
197
+ ModelType .O1_MINI .value ,
198
+ ModelType .O1_PREVIEW .value ,
199
+ ]:
200
+ encoding = tiktoken .get_encoding ("o200k_base" )
201
+ else :
202
+ print ("Model not found. Using cl100k_base encoding." )
203
+ encoding = tiktoken .get_encoding ("cl100k_base" )
198
204
return encoding
199
205
200
206
You can’t perform that action at this time.
0 commit comments