Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OpenAI support for structured outputs #184

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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