-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Labels
bugSomething isn't workingSomething isn't working
Description
Initial Checks
- I confirm that I'm using the latest version of Pydantic AI
- I confirm that I searched for my issue in https://github.com/pydantic/pydantic-ai/issues before opening this issue
Description
When using an OpenAIChatModel and an event_stream_handler, the model_name field of the ModelResponse objects are empty for 1.0.3 <= pydantic_ai <= 1.0.8. It works as expected for version 1.0.2. It also works for newer versions if I'm not using an event handler.
The example code below illustrates the problem, (sorry for not revealing my AsyncAzureOpenAI client 😉).
Example Code
from collections.abc import AsyncIterable
from pydantic_ai import Agent, RunContext
from pydantic_ai.messages import AgentStreamEvent, ModelResponse
from pydantic_ai.models.openai import OpenAIChatModel
from pydantic_ai.providers.azure import AzureProvider
from my_own_app.llm_models import client
model = OpenAIChatModel(
model_name="gpt-4o-2024-05-13",
provider=AzureProvider(openai_client=client),
)
agent = Agent(model)
async def event_stream_handler(
_ctx: RunContext,
event_stream: AsyncIterable[AgentStreamEvent],
) -> None:
pass
response_with_handler = await agent.run(
"Who was Albert Einstein?",
event_stream_handler=event_stream_handler,
)
[
msg.cost()
for msg in response_with_handler.all_messages()
if isinstance(msg, ModelResponse)
]Python, Pydantic AI & LLM client version
python=3.13
pydantic_ai=1.0.8
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working