JSON Mode
Example Code
import openai
# Initialize the OpenAI client with the Avian API
client = openai.Client(
api_key="your-api-key-here",
base_url="https://api.avian.io/v1"
)
# Define the function to call the API with JSON mode enabled
def get_response():
response = client.chat_completions.create(
model="Meta-Llama-3.1-405B-Instruct",
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 the JSON response
print(response.choices[0].message.content)
# Example usage
get_response()Note
Last updated