openai[patch]: fix int test (#29395)

This commit is contained in:
Bagatur
2025-01-23 13:23:01 -08:00
committed by GitHub
parent 8d566a8fe7
commit 317fb86fd9
4 changed files with 38 additions and 33 deletions

View File

@@ -27,7 +27,6 @@ from langchain_tests.integration_tests.chat_models import (
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
@@ -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"""
@@ -658,24 +657,6 @@ def test_openai_structured_output(model: str) -> None:
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")
@@ -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