Skip to content

Use AsyncBeta instead of AsyncAnthropic #1818

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 24, 2025
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
151 changes: 78 additions & 73 deletions pydantic_ai_slim/pydantic_ai/models/anthropic.py

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,24 @@ interactions:
stop_sequences:
- Paris
stream: false
uri: https://api.anthropic.com/v1/messages
uri: https://api.anthropic.com/v1/messages?beta=true
response:
headers:
connection:
- keep-alive
content-length:
- '333'
- '359'
content-type:
- application/json
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
parsed_body:
content:
- text: 'The capital of France is '
type: text
id: msg_01FfkgikmbDFzn9XE1YYkJmA
id: msg_01SVFZqkSLhUPkAA4w6rhzFD
model: claude-3-5-sonnet-20241022
role: assistant
stop_reason: stop_sequence
Expand All @@ -51,6 +53,7 @@ interactions:
cache_read_input_tokens: 0
input_tokens: 14
output_tokens: 6
service_tier: standard
status:
code: 200
message: OK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interactions:
connection:
- keep-alive
content-length:
- '202'
- '206'
content-type:
- application/json
host:
Expand All @@ -23,23 +23,27 @@ interactions:
role: user
model: claude-3-opus-latest
stream: false
system: You are a helpful assistant.
uri: https://api.anthropic.com/v1/messages
system: |+
You are a helpful assistant.

