Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/message-history.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ print(result.all_messages())
parts=[
SystemPromptPart(
content='Be a helpful assistant.',
timestamp=datetime.datetime(...),
dynamic_ref=None,
part_kind='system-prompt',
),
Expand Down Expand Up @@ -89,6 +90,7 @@ async def main():
parts=[
SystemPromptPart(
content='Be a helpful assistant.',
timestamp=datetime.datetime(...),
dynamic_ref=None,
part_kind='system-prompt',
),
Expand Down Expand Up @@ -118,6 +120,7 @@ async def main():
parts=[
SystemPromptPart(
content='Be a helpful assistant.',
timestamp=datetime.datetime(...),
dynamic_ref=None,
part_kind='system-prompt',
),
Expand Down Expand Up @@ -175,6 +178,7 @@ print(result2.all_messages())
parts=[
SystemPromptPart(
content='Be a helpful assistant.',
timestamp=datetime.datetime(...),
dynamic_ref=None,
part_kind='system-prompt',
),
Expand Down Expand Up @@ -300,6 +304,7 @@ print(result2.all_messages())
parts=[
SystemPromptPart(
content='Be a helpful assistant.',
timestamp=datetime.datetime(...),
dynamic_ref=None,
part_kind='system-prompt',
),
Expand Down
1 change: 1 addition & 0 deletions docs/testing-evals.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ async def test_forecast():
parts=[
SystemPromptPart(
content='Providing a weather forecast at the locations the user provides.',
timestamp=IsNow(tz=timezone.utc),
),
UserPromptPart(
content='What will the weather be like in London on 2024-11-28?',
Expand Down
1 change: 1 addition & 0 deletions docs/tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ print(dice_result.all_messages())
parts=[
SystemPromptPart(
content="You're a dice game, you should roll the die and see if the number you get back matches the user's guess. If so, tell them they're a winner. Use the player's name in the response.",
timestamp=datetime.datetime(...),
dynamic_ref=None,
part_kind='system-prompt',
),
Expand Down
3 changes: 3 additions & 0 deletions pydantic_ai_slim/pydantic_ai/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class SystemPromptPart:
content: str
"""The content of the prompt."""

timestamp: datetime = field(default_factory=_now_utc)
"""The timestamp of the prompt."""

dynamic_ref: str | None = None
"""The ref of the dynamic system prompt function that generated this part.

Expand Down
2 changes: 1 addition & 1 deletion tests/models/test_anthropic.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ async def get_location(loc_name: str) -> str:
[
ModelRequest(
parts=[
SystemPromptPart(content='this is the system prompt'),
SystemPromptPart(content='this is the system prompt', timestamp=IsNow(tz=timezone.utc)),
UserPromptPart(content='hello', timestamp=IsNow(tz=timezone.utc)),
]
),
Expand Down
15 changes: 12 additions & 3 deletions tests/models/test_bedrock.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ async def test_bedrock_model(allow_model_requests: None, bedrock_provider: Bedro
[
ModelRequest(
parts=[
SystemPromptPart(content='You are a chatbot.'),
SystemPromptPart(
content='You are a chatbot.',
timestamp=IsDatetime(),
),
UserPromptPart(
content='Hello!',
timestamp=IsDatetime(),
Expand Down Expand Up @@ -122,7 +125,10 @@ async def temperature(city: str, date: datetime.date) -> str:
[
ModelRequest(
parts=[
SystemPromptPart(content='You are a helpful chatbot.'),
SystemPromptPart(
content='You are a helpful chatbot.',
timestamp=IsDatetime(),
),
UserPromptPart(
content='What was the temperature in London 1st January 2022?',
timestamp=IsDatetime(),
Expand Down Expand Up @@ -242,7 +248,10 @@ async def get_capital(country: str) -> str:
[
ModelRequest(
parts=[
SystemPromptPart(content='You are a helpful chatbot.'),
SystemPromptPart(
content='You are a helpful chatbot.',
timestamp=IsDatetime(),
),
UserPromptPart(
content='What is the capital of France?',
timestamp=IsDatetime(),
Expand Down
2 changes: 1 addition & 1 deletion tests/models/test_cohere.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ async def get_location(loc_name: str) -> str:
[
ModelRequest(
parts=[
SystemPromptPart(content='this is the system prompt'),
SystemPromptPart(content='this is the system prompt', timestamp=IsNow(tz=timezone.utc)),
UserPromptPart(content='Hello', timestamp=IsNow(tz=timezone.utc)),
]
),
Expand Down
2 changes: 1 addition & 1 deletion tests/models/test_gemini.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ async def get_location(loc_name: str) -> str:
[
ModelRequest(
parts=[
SystemPromptPart(content='this is the system prompt'),
SystemPromptPart(content='this is the system prompt', timestamp=IsNow(tz=timezone.utc)),
UserPromptPart(content='Hello', timestamp=IsNow(tz=timezone.utc)),
]
),
Expand Down
2 changes: 1 addition & 1 deletion tests/models/test_groq.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ async def get_location(loc_name: str) -> str:
[
ModelRequest(
parts=[
SystemPromptPart(content='this is the system prompt'),
SystemPromptPart(content='this is the system prompt', timestamp=IsNow(tz=timezone.utc)),
UserPromptPart(content='Hello', timestamp=IsNow(tz=timezone.utc)),
]
),
Expand Down
12 changes: 6 additions & 6 deletions tests/models/test_mistral.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ async def test_request_result_type_with_arguments_str_response(allow_model_reque
[
ModelRequest(
parts=[
SystemPromptPart(content='System prompt value'),
SystemPromptPart(content='System prompt value', timestamp=IsNow(tz=timezone.utc)),
UserPromptPart(content='User prompt value', timestamp=IsNow(tz=timezone.utc)),
]
),
Expand Down Expand Up @@ -1070,7 +1070,7 @@ async def get_location(loc_name: str) -> str:
[
ModelRequest(
parts=[
SystemPromptPart(content='this is the system prompt'),
SystemPromptPart(content='this is the system prompt', timestamp=IsNow(tz=timezone.utc)),
UserPromptPart(content='Hello', timestamp=IsNow(tz=timezone.utc)),
]
),
Expand Down Expand Up @@ -1207,7 +1207,7 @@ async def get_location(loc_name: str) -> str:
[
ModelRequest(
parts=[
SystemPromptPart(content='this is the system prompt'),
SystemPromptPart(content='this is the system prompt', timestamp=IsNow(tz=timezone.utc)),
UserPromptPart(content='Hello', timestamp=IsNow(tz=timezone.utc)),
]
),
Expand Down Expand Up @@ -1347,7 +1347,7 @@ async def get_location(loc_name: str) -> str:
[
ModelRequest(
parts=[
SystemPromptPart(content='this is the system prompt'),
SystemPromptPart(content='this is the system prompt', timestamp=IsNow(tz=timezone.utc)),
UserPromptPart(content='User prompt value', timestamp=IsNow(tz=timezone.utc)),
]
),
Expand Down Expand Up @@ -1447,7 +1447,7 @@ async def get_location(loc_name: str) -> str:
[
ModelRequest(
parts=[
SystemPromptPart(content='this is the system prompt'),
SystemPromptPart(content='this is the system prompt', timestamp=IsNow(tz=timezone.utc)),
UserPromptPart(content='User prompt value', timestamp=IsNow(tz=timezone.utc)),
]
),
Expand Down Expand Up @@ -1550,7 +1550,7 @@ async def get_location(loc_name: str) -> str:
[
ModelRequest(
parts=[
SystemPromptPart(content='this is the system prompt'),
SystemPromptPart(content='this is the system prompt', timestamp=IsNow(tz=timezone.utc)),
UserPromptPart(content='User prompt value', timestamp=IsNow(tz=timezone.utc)),
]
),
Expand Down
2 changes: 1 addition & 1 deletion tests/models/test_model_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ def test_call_all():
[
ModelRequest(
parts=[
SystemPromptPart(content='foobar'),
SystemPromptPart(content='foobar', timestamp=IsNow(tz=timezone.utc)),
UserPromptPart(content='Hello', timestamp=IsNow(tz=timezone.utc)),
]
),
Expand Down
2 changes: 1 addition & 1 deletion tests/models/test_openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ async def get_location(loc_name: str) -> str:
[
ModelRequest(
parts=[
SystemPromptPart(content='this is the system prompt'),
SystemPromptPart(content='this is the system prompt', timestamp=IsNow(tz=timezone.utc)),
UserPromptPart(content='Hello', timestamp=IsNow(tz=timezone.utc)),
]
),
Expand Down
25 changes: 15 additions & 10 deletions tests/test_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ async def ret_a(x: str) -> str:
[
ModelRequest(
parts=[
SystemPromptPart(content='Foobar'),
SystemPromptPart(content='Foobar', timestamp=IsNow(tz=timezone.utc)),
UserPromptPart(content='Hello', timestamp=IsNow(tz=timezone.utc)),
]
),
Expand All @@ -538,7 +538,7 @@ async def ret_a(x: str) -> str:
[
ModelRequest(
parts=[
SystemPromptPart(content='Foobar'),
SystemPromptPart(content='Foobar', timestamp=IsNow(tz=timezone.utc)),
UserPromptPart(content='Hello', timestamp=IsNow(tz=timezone.utc)),
]
),
Expand Down Expand Up @@ -586,7 +586,7 @@ async def ret_a(x: str) -> str:
[
ModelRequest(
parts=[
SystemPromptPart(content='Foobar'),
SystemPromptPart(content='Foobar', timestamp=IsNow(tz=timezone.utc)),
UserPromptPart(content='Hello', timestamp=IsNow(tz=timezone.utc)),
]
),
Expand Down Expand Up @@ -632,7 +632,7 @@ async def ret_a(x: str) -> str:
[
ModelRequest(
parts=[
SystemPromptPart(content='Foobar'),
SystemPromptPart(content='Foobar', timestamp=IsNow(tz=timezone.utc)),
UserPromptPart(content='Hello', timestamp=IsNow(tz=timezone.utc)),
]
),
Expand Down Expand Up @@ -670,7 +670,7 @@ async def ret_a(x: str) -> str:
[
ModelRequest(
parts=[
SystemPromptPart(content='Foobar'),
SystemPromptPart(content='Foobar', timestamp=IsNow(tz=timezone.utc)),
UserPromptPart(content='Hello', timestamp=IsNow(tz=timezone.utc)),
],
),
Expand Down Expand Up @@ -1374,8 +1374,10 @@ async def func() -> str:
[
ModelRequest(
parts=[
SystemPromptPart(content='Foobar', part_kind='system-prompt'),
SystemPromptPart(content=dynamic_value, part_kind='system-prompt'),
SystemPromptPart(content='Foobar', part_kind='system-prompt', timestamp=IsNow(tz=timezone.utc)),
SystemPromptPart(
content=dynamic_value, part_kind='system-prompt', timestamp=IsNow(tz=timezone.utc)
),
UserPromptPart(content='Hello', timestamp=IsNow(tz=timezone.utc), part_kind='user-prompt'),
],
kind='request',
Expand All @@ -1397,10 +1399,11 @@ async def func() -> str:
[
ModelRequest(
parts=[
SystemPromptPart(content='Foobar', part_kind='system-prompt'),
SystemPromptPart(content='Foobar', part_kind='system-prompt', timestamp=IsNow(tz=timezone.utc)),
SystemPromptPart(
content='A', # Remains the same
part_kind='system-prompt',
timestamp=IsNow(tz=timezone.utc),
),
UserPromptPart(content='Hello', timestamp=IsNow(tz=timezone.utc), part_kind='user-prompt'),
],
Expand Down Expand Up @@ -1446,11 +1449,12 @@ async def func():
[
ModelRequest(
parts=[
SystemPromptPart(content='Foobar', part_kind='system-prompt'),
SystemPromptPart(content='Foobar', part_kind='system-prompt', timestamp=IsNow(tz=timezone.utc)),
SystemPromptPart(
content=dynamic_value,
part_kind='system-prompt',
dynamic_ref=func.__qualname__,
timestamp=IsNow(tz=timezone.utc),
),
UserPromptPart(content='Hello', timestamp=IsNow(tz=timezone.utc), part_kind='user-prompt'),
],
Expand All @@ -1473,11 +1477,12 @@ async def func():
[
ModelRequest(
parts=[
SystemPromptPart(content='Foobar', part_kind='system-prompt'),
SystemPromptPart(content='Foobar', part_kind='system-prompt', timestamp=IsNow(tz=timezone.utc)),
SystemPromptPart(
content='B',
part_kind='system-prompt',
dynamic_ref=func.__qualname__,
timestamp=IsNow(tz=timezone.utc),
),
UserPromptPart(content='Hello', timestamp=IsNow(tz=timezone.utc), part_kind='user-prompt'),
],
Expand Down