@@ -115,10 +115,8 @@ def invoke(
115
115
try :
116
116
if isinstance (message_history , MessageHistory ):
117
117
message_history = message_history .messages
118
- # We know these are compatible with OpenAI's API at runtime
119
- messages = self .get_messages (input , message_history , system_instruction )
120
118
response = self .client .chat .completions .create (
121
- messages = messages ,
119
+ messages = self . get_messages ( input , message_history , system_instruction ) ,
122
120
model = self .model_name ,
123
121
** self .model_params ,
124
122
)
@@ -158,15 +156,13 @@ def invoke_with_tools(
158
156
if "temperature" not in params :
159
157
params ["temperature" ] = 0.0
160
158
161
- # We know these are compatible with OpenAI's API at runtime
162
- messages = self .get_messages (input , message_history , system_instruction )
163
159
# Convert tools to OpenAI's expected type
164
160
openai_tools : List [ChatCompletionToolParam ] = []
165
161
for tool in tools :
166
162
openai_tools .append (cast (ChatCompletionToolParam , tool ))
167
163
168
164
response = self .client .chat .completions .create (
169
- messages = messages ,
165
+ messages = self . get_messages ( input , message_history , system_instruction ) ,
170
166
model = self .model_name ,
171
167
tools = openai_tools ,
172
168
tool_choice = "auto" ,
@@ -226,10 +222,8 @@ async def ainvoke(
226
222
try :
227
223
if isinstance (message_history , MessageHistory ):
228
224
message_history = message_history .messages
229
- # We know these are compatible with OpenAI's API at runtime
230
- messages = self .get_messages (input , message_history , system_instruction )
231
225
response = await self .async_client .chat .completions .create (
232
- messages = messages ,
226
+ messages = self . get_messages ( input , message_history , system_instruction ) ,
233
227
model = self .model_name ,
234
228
** self .model_params ,
235
229
)
@@ -269,15 +263,13 @@ async def ainvoke_with_tools(
269
263
if "temperature" not in params :
270
264
params ["temperature" ] = 0.0
271
265
272
- # We know these are compatible with OpenAI's API at runtime
273
- messages = self .get_messages (input , message_history , system_instruction )
274
266
# Convert tools to OpenAI's expected type
275
267
openai_tools : List [ChatCompletionToolParam ] = []
276
268
for tool in tools :
277
269
openai_tools .append (cast (ChatCompletionToolParam , tool ))
278
270
279
271
response = await self .async_client .chat .completions .create (
280
- messages = messages ,
272
+ messages = self . get_messages ( input , message_history , system_instruction ) ,
281
273
model = self .model_name ,
282
274
tools = openai_tools ,
283
275
tool_choice = "auto" ,
0 commit comments