uri: https://api.anthropic.com/v1/messages?beta=true
response:
headers:
connection:
- keep-alive
content-length:
- '328'
- '354'
content-type:
- application/json
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
parsed_body:
content:
- text: The capital of France is Paris.
type: text
id: msg_01U58nruzfn9BrXrrF2hhb4m
id: msg_01BznVNBje2zyfpCfNQCD5en
model: claude-3-opus-20240229
role: assistant
stop_reason: end_turn
Expand All @@ -50,7 +54,9 @@ interactions:
cache_read_input_tokens: 0
input_tokens: 20
output_tokens: 10
service_tier: standard
status:
code: 200
message: OK
version: 1
...
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,24 @@ interactions:
role: user
model: claude-3-5-sonnet-latest
stream: false
uri: https://api.anthropic.com/v1/messages
uri: https://api.anthropic.com/v1/messages?beta=true
response:
headers:
connection:
- keep-alive
content-length:
- '502'
- '433'
content-type:
- application/json
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
parsed_body:
content:
- text: The document appears to be a simple PDF file with only the text "Dummy PDF file" displayed at the top. It appears
to be mostly blank otherwise, likely serving as a template or placeholder document.
- text: The document shows only the text "Dummy PDF file" at the top of what appears to be a blank white page.
type: text
id: msg_01MV5d7ebPBUzPV5DerCiRFS
id: msg_01Jr6x34UmKgzgrJE96jaYpm
model: claude-3-5-sonnet-20241022
role: assistant
stop_reason: end_turn
Expand All @@ -54,7 +55,8 @@ interactions:
cache_creation_input_tokens: 0
cache_read_input_tokens: 0
input_tokens: 1615
output_tokens: 44
output_tokens: 28
service_tier: standard
status:
code: 200
message: OK
Expand Down
21 changes: 12 additions & 9 deletions tests/models/cassettes/test_anthropic/test_document_url_input.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,28 @@ interactions:
role: user
model: claude-3-5-sonnet-latest
stream: false
uri: https://api.anthropic.com/v1/messages
uri: https://api.anthropic.com/v1/messages?beta=true
response:
headers:
connection:
- keep-alive
content-length:
- '795'
- '813'
content-type:
- application/json
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
parsed_body:
content:
- text: This document appears to be a sample PDF file that primarily contains Lorem ipsum text, which is placeholder
text commonly used in design and publishing. The document begins with "Sample PDF" and states "This is a simple
PDF file. Fun fun fun." followed by several paragraphs of Lorem ipsum text. The content doesn't convey any meaningful
information as Lorem ipsum is essentially dummy text used to demonstrate the visual form of a document without the
distraction of meaningful content.
- text: This document appears to be a sample PDF file that contains Lorem ipsum text, which is placeholder text commonly
used in design and publishing. The document starts with "Sample PDF" and includes the line "This is a simple PDF
file. Fun fun fun." followed by several paragraphs of Lorem ipsum text. Lorem ipsum is dummy text that has no meaningful
content - it's typically used to demonstrate the visual form of a document or typeface without the distraction of
meaningful content.
type: text
id: msg_0146LphUoRKNWvDULHuTfu4H
id: msg_015t94iUurjyZ7Jvi7kvDe5b
model: claude-3-5-sonnet-20241022
role: assistant
stop_reason: end_turn
Expand All @@ -56,7 +58,8 @@ interactions:
cache_creation_input_tokens: 0
cache_read_input_tokens: 0
input_tokens: 2682
output_tokens: 96
output_tokens: 98
service_tier: standard
status:
code: 200
message: OK
Expand Down
27 changes: 16 additions & 11 deletions tests/models/cassettes/test_anthropic/test_extra_headers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ interactions:
connection:
- keep-alive
content-length:
- '202'
- '169'
content-type:
- application/json
extra-header-key:
- Extra-Header-Value
host:
- api.anthropic.com
xProxy-Limit-IDs:
- monthly_budget
method: POST
parsed_body:
max_tokens: 1024
Expand All @@ -23,34 +23,39 @@ interactions:
- text: hello
type: text
role: user
model: claude-3-opus-latest
metadata:
user_id: '123'
model: claude-3-5-haiku-latest
stream: false
uri: https://api.anthropic.com/v1/messages
uri: https://api.anthropic.com/v1/messages?beta=true
response:
headers:
connection:
- keep-alive
content-length:
- '328'
- '398'
content-type:
- application/json
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
parsed_body:
content:
- text: Hello! How can I assist you today?
- text: Hi there! How are you doing today? Is there anything I can help you with?
type: text
id: msg_01U58nruzfn9BrXrrF2hhb4m
model: claude-3-5-haiku-latest
id: msg_016xQfqVwNtY1LLF1xHTN5Sk
model: claude-3-5-haiku-20241022
role: assistant
stop_reason: end_turn
stop_sequence: null
type: message
usage:
cache_creation_input_tokens: 0
cache_read_input_tokens: 0
input_tokens: 20
output_tokens: 10
input_tokens: 8
output_tokens: 21
service_tier: standard
status:
code: 200
message: OK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,28 @@ interactions:
properties: {}
type: object
name: get_image
uri: https://api.anthropic.com/v1/messages
uri: https://api.anthropic.com/v1/messages?beta=true
response:
headers:
connection:
- keep-alive
content-length:
- '441'
- '447'
content-type:
- application/json
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
parsed_body:
content:
- text: Let me get the image and check what fruit is shown.
- text: Let me get the image and check.
type: text
- id: toolu_01VMGXdexE1Fy5xdWgoom9Te
- id: toolu_01YJiJ82nETV7aRdJr9f6Np7
input: {}
name: get_image
type: tool_use
id: msg_01BPu4UTHXhqtR1TvsRhBLYY
id: msg_01CC59GmUmYXKCV26rHfr32m
model: claude-3-5-sonnet-20241022
role: assistant
stop_reason: tool_use
Expand All @@ -61,7 +63,8 @@ interactions:
cache_creation_input_tokens: 0
cache_read_input_tokens: 0
input_tokens: 372
output_tokens: 49
output_tokens: 45
service_tier: standard
status:
code: 200
message: OK
Expand All @@ -74,7 +77,7 @@ interactions:
connection:
- keep-alive
content-length:
- '2780301'
- '2780281'
content-type:
- application/json
host:
Expand All @@ -88,17 +91,17 @@ interactions:
type: text
role: user
- content:
- text: Let me get the image and check what fruit is shown.
- text: Let me get the image and check.
type: text
- id: toolu_01VMGXdexE1Fy5xdWgoom9Te
- id: toolu_01YJiJ82nETV7aRdJr9f6Np7
input: {}
name: get_image
type: tool_use
role: assistant
- content:
- content: See file 1c8566
is_error: false
tool_use_id: toolu_01VMGXdexE1Fy5xdWgoom9Te
tool_use_id: toolu_01YJiJ82nETV7aRdJr9f6Np7
type: tool_result
- text: 'This is file 1c8566:'
type: text
Expand All @@ -119,24 +122,26 @@ interactions:
properties: {}
type: object
name: get_image
uri: https://api.anthropic.com/v1/messages
uri: https://api.anthropic.com/v1/messages?beta=true
response:
headers:
connection:
- keep-alive
content-length:
- '559'
- '592'
content-type:
- application/json
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
parsed_body:
content:
- text: The image shows a kiwi fruit that has been cut in half, displaying its characteristic bright green flesh with
small black seeds arranged in a circular pattern around a white center core. The kiwi's fuzzy brown skin is visible
around the edges of the slice.
small black seeds arranged in a circular pattern around a white center core. The fruit's thin, fuzzy brown skin
is visible around the edges of the slice.
type: text
id: msg_01Ua6uyZUF15YV3G1PusaqSq
id: msg_014MJqSsWD1pUC23Vvi57LoY
model: claude-3-5-sonnet-20241022
role: assistant
stop_reason: end_turn
Expand All @@ -145,8 +150,9 @@ interactions:
usage:
cache_creation_input_tokens: 0
cache_read_input_tokens: 0
input_tokens: 2025
input_tokens: 2021
output_tokens: 57
service_tier: standard
status:
code: 200
message: OK
Expand Down
Loading