Structured Outputs
Enabling JSON Output allows users to get structured responses from Arcee AI models. The JSON Output ensures the model outputs valid JSON strings.
JSON Output Example
import json
from openai import OpenAI
client = OpenAI(
api_key="afm-13cf46d35fd48a6aa2da4c8d62424de8",
base_url="https://api.arcee.ai/api/v1"
)
system_prompt = """
The user will provide some exam text. Please parse the "question" and "answer" and output them in JSON format.
EXAMPLE INPUT:
Which is the highest mountain in the world? Mount Everest.
EXAMPLE JSON OUTPUT:
{
"question": "What is the capital of France?",
"answer": "Paris"
}
"""
user_prompt = "What is the capital of Italy?"
messages = [{"role": "system", "content": system_prompt},
{"role": "user", "content": user_prompt}]
response = client.chat.completions.create(
model="arcee-ai/AFM-4.5B",
messages=messages,
response_format={
'type': 'json_object'
}
)
print(json.loads(response.choices[0].message.content))Last updated

