-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix how quotes are parsed in json (#2189)
## Description When we have agents that respond with JSON with quotes in the fields, then it breaks parsing. This fixes that. Fixes #2128
- Loading branch information
Showing
4 changed files
with
213 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
libs/agno/tests/integration/agent/test_structured_output_parsing.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from typing import List | ||
|
||
from pydantic import BaseModel, Field | ||
|
||
from agno.agent import Agent, RunResponse # noqa | ||
from agno.models.openai.chat import OpenAIChat # noqa | ||
|
||
|
||
def test_structured_output_parsing_with_quotes(): | ||
class MovieScript(BaseModel): | ||
script: str = Field(..., description="The script of the movie.") | ||
name: str = Field(..., description="Give a name to this movie") | ||
characters: List[str] = Field(..., description="Name of characters for this movie.") | ||
|
||
movie_agent = Agent( | ||
model=OpenAIChat(id="gpt-4o-mini"), | ||
description="You help people write movie scripts. Always add some example dialog in your scripts in double quotes.", | ||
response_model=MovieScript, | ||
) | ||
|
||
# Get the response in a variable | ||
response: RunResponse = movie_agent.run("New York") | ||
# Verify structured output | ||
assert isinstance(response.content, MovieScript) | ||
assert response.content.script is not None | ||
assert response.content.name is not None | ||
assert response.content.characters is not None |
Oops, something went wrong.