Skip to content

Commit

Permalink
openai[patch]: fix int test (#29395)
Browse files Browse the repository at this point in the history
  • Loading branch information
baskaryan authored Jan 23, 2025
1 parent 8d566a8 commit 317fb86
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 33 deletions.
2 changes: 1 addition & 1 deletion libs/partners/openai/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ test tests:
TIKTOKEN_CACHE_DIR=tiktoken_cache poetry run pytest --disable-socket --allow-unix-socket $(TEST_FILE)

integration_test integration_tests:
poetry run pytest $(TEST_FILE)
poetry run pytest -n auto $(TEST_FILE)

test_watch:
poetry run ptw --snapshot-update --now . -- -vv $(TEST_FILE)
Expand Down
36 changes: 35 additions & 1 deletion libs/partners/openai/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions libs/partners/openai/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pytest-watcher = "^0.3.4"
pytest-asyncio = "^0.21.1"
pytest-cov = "^4.1.0"
pytest-socket = "^0.6.0"
pytest-xdist = "^3.6.1"
[[tool.poetry.group.test.dependencies.numpy]]
version = "^1"
python = "<3.12"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
magic_function as invalid_magic_function,
)
from pydantic import BaseModel, Field
from typing_extensions import TypedDict

from langchain_openai import ChatOpenAI
from tests.unit_tests.fake.callbacks import FakeCallbackHandler
Expand Down Expand Up @@ -643,7 +642,7 @@ def test_disable_parallel_tool_calling() -> None:
assert len(result.tool_calls) == 1


@pytest.mark.parametrize("model", ["gpt-4o-mini", "o1"])
@pytest.mark.parametrize("model", ["gpt-4o-mini", "o1", "gpt-4"])
def test_openai_structured_output(model: str) -> None:
class MyModel(BaseModel):
"""A Person"""
Expand All @@ -658,24 +657,6 @@ class MyModel(BaseModel):
assert result.age == 27


def test_structured_output_errors_with_legacy_models() -> None:
class MyModel(BaseModel):
"""A Person"""

name: str
age: int

llm = ChatOpenAI(model="gpt-4").with_structured_output(MyModel)

with pytest.warns(UserWarning, match="with_structured_output"):
with pytest.raises(openai.BadRequestError):
_ = llm.invoke("I'm a 27 year old named Erick")

with pytest.warns(UserWarning, match="with_structured_output"):
with pytest.raises(openai.BadRequestError):
_ = list(llm.stream("I'm a 27 year old named Erick"))


def test_openai_proxy() -> None:
"""Test ChatOpenAI with proxy."""
chat_openai = ChatOpenAI(openai_proxy="http://localhost:8080")
Expand Down Expand Up @@ -1221,14 +1202,3 @@ def test_o1_doesnt_stream() -> None:
def test_o1_stream_default_works() -> None:
result = list(ChatOpenAI(model="o1").stream("say 'hi'"))
assert len(result) > 0


def test_structured_output_old_model() -> None:
class Output(TypedDict):
"""output."""

foo: str

llm = ChatOpenAI(model="gpt-4").with_structured_output(Output)
output = llm.invoke("bar")
assert "foo" in output

0 comments on commit 317fb86

Please sign in to comment.