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-messages",
"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-messages",
"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-messages",
"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
Metadata
Release files for hyperpocket-anthropic 0.5.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| hyperpocket_anthropic-0.5.7.tar.gz | 59.1 kB | Without provenance | Details for hyperpocket_anthropic-0.5.7.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| hyperpocket_anthropic-0.5.7-py3-none-any.whl | Python 3 | none | any | Details for hyperpocket_anthropic-0.5.7-py3-none-any.whl |
Total release size: 62.8 kB
Release files / hyperpocket_anthropic-0.5.7.tar.gz
| Download URL | hyperpocket_anthropic-0.5.7.tar.gz |
|---|---|
| Size | 59.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c88787a809547514142abedd679b7fef62211de412e46954d6309903ef2aa96a
|
|
BLAKE2b-256 checksum How to use checksums |
65052fe106cbbbbaea8fe7ed89686d221e40df2cfd2d326cc6555c8b239c308d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.14
|
Release files / hyperpocket_anthropic-0.5.7-py3-none-any.whl
| Download URL | hyperpocket_anthropic-0.5.7-py3-none-any.whl |
|---|---|
| Size | 3.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bd31773b375ea70564d481d66d6f1c85a6af96df4ac415d336d927e5554d44c5
|
|
BLAKE2b-256 checksum How to use checksums |
ac01e9532d575f7795d6c1867be7bc91f662eeefa7d7d011d148c64bfdfcffbc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.14
|
Security for hyperpocket-anthropic 0.5.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.