Skip to content

Commit cbc6d57

Browse files
authored
Use AsyncBeta instead of AsyncAnthropic (#1818)
1 parent 2baf146 commit cbc6d57

12 files changed

+398
-3142
lines changed

pydantic_ai_slim/pydantic_ai/models/anthropic.py

Lines changed: 78 additions & 73 deletions
Large diffs are not rendered by default.

tests/cassettes/test_settings/test_stop_settings[anthropic].yaml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,24 @@ interactions:
2525
stop_sequences:
2626
- Paris
2727
stream: false
28-
uri: https://api.anthropic.com/v1/messages
28+
uri: https://api.anthropic.com/v1/messages?beta=true
2929
response:
3030
headers:
3131
connection:
3232
- keep-alive
3333
content-length:
34-
- '333'
34+
- '359'
3535
content-type:
3636
- application/json
37+
strict-transport-security:
38+
- max-age=31536000; includeSubDomains; preload
3739
transfer-encoding:
3840
- chunked
3941
parsed_body:
4042
content:
4143
- text: 'The capital of France is '
4244
type: text
43-
id: msg_01FfkgikmbDFzn9XE1YYkJmA
45+
id: msg_01SVFZqkSLhUPkAA4w6rhzFD
4446
model: claude-3-5-sonnet-20241022
4547
role: assistant
4648
stop_reason: stop_sequence
@@ -51,6 +53,7 @@ interactions:
5153
cache_read_input_tokens: 0
5254
input_tokens: 14
5355
output_tokens: 6
56+
service_tier: standard
5457
status:
5558
code: 200
5659
message: OK

tests/models/cassettes/test_anthropic/test_anthropic_model_instructions.yaml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ interactions:
88
connection:
99
- keep-alive
1010
content-length:
11-
- '202'
11+
- '206'
1212
content-type:
1313
- application/json
1414
host:
@@ -23,23 +23,27 @@ interactions:
2323
role: user
2424
model: claude-3-opus-latest
2525
stream: false
26-
system: You are a helpful assistant.
27-
uri: https://api.anthropic.com/v1/messages
26+
system: |+
27+
You are a helpful assistant.
28+
29+
uri: https://api.anthropic.com/v1/messages?beta=true
2830
response:
2931
headers:
3032
connection:
3133
- keep-alive
3234
content-length:
33-
- '328'
35+
- '354'
3436
content-type:
3537
- application/json
38+
strict-transport-security:
39+
- max-age=31536000; includeSubDomains; preload
3640
transfer-encoding:
3741
- chunked
3842
parsed_body:
3943
content:
4044
- text: The capital of France is Paris.
4145
type: text
42-
id: msg_01U58nruzfn9BrXrrF2hhb4m
46+
id: msg_01BznVNBje2zyfpCfNQCD5en
4347
model: claude-3-opus-20240229
4448
role: assistant
4549
stop_reason: end_turn
@@ -50,7 +54,9 @@ interactions:
5054
cache_read_input_tokens: 0
5155
input_tokens: 20
5256
output_tokens: 10
57+
service_tier: standard
5358
status:
5459
code: 200
5560
message: OK
5661
version: 1
62+
...

tests/models/cassettes/test_anthropic/test_document_binary_content_input.yaml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,24 @@ interactions:
2828
role: user
2929
model: claude-3-5-sonnet-latest
3030
stream: false
31-
uri: https://api.anthropic.com/v1/messages
31+
uri: https://api.anthropic.com/v1/messages?beta=true
3232
response:
3333
headers:
3434
connection:
3535
- keep-alive
3636
content-length:
37-
- '502'
37+
- '433'
3838
content-type:
3939
- application/json
40+
strict-transport-security:
41+
- max-age=31536000; includeSubDomains; preload
4042
transfer-encoding:
4143
- chunked
4244
parsed_body:
4345
content:
44-
- text: The document appears to be a simple PDF file with only the text "Dummy PDF file" displayed at the top. It appears
45-
to be mostly blank otherwise, likely serving as a template or placeholder document.
46+
- text: The document shows only the text "Dummy PDF file" at the top of what appears to be a blank white page.
4647
type: text
47-
id: msg_01MV5d7ebPBUzPV5DerCiRFS
48+
id: msg_01Jr6x34UmKgzgrJE96jaYpm
4849
model: claude-3-5-sonnet-20241022
4950
role: assistant
5051
stop_reason: end_turn
@@ -54,7 +55,8 @@ interactions:
5455
cache_creation_input_tokens: 0
5556
cache_read_input_tokens: 0
5657
input_tokens: 1615
57-
output_tokens: 44
58+
output_tokens: 28
59+
service_tier: standard
5860
status:
5961
code: 200
6062
message: OK

tests/models/cassettes/test_anthropic/test_document_url_input.yaml

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,28 @@ interactions:
2727
role: user
2828
model: claude-3-5-sonnet-latest
2929
stream: false
30-
uri: https://api.anthropic.com/v1/messages
30+
uri: https://api.anthropic.com/v1/messages?beta=true
3131
response:
3232
headers:
3333
connection:
3434
- keep-alive
3535
content-length:
36-
- '795'
36+
- '813'
3737
content-type:
3838
- application/json
39+
strict-transport-security:
40+
- max-age=31536000; includeSubDomains; preload
3941
transfer-encoding:
4042
- chunked
4143
parsed_body:
4244
content:
43-
- text: This document appears to be a sample PDF file that primarily contains Lorem ipsum text, which is placeholder
44-
text commonly used in design and publishing. The document begins with "Sample PDF" and states "This is a simple
45-
PDF file. Fun fun fun." followed by several paragraphs of Lorem ipsum text. The content doesn't convey any meaningful
46-
information as Lorem ipsum is essentially dummy text used to demonstrate the visual form of a document without the
47-
distraction of meaningful content.
45+
- text: This document appears to be a sample PDF file that contains Lorem ipsum text, which is placeholder text commonly
46+
used in design and publishing. The document starts with "Sample PDF" and includes the line "This is a simple PDF
47+
file. Fun fun fun." followed by several paragraphs of Lorem ipsum text. Lorem ipsum is dummy text that has no meaningful
48+
content - it's typically used to demonstrate the visual form of a document or typeface without the distraction of
49+
meaningful content.
4850
type: text
49-
id: msg_0146LphUoRKNWvDULHuTfu4H
51+
id: msg_015t94iUurjyZ7Jvi7kvDe5b
5052
model: claude-3-5-sonnet-20241022
5153
role: assistant
5254
stop_reason: end_turn
@@ -56,7 +58,8 @@ interactions:
5658
cache_creation_input_tokens: 0
5759
cache_read_input_tokens: 0
5860
input_tokens: 2682
59-
output_tokens: 96
61+
output_tokens: 98
62+
service_tier: standard
6063
status:
6164
code: 200
6265
message: OK

tests/models/cassettes/test_anthropic/test_extra_headers.yaml

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ interactions:
88
connection:
99
- keep-alive
1010
content-length:
11-
- '202'
11+
- '169'
1212
content-type:
1313
- application/json
14+
extra-header-key:
15+
- Extra-Header-Value
1416
host:
1517
- api.anthropic.com
16-
xProxy-Limit-IDs:
17-
- monthly_budget
1818
method: POST
1919
parsed_body:
2020
max_tokens: 1024
@@ -23,34 +23,39 @@ interactions:
2323
- text: hello
2424
type: text
2525
role: user
26-
model: claude-3-opus-latest
26+
metadata:
27+
user_id: '123'
28+
model: claude-3-5-haiku-latest
2729
stream: false
28-
uri: https://api.anthropic.com/v1/messages
30+
uri: https://api.anthropic.com/v1/messages?beta=true
2931
response:
3032
headers:
3133
connection:
3234
- keep-alive
3335
content-length:
34-
- '328'
36+
- '398'
3537
content-type:
3638
- application/json
39+
strict-transport-security:
40+
- max-age=31536000; includeSubDomains; preload
3741
transfer-encoding:
3842
- chunked
3943
parsed_body:
4044
content:
41-
- text: Hello! How can I assist you today?
45+
- text: Hi there! How are you doing today? Is there anything I can help you with?
4246
type: text
43-
id: msg_01U58nruzfn9BrXrrF2hhb4m
44-
model: claude-3-5-haiku-latest
47+
id: msg_016xQfqVwNtY1LLF1xHTN5Sk
48+
model: claude-3-5-haiku-20241022
4549
role: assistant
4650
stop_reason: end_turn
4751
stop_sequence: null
4852
type: message
4953
usage:
5054
cache_creation_input_tokens: 0
5155
cache_read_input_tokens: 0
52-
input_tokens: 20
53-
output_tokens: 10
56+
input_tokens: 8
57+
output_tokens: 21
58+
service_tier: standard
5459
status:
5560
code: 200
5661
message: OK

tests/models/cassettes/test_anthropic/test_image_as_binary_content_tool_response.yaml

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,28 @@ interactions:
3232
properties: {}
3333
type: object
3434
name: get_image
35-
uri: https://api.anthropic.com/v1/messages
35+
uri: https://api.anthropic.com/v1/messages?beta=true
3636
response:
3737
headers:
3838
connection:
3939
- keep-alive
4040
content-length:
41-
- '441'
41+
- '447'
4242
content-type:
4343
- application/json
44+
strict-transport-security:
45+
- max-age=31536000; includeSubDomains; preload
4446
transfer-encoding:
4547
- chunked
4648
parsed_body:
4749
content:
48-
- text: Let me get the image and check what fruit is shown.
50+
- text: Let me get the image and check.
4951
type: text
50-
- id: toolu_01VMGXdexE1Fy5xdWgoom9Te
52+
- id: toolu_01YJiJ82nETV7aRdJr9f6Np7
5153
input: {}
5254
name: get_image
5355
type: tool_use
54-
id: msg_01BPu4UTHXhqtR1TvsRhBLYY
56+
id: msg_01CC59GmUmYXKCV26rHfr32m
5557
model: claude-3-5-sonnet-20241022
5658
role: assistant
5759
stop_reason: tool_use
@@ -61,7 +63,8 @@ interactions:
6163
cache_creation_input_tokens: 0
6264
cache_read_input_tokens: 0
6365
input_tokens: 372
64-
output_tokens: 49
66+
output_tokens: 45
67+
service_tier: standard
6568
status:
6669
code: 200
6770
message: OK
@@ -74,7 +77,7 @@ interactions:
7477
connection:
7578
- keep-alive
7679
content-length:
77-
- '2780301'
80+
- '2780281'
7881
content-type:
7982
- application/json
8083
host:
@@ -88,17 +91,17 @@ interactions:
8891
type: text
8992
role: user
9093
- content:
91-
- text: Let me get the image and check what fruit is shown.
94+
- text: Let me get the image and check.
9295
type: text
93-
- id: toolu_01VMGXdexE1Fy5xdWgoom9Te
96+
- id: toolu_01YJiJ82nETV7aRdJr9f6Np7
9497
input: {}
9598
name: get_image
9699
type: tool_use
97100
role: assistant
98101
- content:
99102
- content: See file 1c8566
100103
is_error: false
101-
tool_use_id: toolu_01VMGXdexE1Fy5xdWgoom9Te
104+
tool_use_id: toolu_01YJiJ82nETV7aRdJr9f6Np7
102105
type: tool_result
103106
- text: 'This is file 1c8566:'
104107
type: text
@@ -119,24 +122,26 @@ interactions:
119122
properties: {}
120123
type: object
121124
name: get_image
122-
uri: https://api.anthropic.com/v1/messages
125+
uri: https://api.anthropic.com/v1/messages?beta=true
123126
response:
124127
headers:
125128
connection:
126129
- keep-alive
127130
content-length:
128-
- '559'
131+
- '592'
129132
content-type:
130133
- application/json
134+
strict-transport-security:
135+
- max-age=31536000; includeSubDomains; preload
131136
transfer-encoding:
132137
- chunked
133138
parsed_body:
134139
content:
135140
- text: The image shows a kiwi fruit that has been cut in half, displaying its characteristic bright green flesh with
136-
small black seeds arranged in a circular pattern around a white center core. The kiwi's fuzzy brown skin is visible
137-
around the edges of the slice.
141+
small black seeds arranged in a circular pattern around a white center core. The fruit's thin, fuzzy brown skin
142+
is visible around the edges of the slice.
138143
type: text
139-
id: msg_01Ua6uyZUF15YV3G1PusaqSq
144+
id: msg_014MJqSsWD1pUC23Vvi57LoY
140145
model: claude-3-5-sonnet-20241022
141146
role: assistant
142147
stop_reason: end_turn
@@ -145,8 +150,9 @@ interactions:
145150
usage:
146151
cache_creation_input_tokens: 0
147152
cache_read_input_tokens: 0
148-
input_tokens: 2025
153+
input_tokens: 2021
149154
output_tokens: 57
155+
service_tier: standard
150156
status:
151157
code: 200
152158
message: OK

0 commit comments

Comments
 (0)