-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Open
Labels
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
After opening #2797 and fixing it in #2798, I ran into more typing problems that can be traced to using the invariant list[ModelMessage]
.
Example Code
from pydantic_ai.direct import model_request_sync
from pydantic_ai.messages import ModelRequest, SystemPromptPart, UserPromptPart
from pydantic_ai.models.openai import OpenAIChatModel
model = OpenAIChatModel('gpt-4.1-mini')
messages = [
ModelRequest(
parts=[
SystemPromptPart(content='You are a helpful assistant.'),
UserPromptPart(content='What is the capital of France?'),
]
),
]
model_request_sync(
model=model,
messages=messages,
)
# (pydantic-ai) ➜ pydantic-ai git:(main) ✗ uv run pyright mre.py
# /home/moritz/Documents/pydantic-ai/mre.py
# /home/moritz/Documents/pydantic-ai/mre.py:18:14 - error: Argument of type "list[ModelRequest]" cannot be assigned to parameter "messages" of type "list[ModelMessage]" in function "model_request_sync"
# "list[ModelRequest]" is not assignable to "list[ModelMessage]"
# Type parameter "_T@list" is invariant, but "ModelRequest" is not the same as "ModelMessage"
# Consider switching from "list" to "Sequence" which is covariant (reportArgumentType)
# 1 error, 0 warnings, 0 informations
Python, Pydantic AI & LLM client version
`pydantic-ai==1.0.8`