@@ -259,6 +259,7 @@ def _append_oai_message(self, message: Union[Dict, str], role, conversation_id:
259
259
If the message received is a string, it will be put in the "content" field of the new dictionary.
260
260
If the message received is a dictionary but does not have any of the two fields "content" or "function_call",
261
261
this message is not a valid ChatCompletion message.
262
+ If only "function_call" is provided, "content" will be set to None if not provided, and the role of the message will be forced "assistant".
262
263
263
264
Args:
264
265
message (dict or str): message to be appended to the ChatCompletion conversation.
@@ -271,10 +272,15 @@ def _append_oai_message(self, message: Union[Dict, str], role, conversation_id:
271
272
message = self ._message_to_dict (message )
272
273
# create oai message to be appended to the oai conversation that can be passed to oai directly.
273
274
oai_message = {k : message [k ] for k in ("content" , "function_call" , "name" , "context" ) if k in message }
274
- if "content" not in oai_message and "function_call" not in oai_message :
275
- return False
275
+ if "content" not in oai_message :
276
+ if "function_call" in oai_message :
277
+ oai_message ["content" ] = None # if only function_call is provided, content will be set to None.
278
+ else :
279
+ return False
276
280
277
281
oai_message ["role" ] = "function" if message .get ("role" ) == "function" else role
282
+ if "function_call" in oai_message :
283
+ oai_message ["role" ] = "assistant" # only messages with role 'assistant' can have a function call.
278
284
self ._oai_messages [conversation_id ].append (oai_message )
279
285
return True
280
286
@@ -289,8 +295,8 @@ def send(
289
295
290
296
Args:
291
297
message (dict or str): message to be sent.
292
- The message could contain the following fields (either content or function_call must be provided) :
293
- - content (str): the content of the message.
298
+ The message could contain the following fields:
299
+ - content (str): Required, the content of the message. (Can be None)
294
300
- function_call (str): the name of the function to be called.
295
301
- name (str): the name of the function to be called.
296
302
- role (str): the role of the message, any role that is not "function"
@@ -338,8 +344,8 @@ async def a_send(
338
344
339
345
Args:
340
346
message (dict or str): message to be sent.
341
- The message could contain the following fields (either content or function_call must be provided) :
342
- - content (str): the content of the message.
347
+ The message could contain the following fields:
348
+ - content (str): Required, the content of the message. (Can be None)
343
349
- function_call (str): the name of the function to be called.
344
350
- name (str): the name of the function to be called.
345
351
- role (str): the role of the message, any role that is not "function"
0 commit comments