#API request returning choices[0]message with {content: None}

3 messages · Page 1 of 1 (latest)

acoustic blade
#

Im trying to get gpt to return a A,B,C,D MC question for the meaning of a passed in word (in a non english language).

I implemented like so:
functions = [
{
"name": "get_word_quiz",
"description": "Get one multiple choice question for the meaning of the spanish word",
"parameters": {
"type": "object",
"properties": {
"word": {
"type": "string",
"description": "A spanish word, e.g. Bien",
},
"multiple_choice_question": {"type": "string"},
},
"required": ["word"],
},
}
]

messages = [{"role": "user", "content": "word quiz for: demasiado"}]

headers = {
"Content-Type": "application/json",
"Authorization": "Bearer " + openai.api_key,
}
json_data = {"model": "gpt-3.5-turbo-0613", "messages": messages, "functions": functions, "function_call": {"name": "get_word_quiz"}}

response = requests.post(
"https://api.openai.com/v1/chat/completions",
headers=headers,
json=json_data,
)

However, when I run the code I get the following response with no content or text being returned:

{'id': '...', 'object': 'chat.completion', 'created': 1688348071, 'model': 'gpt-3.5-turbo-0613', 'choices': [{'index': 0, 'message': {'role': 'assistant', 'content': None, 'function_call': {'name': 'get_word_quiz', 'arguments': '{\n "word": "demasiado"\n}'}}, 'finish_reason': 'stop'}], 'usage': {'prompt_tokens': 82, 'completion_tokens': 11, 'total_tokens': 93}}

Is there something I am missing here?
(Also, is there any way to shorten the prompt so that I can just call the function with the arguments? Something like {"role": "user", "content": "word_quiz('demasiado')"}

Or specifically a list of words where returns a question for each word "content": "word_quiz(['demasiado', 'perdido', 'hola'])"}

Please let me know, thanks!

wind pumice
#

Hey - did you find a solution to that? I'm in a similar situation 😕

woven scroll
#

Content is none because it's doing the function call trigger. But if that's your whole code, it's trying to trigger the function but you don't have the actual function for it to trigger.