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

openai[patch] get output_type when using with_structured_output #26307

Merged
merged 10 commits into from
Sep 13, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
x
  • Loading branch information
eyurtsev committed Sep 11, 2024
commit bff523b792a7a559651c6a8a300d722d5a33b171
17 changes: 17 additions & 0 deletions libs/partners/openai/tests/unit_tests/chat_models/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,3 +694,20 @@ def test_get_num_tokens_from_messages() -> None:
expected = 176
actual = llm.get_num_tokens_from_messages(messages)
assert expected == actual


def test_schema_from_with_structured_output() -> None:
"""Test schema from with_structured_output."""

class Foo(BaseModel):
bar: Any

model_chat = ChatOpenAI(api_key="foo")

model = model_chat.with_structured_output(Foo, method="json_schema", strict=True)

assert model.get_output_schema().schema() == {
"properties": {"bar": {"title": "Bar"}},
"title": "Foo",
"type": "object",
}