supporting thinking for anthropic models (#3978)

* supporting thinking for anthropic models

* drop comments here

* thinking and tool calling support

* fix: properly mock tool use and text block types in Anthropic tests

- Updated the test for the Anthropic tool use conversation flow to include type attributes for mocked ToolUseBlock and text blocks, ensuring accurate simulation of tool interactions during testing.

* feat: add AnthropicThinkingConfig for enhanced thinking capabilities

This update introduces the AnthropicThinkingConfig class to manage thinking parameters for the Anthropic completion model. The LLM and AnthropicCompletion classes have been updated to utilize this new configuration. Additionally, new test cassettes have been added to validate the functionality of thinking blocks across interactions.
This commit is contained in:
Lorenze Jay
2025-12-08 15:34:54 -08:00
committed by GitHub
parent f2f994612c
commit 6125b866fd
11 changed files with 1605 additions and 73 deletions

View File

@@ -0,0 +1,122 @@
interactions:
- request:
body: '{"max_tokens":10000,"messages":[{"role":"user","content":"What is the weather
in Tokyo?"}],"model":"claude-sonnet-4-5","stream":false,"thinking":{"type":"enabled","budget_tokens":5000}}'
headers:
accept:
- application/json
accept-encoding:
- gzip, deflate
anthropic-version:
- '2023-06-01'
connection:
- keep-alive
content-length:
- '185'
content-type:
- application/json
host:
- api.anthropic.com
user-agent:
- Anthropic/Python 0.75.0
x-stainless-arch:
- arm64
x-stainless-async:
- 'false'
x-stainless-lang:
- python
x-stainless-os:
- MacOS
x-stainless-package-version:
- 0.75.0
x-stainless-retry-count:
- '0'
x-stainless-runtime:
- CPython
x-stainless-runtime-version:
- 3.13.3
x-stainless-timeout:
- NOT_GIVEN
method: POST
uri: https://api.anthropic.com/v1/messages
response:
body:
string: !!binary |
H4sIAAAAAAAAAwAAAP//hJNdr6o4GIX/SsPNXIjbD/xAk3OhiIiyZasI4uxkUmkFBFpsy4f75Pz3
CU72PjOTyZyrNm/WWu9K0+e7lFGEU2kqBSksEG5zSggW7UF72O53+8PupD+RZClG0lTKePhHtzeo
vMQjm621jXbB3apfy6MTbyRZEo8cNyrMOQyxJEuMps0Ach5zAYmQZCmgRGAipOnv3z/1IopJEpOw
Sfi8TiUnwqDgmIGYA8ibIcgwg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Z1hwwfvfO9NezUdQ8xhzW3OtqPvOn9Zh+O62JuUp2MqO61IXsFl9YuXELO
61YDXJgX82rzcEXTY0Mp+6AjOHmhliCdziUKfYCE5wIxoFaKcw2VubjbN7ISStbZP0EStednDRk2
A7SJmF9C/xScrDyCu//YOlvvRxgwIrLTF+Nf/RfdDr/p1JAv+fvR9vK0oYT4Yg10tojUUv1uOo4d
TdM7AAAA//8DANemNnfhBgAA
headers:
CF-RAY:
- 9a4b033548b28ea2-SJC
Connection:
- keep-alive
Content-Encoding:
- gzip
Content-Type:
- application/json
Date:
- Wed, 26 Nov 2025 17:12:50 GMT
Server:
- cloudflare
Transfer-Encoding:
- chunked
X-Robots-Tag:
- none
anthropic-organization-id:
- 32982f3d-354e-4063-a1d9-6e3e0361bcfe
anthropic-ratelimit-input-tokens-limit:
- '30000'
anthropic-ratelimit-input-tokens-remaining:
- '30000'
anthropic-ratelimit-input-tokens-reset:
- '2025-11-26T17:12:47Z'
anthropic-ratelimit-output-tokens-limit:
- '8000'
anthropic-ratelimit-output-tokens-remaining:
- '8000'
anthropic-ratelimit-output-tokens-reset:
- '2025-11-26T17:12:51Z'
anthropic-ratelimit-requests-limit:
- '50'
anthropic-ratelimit-requests-remaining:
- '49'
anthropic-ratelimit-requests-reset:
- '2025-11-26T17:12:46Z'
anthropic-ratelimit-tokens-limit:
- '38000'
anthropic-ratelimit-tokens-remaining:
- '38000'
anthropic-ratelimit-tokens-reset:
- '2025-11-26T17:12:47Z'
cf-cache-status:
- DYNAMIC
request-id:
- req_011CVWsgwRugLxGNv45mLXEL
retry-after:
- '13'
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
x-envoy-upstream-service-time:
- '4553'
status:
code: 200
message: OK
version: 1