I recently implemented function calling in a project I am working on and am getting some weird output. My understanding is that when I call ‘chat.completion’ with a 0613 model such as gpt-3.5-0613 and I include function descriptions for the functions parameter, that it should return the name of the function to call here:
response = openai.ChatCompletion.create(
model=model,
messages=messages,
functions=functions,
temperature=0
)
response_message = response["choices"][0]["message"]["function_call"]["name"]
For some queries, even when calling chat completion from an appropriate model, and including functions = my_functions to populate the functions paramater, I am sometimes getting back the function selection in the content field, with no function_call field populated at all.
For example:
[{'name': 'generate_sql', 'description': 'function used to generate the relevant sql to fulfill user request. use when the user wants to query the database or reference information in the database', 'parameters': {'type': 'object', 'properties': {'user_prompt': {'type': 'string', 'description': "the user's query to the database ex. 'How many shipments are in the database? What was our profit for the month of may 2023?'"}}, 'required': ['user_prompt']}},
{'name': 'reference_memory', 'description': 'function that references previous hsitory of the conversation to answer user query. conversation history contains summaries about previous topics discussed', 'parameters': {'type': 'object', 'properties': {'user_prompt': {'type': 'string', 'description': "the user's query to the conversation history. ex. 'What did I just ask you? What does that data mean? Can you identify any trends there?'"}}, 'required': ['user_prompt']}}]
{
"id": "chatcmpl-7W9ovBd5AhhY1K9dYooxeHuFZspl3",
"object": "chat.completion",
"created": 1687898601,
"model": "gpt-3.5-turbo-0613",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "reference_memory"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 285,
"completion_tokens": 3,
"total_tokens": 288
}
}
As you can see the name of the function to call populates under ‘content’ and does not create a function_call key, even though I used the appropriate model, and included information for the functions parameter.
Any ideas what could be the cause of this? Is it a bug in the function-calling feature?