-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
41162c6
commit 5e35ffe
Showing
24 changed files
with
3,127 additions
and
4 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 +1 @@ | ||
configured_endpoints: 2 | ||
configured_endpoints: 3 |
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,53 @@ | ||
from __future__ import annotations | ||
|
||
from anthropic import Anthropic | ||
from anthropic.types.beta.tools import ToolParam, ToolsBetaMessageParam | ||
|
||
client = Anthropic() | ||
|
||
user_message: ToolsBetaMessageParam = { | ||
"role": "user", | ||
"content": "What is the weather in SF?", | ||
} | ||
tools: list[ToolParam] = [ | ||
{ | ||
"name": "get_weather", | ||
"description": "Get the weather for a specific location", | ||
"input_schema": { | ||
"type": "object", | ||
"properties": {"location": {"type": "string"}}, | ||
}, | ||
} | ||
] | ||
|
||
message = client.beta.tools.messages.create( | ||
model="claude-3-opus-20240229", | ||
max_tokens=1024, | ||
messages=[user_message], | ||
tools=tools, | ||
) | ||
print(f"Initial response: {message.model_dump_json(indent=2)}") | ||
|
||
assert message.stop_reason == "tool_use" | ||
|
||
tool = next(c for c in message.content if c.type == "tool_use") | ||
response = client.beta.tools.messages.create( | ||
model="claude-3-opus-20240229", | ||
max_tokens=1024, | ||
messages=[ | ||
user_message, | ||
{"role": message.role, "content": message.content}, | ||
{ | ||
"role": "user", | ||
"content": [ | ||
{ | ||
"type": "tool_result", | ||
"tool_use_id": tool.id, | ||
"content": [{"type": "text", "text": "The weather is 73f"}], | ||
} | ||
], | ||
}, | ||
], | ||
tools=tools, | ||
) | ||
print(f"\nFinal response: {response.model_dump_json(indent=2)}") |
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
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,33 @@ | ||
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. | ||
|
||
from .beta import ( | ||
Beta, | ||
AsyncBeta, | ||
BetaWithRawResponse, | ||
AsyncBetaWithRawResponse, | ||
BetaWithStreamingResponse, | ||
AsyncBetaWithStreamingResponse, | ||
) | ||
from .tools import ( | ||
Tools, | ||
AsyncTools, | ||
ToolsWithRawResponse, | ||
AsyncToolsWithRawResponse, | ||
ToolsWithStreamingResponse, | ||
AsyncToolsWithStreamingResponse, | ||
) | ||
|
||
__all__ = [ | ||
"Tools", | ||
"AsyncTools", | ||
"ToolsWithRawResponse", | ||
"AsyncToolsWithRawResponse", | ||
"ToolsWithStreamingResponse", | ||
"AsyncToolsWithStreamingResponse", | ||
"Beta", | ||
"AsyncBeta", | ||
"BetaWithRawResponse", | ||
"AsyncBetaWithRawResponse", | ||
"BetaWithStreamingResponse", | ||
"AsyncBetaWithStreamingResponse", | ||
] |
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,81 @@ | ||
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. | ||
|
||
from __future__ import annotations | ||
|
||
from .tools import ( | ||
Tools, | ||
AsyncTools, | ||
ToolsWithRawResponse, | ||
AsyncToolsWithRawResponse, | ||
ToolsWithStreamingResponse, | ||
AsyncToolsWithStreamingResponse, | ||
) | ||
from ..._compat import cached_property | ||
from ..._resource import SyncAPIResource, AsyncAPIResource | ||
from .tools.tools import Tools, AsyncTools | ||
|
||
__all__ = ["Beta", "AsyncBeta"] | ||
|
||
|
||
class Beta(SyncAPIResource): | ||
@cached_property | ||
def tools(self) -> Tools: | ||
return Tools(self._client) | ||
|
||
@cached_property | ||
def with_raw_response(self) -> BetaWithRawResponse: | ||
return BetaWithRawResponse(self) | ||
|
||
@cached_property | ||
def with_streaming_response(self) -> BetaWithStreamingResponse: | ||
return BetaWithStreamingResponse(self) | ||
|
||
|
||
class AsyncBeta(AsyncAPIResource): | ||
@cached_property | ||
def tools(self) -> AsyncTools: | ||
return AsyncTools(self._client) | ||
|
||
@cached_property | ||
def with_raw_response(self) -> AsyncBetaWithRawResponse: | ||
return AsyncBetaWithRawResponse(self) | ||
|
||
@cached_property | ||
def with_streaming_response(self) -> AsyncBetaWithStreamingResponse: | ||
return AsyncBetaWithStreamingResponse(self) | ||
|
||
|
||
class BetaWithRawResponse: | ||
def __init__(self, beta: Beta) -> None: | ||
self._beta = beta | ||
|
||
@cached_property | ||
def tools(self) -> ToolsWithRawResponse: | ||
return ToolsWithRawResponse(self._beta.tools) | ||
|
||
|
||
class AsyncBetaWithRawResponse: | ||
def __init__(self, beta: AsyncBeta) -> None: | ||
self._beta = beta | ||
|
||
@cached_property | ||
def tools(self) -> AsyncToolsWithRawResponse: | ||
return AsyncToolsWithRawResponse(self._beta.tools) | ||
|
||
|
||
class BetaWithStreamingResponse: | ||
def __init__(self, beta: Beta) -> None: | ||
self._beta = beta | ||
|
||
@cached_property | ||
def tools(self) -> ToolsWithStreamingResponse: | ||
return ToolsWithStreamingResponse(self._beta.tools) | ||
|
||
|
||
class AsyncBetaWithStreamingResponse: | ||
def __init__(self, beta: AsyncBeta) -> None: | ||
self._beta = beta | ||
|
||
@cached_property | ||
def tools(self) -> AsyncToolsWithStreamingResponse: | ||
return AsyncToolsWithStreamingResponse(self._beta.tools) |
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,33 @@ | ||
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. | ||
|
||
from .tools import ( | ||
Tools, | ||
AsyncTools, | ||
ToolsWithRawResponse, | ||
AsyncToolsWithRawResponse, | ||
ToolsWithStreamingResponse, | ||
AsyncToolsWithStreamingResponse, | ||
) | ||
from .messages import ( | ||
Messages, | ||
AsyncMessages, | ||
MessagesWithRawResponse, | ||
AsyncMessagesWithRawResponse, | ||
MessagesWithStreamingResponse, | ||
AsyncMessagesWithStreamingResponse, | ||
) | ||
|
||
__all__ = [ | ||
"Messages", | ||
"AsyncMessages", | ||
"MessagesWithRawResponse", | ||
"AsyncMessagesWithRawResponse", | ||
"MessagesWithStreamingResponse", | ||
"AsyncMessagesWithStreamingResponse", | ||
"Tools", | ||
"AsyncTools", | ||
"ToolsWithRawResponse", | ||
"AsyncToolsWithRawResponse", | ||
"ToolsWithStreamingResponse", | ||
"AsyncToolsWithStreamingResponse", | ||
] |
Oops, something went wrong.