-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): add
tool_choice
param, image block params inside `tool_r…
…esult.content`, and streaming for `tool_use` blocks (#502)
- Loading branch information
1 parent
5d896a2
commit e0c78af
Showing
18 changed files
with
1,192 additions
and
258 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
configured_endpoints: 3 | ||
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic-4742de59ec06077403336bc26e26390e57888e5eef313bf27eab241dbb905f06.yml | ||
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic-0017013a270564e5cdfb7b8ffe474c962f4b806c862cbcc33c905504897fabbe.yml |
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
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,48 @@ | ||
import asyncio | ||
from typing_extensions import override | ||
|
||
from anthropic import AsyncAnthropic | ||
from anthropic.lib.streaming.beta import AsyncToolsBetaMessageStream | ||
|
||
client = AsyncAnthropic() | ||
|
||
|
||
class MyHandler(AsyncToolsBetaMessageStream): | ||
@override | ||
async def on_input_json(self, delta: str, snapshot: object) -> None: | ||
print(f"delta: {repr(delta)}") | ||
print(f"snapshot: {snapshot}") | ||
print() | ||
|
||
|
||
async def main() -> None: | ||
async with client.beta.tools.messages.stream( | ||
max_tokens=1024, | ||
model="claude-3-haiku-20240307", | ||
tools=[ | ||
{ | ||
"name": "get_weather", | ||
"description": "Get the weather at a specific 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": "Unit for the output", | ||
}, | ||
}, | ||
"required": ["location"], | ||
}, | ||
} | ||
], | ||
messages=[{"role": "user", "content": "What is the weather in SF?"}], | ||
event_handler=MyHandler, | ||
) as stream: | ||
await stream.until_done() | ||
|
||
print() | ||
|
||
|
||
asyncio.run(main()) |
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,8 @@ | ||
from ._tools import ( | ||
ToolsBetaMessageStream as ToolsBetaMessageStream, | ||
ToolsBetaMessageStreamT as ToolsBetaMessageStreamT, | ||
AsyncToolsBetaMessageStream as AsyncToolsBetaMessageStream, | ||
AsyncToolsBetaMessageStreamT as AsyncToolsBetaMessageStreamT, | ||
ToolsBetaMessageStreamManager as ToolsBetaMessageStreamManager, | ||
AsyncToolsBetaMessageStreamManager as AsyncToolsBetaMessageStreamManager, | ||
) |
Oops, something went wrong.