No project description provided
Project description
Anthropic extensions
Get Pocket Anthropic Tool Spec
from hyperpocket_anthropic import PocketAnthropic
pocket = PocketAnthropic(tools=[
"https://github.com/my-org/some-awesome-tool",
"https://github.com/vessl-ai/hyperpocket/tree/main/tools/slack/get-message",
"https://github.com/vessl-ai/hyperpocket/tree/main/tools/slack/post-message",
]
)
# get anthropic compatible tool specs from pocket
tool_specs = pocket.get_anthropic_tool_specs()
Tool Injection
import os
from anthropic import Anthropic
messages = [
{
"role": "user",
"content": "get slack message",
}
]
llm = Anthropic()
response = llm.messages.create(
model=os.getenv("ANTHROPIC_MODEL_NAME"),
max_tokens=500,
messages=messages,
tools=tool_specs, # pass the tool specs as an tools argument
)
Tool Call
response = llm.messages.create(
model=os.getenv("ANTHROPIC_MODEL_NAME"),
max_tokens=500,
messages=messages,
tools=tool_specs, # pass the tool specs as an tools argument
)
tool_result_blocks = []
for block in response.content:
if block.type == "tool_use":
tool_result_block = pocket.invoke(block)
tool_result_blocks.append(tool_result_block)
messages.append({"role": "user", "content": tool_result_blocks})
response_after_tool_call = llm.messages.create(
model=os.getenv("ANTHROPIC_MODEL_NAME"),
max_tokens=500,
messages=messages,
tools=tool_specs, # pass the tool specs as an tools argument
)
# ...
Full Code
import os
from anthropic import Anthropic
from hyperpocket_anthropic import PocketAnthropic
pocket = PocketAnthropic(tools=[
"https://github.com/my-org/some-awesome-tool",
"https://github.com/vessl-ai/hyperpocket/tree/main/tools/slack/get-message",
"https://github.com/vessl-ai/hyperpocket/tree/main/tools/slack/post-message",
]
)
# get anthropic compatible tool specs from pocket
tool_specs = pocket.get_anthropic_tool_specs()
messages = [
{
"role": "user",
"content": "get slack message",
}
]
llm = Anthropic()
response = llm.messages.create(
model=os.getenv("ANTHROPIC_MODEL_NAME"),
max_tokens=500,
messages=messages,
tools=tool_specs, # pass the tool specs as an tools argument
)
tool_result_blocks = []
for block in response.content:
if block.type == "tool_use":
tool_result_block = pocket.invoke(block) # tool call by pocket
tool_result_blocks.append(tool_result_block)
messages.append({"role": "user", "content": tool_result_blocks})
response_after_tool_call = llm.messages.create(
model=os.getenv("ANTHROPIC_MODEL_NAME"),
max_tokens=500,
messages=messages,
tools=tool_specs, # pass the tool specs as an tools argument
)
Examples
import os
from anthropic import Anthropic
from hyperpocket_anthropic import PocketAnthropic
client = Anthropic()
pocket = PocketAnthropic(tools=[
"https://github.com/my-org/some-awesome-tool",
"https://github.com/vessl-ai/hyperpocket/tree/main/tools/slack/get-message",
"https://github.com/vessl-ai/hyperpocket/tree/main/tools/slack/post-message",
]
)
tool_specs = pocket.get_anthropic_tool_specs()
messages = []
while True:
print("user(q to quit) : ", end="")
user_input = input()
if user_input == "q":
break
if user_input == "":
continue
messages.append({"role": "user", "content": user_input})
while True:
response = client.messages.create(
model=os.getenv("ANTHROPIC_MODEL_NAME"),
max_tokens=500,
messages=messages,
tools=tool_specs,
)
messages.append({"role": "assistant", "content": response.content})
tool_result_blocks = []
for block in response.content:
if block.type == "text":
print("[ai] response : ", block.text)
elif block.type == "tool_use":
tool_result_block = pocket.invoke(block)
tool_result_blocks.append(tool_result_block)
print("[tool] response : ", tool_result_block["content"])
messages.append({"role": "user", "content": tool_result_blocks})
if response.stop_reason != "tool_use":
break
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hyperpocket_anthropic-0.3.7.tar.gz.
File metadata
- Download URL: hyperpocket_anthropic-0.3.7.tar.gz
- Upload date:
- Size: 59.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8638450cf955800db0861f83af26a46a6e64982ee95bec52647deba1aca7b803
|
|
| MD5 |
af455dfd9bbae96f19342ad9c5b80440
|
|
| BLAKE2b-256 |
c3c7cb5df2730031af045bb1b2410c453c4dff47acdd84f5275f3fdc1bf13ce1
|
File details
Details for the file hyperpocket_anthropic-0.3.7-py3-none-any.whl.
File metadata
- Download URL: hyperpocket_anthropic-0.3.7-py3-none-any.whl
- Upload date:
- Size: 3.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
912028e34249eb8282ea5488bd109ac871063966fb545dd834489e58918fa780
|
|
| MD5 |
2acb7d50198d174db175843acb7624ca
|
|
| BLAKE2b-256 |
1c73352ef51cec88d283868b4964e7affb4e26e3d2e7a2cdebd92a34b8d0f7f2
|