Skip to content

Commit eae4705

Browse files
committed
fix: tests
1 parent 91008c2 commit eae4705

File tree

8 files changed

+163
-6
lines changed

8 files changed

+163
-6
lines changed

docs/agents.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ async def main():
285285
system_prompts=(),
286286
system_prompt_functions=[],
287287
system_prompt_dynamic_functions={},
288+
response_prefix=None,
288289
),
289290
ModelRequestNode(
290291
request=ModelRequest(
@@ -349,6 +350,7 @@ async def main():
349350
system_prompts=(),
350351
system_prompt_functions=[],
351352
system_prompt_dynamic_functions={},
353+
response_prefix=None,
352354
),
353355
ModelRequestNode(
354356
request=ModelRequest(

pydantic_ai_slim/pydantic_ai/agent/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ async def main():
513513
system_prompts=(),
514514
system_prompt_functions=[],
515515
system_prompt_dynamic_functions={},
516+
response_prefix=None,
516517
),
517518
ModelRequestNode(
518519
request=ModelRequest(

pydantic_ai_slim/pydantic_ai/agent/abstract.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,7 @@ async def main():
644644
system_prompts=(),
645645
system_prompt_functions=[],
646646
system_prompt_dynamic_functions={},
647+
response_prefix=None,
647648
),
648649
ModelRequestNode(
649650
request=ModelRequest(

pydantic_ai_slim/pydantic_ai/agent/wrapper.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ async def main():
152152
system_prompts=(),
153153
system_prompt_functions=[],
154154
system_prompt_dynamic_functions={},
155+
response_prefix=None,
155156
),
156157
ModelRequestNode(
157158
request=ModelRequest(

pydantic_ai_slim/pydantic_ai/durable_exec/temporal/_agent.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,7 @@ async def main():
683683
system_prompts=(),
684684
system_prompt_functions=[],
685685
system_prompt_dynamic_functions={},
686+
response_prefix=None,
686687
),
687688
ModelRequestNode(
688689
request=ModelRequest(
@@ -692,7 +693,8 @@ async def main():
692693
timestamp=datetime.datetime(...),
693694
)
694695
]
695-
)
696+
),
697+
response_prefix=None,
696698
),
697699
CallToolsNode(
698700
model_response=ModelResponse(

pydantic_ai_slim/pydantic_ai/run.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ async def main():
5353
system_prompts=(),
5454
system_prompt_functions=[],
5555
system_prompt_dynamic_functions={},
56+
response_prefix=None,
5657
),
5758
ModelRequestNode(
5859
request=ModelRequest(
@@ -189,6 +190,7 @@ async def main():
189190
system_prompts=(),
190191
system_prompt_functions=[],
191192
system_prompt_dynamic_functions={},
193+
response_prefix=None,
192194
),
193195
ModelRequestNode(
194196
request=ModelRequest(
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
interactions:
2+
- request:
3+
headers:
4+
accept:
5+
- application/json
6+
accept-encoding:
7+
- gzip, deflate
8+
connection:
9+
- keep-alive
10+
content-length:
11+
- '215'
12+
content-type:
13+
- application/json
14+
host:
15+
- api.anthropic.com
16+
method: POST
17+
parsed_body:
18+
max_tokens: 4096
19+
messages:
20+
- content:
21+
- text: 'What is the name of color #FF0000'
22+
type: text
23+
role: user
24+
- content: It's name is
25+
role: assistant
26+
model: claude-3-5-sonnet-latest
27+
stream: false
28+
uri: https://api.anthropic.com/v1/messages?beta=true
29+
response:
30+
headers:
31+
connection:
32+
- keep-alive
33+
content-length:
34+
- '601'
35+
content-type:
36+
- application/json
37+
strict-transport-security:
38+
- max-age=31536000; includeSubDomains; preload
39+
transfer-encoding:
40+
- chunked
41+
parsed_body:
42+
content:
43+
- text: |2-
44+
Red. #FF0000 is the hexadecimal color code for pure red in RGB color space, where:
45+
- FF represents the maximum value (255) for the red channel
46+
- 00 represents no green
47+
- 00 represents no blue
48+
type: text
49+
id: msg_0139bvQ8xYiX5eFuQo2kt2uJ
50+
model: claude-3-5-sonnet-20241022
51+
role: assistant
52+
stop_reason: end_turn
53+
stop_sequence: null
54+
type: message
55+
usage:
56+
cache_creation:
57+
ephemeral_1h_input_tokens: 0
58+
ephemeral_5m_input_tokens: 0
59+
cache_creation_input_tokens: 0
60+
cache_read_input_tokens: 0
61+
input_tokens: 21
62+
output_tokens: 58
63+
service_tier: standard
64+
status:
65+
code: 200
66+
message: OK
67+
- request:
68+
headers:
69+
accept:
70+
- application/json
71+
accept-encoding:
72+
- gzip, deflate
73+
connection:
74+
- keep-alive
75+
content-length:
76+
- '186'
77+
content-type:
78+
- application/json
79+
host:
80+
- api.anthropic.com
81+
method: POST
82+
parsed_body:
83+
max_tokens: 4096
84+
messages:
85+
- content:
86+
- text: Hello
87+
type: text
88+
role: user
89+
- content: It's name is
90+
role: assistant
91+
model: claude-3-5-sonnet-latest
92+
stream: true
93+
uri: https://api.anthropic.com/v1/messages?beta=true
94+
response:
95+
body:
96+
string: |+
97+
event: message_start
98+
data: {"type":"message_start","message":{"id":"msg_01LrWvsWg9nVGu2ZAabNiKgH","type":"message","role":"assistant","model":"claude-3-5-sonnet-20241022","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":12,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":3,"service_tier":"standard"}} }
99+
100+
event: content_block_start
101+
data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} }
102+
103+
event: content_block_delta
104+
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" Claude. It"} }
105+
106+
event: content_block_delta
107+
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" was created by Anthropic and aims to be direct"} }
108+
109+
event: ping
110+
data: {"type": "ping"}
111+
112+
event: content_block_delta
113+
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" and honest in its interactions."} }
114+
115+
event: ping
116+
data: {"type": "ping"}
117+
118+
event: content_block_stop
119+
data: {"type":"content_block_stop","index":0 }
120+
121+
event: ping
122+
data: {"type": "ping"}
123+
124+
event: ping
125+
data: {"type": "ping"}
126+
127+
event: message_delta
128+
data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":12,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":23} }
129+
130+
event: message_stop
131+
data: {"type":"message_stop" }
132+
133+
headers:
134+
cache-control:
135+
- no-cache
136+
connection:
137+
- keep-alive
138+
content-type:
139+
- text/event-stream; charset=utf-8
140+
strict-transport-security:
141+
- max-age=31536000; includeSubDomains; preload
142+
transfer-encoding:
143+
- chunked
144+
status:
145+
code: 200
146+
message: OK
147+
version: 1
148+
...

