standard-tests: add test for structured output (#23631)

- add test for structured output
- fix bug with structured output for Azure
- better testing on Groq (break out Mixtral + Llama3 and add xfails
where needed)
This commit is contained in:
ccurme
2024-06-28 15:01:40 -04:00
committed by GitHub
parent 6c1ba9731d
commit 390ee8d971
5 changed files with 326 additions and 21 deletions

View File

@@ -12,6 +12,7 @@ from langchain_core.messages import (
HumanMessage,
ToolMessage,
)
from langchain_core.pydantic_v1 import BaseModel, Field
from langchain_core.tools import tool
from langchain_standard_tests.unit_tests.chat_models import (
@@ -139,6 +140,20 @@ class ChatModelIntegrationTests(ChatModelTests):
assert isinstance(full, AIMessage)
_validate_tool_call_message(full)
def test_structured_output(self, model: BaseChatModel) -> None:
if not self.has_tool_calling:
pytest.skip("Test requires tool calling.")
class Joke(BaseModel):
"""Joke to tell user."""
setup: str = Field(description="question to set up a joke")
punchline: str = Field(description="answer to resolve the joke")
chat = model.with_structured_output(Joke)
result = chat.invoke("Tell me a joke about cats.")
assert isinstance(result, Joke)
def test_tool_message_histories_string_content(
self,
model: BaseChatModel,