-
Notifications
You must be signed in to change notification settings - Fork 678
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
feat(anthropic): add instrumentation for Anthropic tool calling #1372
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
...metry-instrumentation-anthropic/tests/cassettes/test_completion/test_anthropic_tools.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
interactions: | ||
- request: | ||
body: '{"max_tokens": 1024, "messages": [{"role": "user", "content": "What is | ||
the weather like right now in New York? Also what time is it there?"}], "model": | ||
"claude-3-opus-20240229", "tools": [{"name": "get_weather", "description": "Get | ||
the current weather in a given location", "input_schema": {"type": "object", | ||
"properties": {"location": {"type": "string", "description": "The city and state, | ||
e.g. San Francisco, CA"}, "unit": {"type": "string", "enum": ["celsius", "fahrenheit"], | ||
"description": "The unit of temperature, either ''celsius'' or ''fahrenheit''"}}, | ||
"required": ["location"]}}, {"name": "get_time", "description": "Get the current | ||
time in a given time zone", "input_schema": {"type": "object", "properties": | ||
{"timezone": {"type": "string", "description": "The IANA time zone name, e.g. | ||
America/Los_Angeles"}}, "required": ["timezone"]}}]}' | ||
headers: | ||
accept: | ||
- application/json | ||
accept-encoding: | ||
- gzip, deflate | ||
anthropic-version: | ||
- '2023-06-01' | ||
connection: | ||
- keep-alive | ||
content-length: | ||
- '845' | ||
content-type: | ||
- application/json | ||
host: | ||
- api.anthropic.com | ||
user-agent: | ||
- Anthropic/Python 0.29.0 | ||
x-stainless-arch: | ||
- x64 | ||
x-stainless-async: | ||
- 'false' | ||
x-stainless-lang: | ||
- python | ||
x-stainless-os: | ||
- Linux | ||
x-stainless-package-version: | ||
- 0.29.0 | ||
x-stainless-runtime: | ||
- CPython | ||
x-stainless-runtime-version: | ||
- 3.10.14 | ||
method: POST | ||
uri: https://api.anthropic.com/v1/messages | ||
response: | ||
body: | ||
string: !!binary | | ||
H4sIAAAAAAAAA4RTYW/TMBD9K6f7wpe0awPbWDQhVTAQaKoQVJsGQZGb3BrT5JzZ54Wu6n9HdklX | ||
ISQ+xbk7v3vv6XmLusIMW7cqJtN3sujO3OPVslf3b282Z0+fp1/mS0xQNh2FKXJOrQgTtKYJBeWc | ||
dqJYMMHWVNRghmWjfEWjlyPTeTdKJ+mrSZpeYIKlYSEWzL5vB0ChX+Fq/GR4KbXmtebVm5wXBhS7 | ||
nixIrR08eLKbBHqCXjcNMFEFYsA7AukNiDGNy3LOeTqGFUnRk5KaLIxgYUIBpCYovbXEAkNTM8yp | ||
hztj12NYhDWWHry25OJ4jo0plWjDOUKnrGpJyCbQ17qs44R3ZKFWDjprHnVFFSgHOQ6gOQbYAORZ | ||
yzEIaAemC9CqGQfa6Z626Jb+zTl2/ks4TD0ZpuNdew6RaqUrYCNQaUulNJuBd/Q4gaUP3kCpGDTf | ||
B5YCS+WoAsNxweDHXxqHc1Cl95NXyglZhkWg/c0wDbYFt8LAx9l8thcV+AKrNvCftWR1qU7m1Bd/ | ||
0IM7X03gVatHineZyhBEu3kW6UIaWrUmWBqpYx6gVE0T64cg7W14EePkghA3zvny5BA73CXP0TSm | ||
KbwLYY8vJPz7YjL9cHF+a+zPm0/96+v3d9e3s2mVnoUQBwmY4VH6wlXuvGC2PUQJs4N1uNv9SNCJ | ||
6QpLysXe0dbYcPTgiUvCjH3TJOjj+8u2e+BCzJrYYXZ+miZovBzX0snpbvcbAAD//wMAiN3y7N8D | ||
AAA= | ||
headers: | ||
CF-Cache-Status: | ||
- DYNAMIC | ||
CF-RAY: | ||
- 89712d1918f04631-SIN | ||
Connection: | ||
- keep-alive | ||
Content-Encoding: | ||
- gzip | ||
Content-Type: | ||
- application/json | ||
Date: | ||
- Fri, 21 Jun 2024 04:15:22 GMT | ||
Server: | ||
- cloudflare | ||
Transfer-Encoding: | ||
- chunked | ||
anthropic-ratelimit-requests-limit: | ||
- '50' | ||
anthropic-ratelimit-requests-remaining: | ||
- '50' | ||
anthropic-ratelimit-requests-reset: | ||
- '2024-06-21T04:16:18Z' | ||
anthropic-ratelimit-tokens-limit: | ||
- '20000' | ||
anthropic-ratelimit-tokens-remaining: | ||
- '20000' | ||
anthropic-ratelimit-tokens-reset: | ||
- '2024-06-21T04:16:18Z' | ||
request-id: | ||
- req_01X7p5rhys5xac6P9AmQiGs4 | ||
via: | ||
- 1.1 google | ||
x-cloud-trace-context: | ||
- 791e086e0002047f61d7da1c157754d9 | ||
status: | ||
code: 200 | ||
message: OK | ||
version: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @peachypeachyy this is already happening in
_set_span_completions
. What I meant is editing the code there to specify the tool selection (if a tool was selected) - and following the similar conventions we have in the OpenAI instrumentationThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @nirga let me step you through my thought process.
Following is the request being sent:
The corresponding formatted response is:
In this case, even though we have 2 functions passed in tools,
get_weather
andget_time
, claude's opus determined to use get_weather as seen in theToolUseBlock
.I have captured this tool
get_weather
which is being used withinToolUseBlock
usingf"{SpanAttributes.LLM_COMPLETIONS}.{i}.name"
.Now, which tool has to be used is governed by the parameter tool_choice which needs to be set in the request. I have not set it in this example, by default the value is
auto
. Do you need me to set spans for this within the request? something likef"{SpanAttributes.LLM_REQUEST_FUNCTIONS}.{i}.tool_choice == auto
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@peachypeachyy can you look at
set_span_completions
? It's also setting the same attributes you're setting here. You should only add the tool choice logging, similar to OpenAI