MCPcopy Create free account
hub / github.com/anthropics/anthropic-sdk-python / main

Function main

examples/tools_stream.py:8–37  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

6
7
8async def main() -> None:
9 async with client.messages.stream(
10 max_tokens=1024,
11 model="claude-sonnet-5",
12 tools=[
13 {
14 "name": "get_weather",
15 "description": "Get the weather at a specific location",
16 "input_schema": {
17 "type": "object",
18 "properties": {
19 "location": {"type": "string", "description": "The city and state, e.g. San Francisco, CA"},
20 "unit": {
21 "type": "string",
22 "enum": ["celsius", "fahrenheit"],
23 "description": "Unit for the output",
24 },
25 },
26 "required": ["location"],
27 },
28 }
29 ],
30 messages=[{"role": "user", "content": "What is the weather in SF?"}],
31 ) as stream:
32 async for event in stream:
33 if event.type == "input_json":
34 print(f"delta: {repr(event.partial_json)}")
35 print(f"snapshot: {event.snapshot}")
36
37 print()
38
39
40asyncio.run(main())

Callers 1

tools_stream.pyFile · 0.70

Calls 1

streamMethod · 0.45

Tested by

no test coverage detected