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

feat(structured outputs): add support for accessing raw responses #1748

Merged
merged 6 commits into from
Sep 26, 2024

Conversation

RobertCraigie
Copy link
Collaborator

@RobertCraigie RobertCraigie commented Sep 26, 2024

You can now access the raw response for the structured outputs .parse() helper.

response = client.beta.chat.completions.with_raw_response.parse(
    model="gpt-4o-2024-08-06",
    messages=[
        {"role": "system", "content": "You are a helpful math tutor."},
        {"role": "user", "content": "solve 8x + 31 = 2"},
    ],
    response_format=MathResponse,
)
print(response.headers.get("x-my-header"))

completion = response.parse()

message = completion.choices[0].message
if message.parsed:
    rich.print(message.parsed.steps)

    print("answer: ", message.parsed.final_answer)
else:
    print(message.refusal)

@RobertCraigie RobertCraigie changed the base branch from next to main September 26, 2024 10:19
@stainless-bot stainless-bot force-pushed the robert/structured-outputs-raw-response branch from a8cae90 to 45d4328 Compare September 26, 2024 10:43
@stainless-bot stainless-bot force-pushed the robert/structured-outputs-raw-response branch from 246f606 to 1cbba60 Compare September 26, 2024 22:17
@RobertCraigie RobertCraigie changed the base branch from main to next September 26, 2024 22:26
@stainless-bot stainless-bot force-pushed the robert/structured-outputs-raw-response branch from 058565e to 46fb7fb Compare September 26, 2024 22:26
This reverts commit 46fb7fb.
@RobertCraigie RobertCraigie marked this pull request as ready for review September 26, 2024 22:32
@RobertCraigie RobertCraigie requested a review from a team as a code owner September 26, 2024 22:32
@RobertCraigie RobertCraigie merged commit 0189e28 into next Sep 26, 2024
@RobertCraigie RobertCraigie deleted the robert/structured-outputs-raw-response branch September 26, 2024 22:32
@stainless-app stainless-app bot mentioned this pull request Sep 26, 2024
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