Skip to content

Conversation

trevbeers-thrive
Copy link

If response_format is passed as a kwarg, use client.beta.chat.completions.parse instead of client.beta.chat.completions.create.

Usage example:

import aisuite as ai
from pydantic import BaseModel

client = ai.Client()

class Joke(BaseModel):
    joke: str

messages = [
    {"role": "system", "content": "Respond in Pirate English."},
    {"role": "user", "content": "Tell me a joke."},
]

response = client.chat.completions.create(
    model="openai:gpt-4o",
    messages=messages,
    response_format=Joke,
    temperature=0.75
)
print(response.choices[0].message.content)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant