#How to make assistant return json from the function?
1 messages · Page 1 of 1 (latest)
Hi @harsh maple. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
Based on the information provided in the extracts, it seems that as of November 2023, JSON mode is not yet supported in the Assistants API (source (https://community.openai.com/t/486969)). This means that you might not be able to directly get a JSON output from the assistant.
However, if you're using the chat models like gpt-3.5-turbo-1106, you can use JSON mode to get a JSON object as a response. Here's an example from the OpenAI documentation (https://platform.openai.com/docs/guides/text-generation):
response = client.chat.completions.create(
model="gpt-3.5-turbo-1106",
response_format={ "type": "json_object" },
messages=[
{"role": "system", "content": "You are a helpful assistant designed to output JSON."},
{"role": "user", "content": "Who won the world series in 2020?"}
]
)
print(response.choices[0].message.content)
In this example, the response includes a JSON object that looks something like the following:
"content": "{\"winner\": \"Los Angeles Dodgers\"}"
Please note that this is not directly related to the Assistants API, but it might be a workaround depending on your use case.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@harsh maple kapa.ai is still learning and improving, please let us know how it did by reacting below
i am using assistants not completions
I think you have to ping the bot again.
you're right, looking somewhere else already haha
@barren elk i am using assistants not completions
Let me check the knowledge base for you. One moment! :books:
I'm sorry for the confusion. Based on the information provided in the extracts, there isn't a direct way to make an Assistant return a JSON from a function. The Assistants API is designed to return responses in a conversational format, rather than structured data like JSON.
However, you can parse the response from the Assistant in your application to extract the information you need. The response from the Assistant will be in a structured format that includes the role (system, user, or assistant) and the content of each message. You can use this structure to extract the information you need from the Assistant's responses.
Here's an example of what the response structure might look like:
{
'id': 'asst-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
'object': 'assistant',
'model': 'gpt-3.5-turbo',
'messages': [
{'role': 'system', 'content': 'You are a helpful assistant.'},
{'role': 'user', 'content': 'Who won the world series in 2020?'},
{'role': 'assistant', 'content': 'The Los Angeles Dodgers won the World Series in 2020.'}
]
}
In this example, you can extract the content of the assistant's message from the response.
Please note that this is a general approach and you might need to adjust it based on the specifics of your application and the exact format of the responses you're getting from the Assistant.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@harsh maple kapa.ai is still learning and improving, please let us know how it did by reacting below