crewAI
crewAI copied to clipboard
JSON formatted Agent output
Is there a way to use model_kwargs, output_format, or anything like this to get OpenAIs JSON mode? I don't want to format data after it comes back, I want it specifically provided as JSON.
Example code from OpenAI docu: https://platform.openai.com/docs/guides/text-generation/json-mode
from openai import OpenAI
client = OpenAI()
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)
Is there a way to utilize that with CrewAI Agents? I'm using langchain_openai and gpt-4-1106-preview as llm model.
In the mean time, you can ask explicitly to return JSON and provide an example. That already works 99% of the time without the official JSON flag.
Perhaps we can just add something like this:
chat = ChatOpenAI(model="gpt-3.5-turbo-1106").bind(
response_format={"type": "json_object"}
)
Somewhere around here.