tests/models/test_anthropic.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2726,19 +2726,19 @@ async def test_anthropic_response_prefix(allow_model_requests: None, anthropic_a
27262726
agent = Agent(m)
27272727

27282728
# Test non-streaming response
2729-
result = await agent.run('What is your favorite color?', response_prefix='My favorite color is')
2730-
assert result.output.startswith('My favorite color is')
2729+
result = await agent.run('What is the name of color #FF0000', response_prefix="It's name is")
2730+
assert result.output.startswith("It's name is")
27312731

27322732
# Test streaming response
27332733
event_parts: list[Any] = []
2734-
async with agent.iter(user_prompt='Hello', response_prefix='My favorite color is') as agent_run:
2734+
async with agent.iter(user_prompt='Hello', response_prefix="It's name is") as agent_run:
27352735
async for node in agent_run:
27362736
if Agent.is_model_request_node(node):
27372737
async with node.stream(agent_run.ctx) as request_stream:
27382738
async for event in request_stream:
27392739
event_parts.append(event)
27402740

2741-
# Check that the first text part starts with the prefix
2741+
# Check that the first text part xpstarts with the prefix
27422742
text_parts = [p for p in event_parts if isinstance(p, PartStartEvent) and isinstance(p.part, TextPart)]
27432743
assert len(text_parts) > 0
2744-
assert cast(TextPart, text_parts[0].part).content.startswith('My favorite color is')
2744+
assert cast(TextPart, text_parts[0].part).content.startswith("It's name is")

0 commit comments

Comments
 (0)