hyperpocket-anthropic 0.1.7__tar.gz → 0.1.8__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- hyperpocket_anthropic-0.1.8/.gitignore +157 -0
- {hyperpocket_anthropic-0.1.7 → hyperpocket_anthropic-0.1.8}/PKG-INFO +27 -30
- {hyperpocket_anthropic-0.1.7 → hyperpocket_anthropic-0.1.8}/README.md +20 -17
- hyperpocket_anthropic-0.1.8/__init__.py +0 -0
- {hyperpocket_anthropic-0.1.7 → hyperpocket_anthropic-0.1.8}/hyperpocket_anthropic/pocket_anthropic.py +1 -1
- hyperpocket_anthropic-0.1.8/pyproject.toml +18 -0
- hyperpocket_anthropic-0.1.8/tests/__init__.py +0 -0
- hyperpocket_anthropic-0.1.8/tests/test_pocket_anthropic.py +147 -0
- hyperpocket_anthropic-0.1.8/uv.lock +1103 -0
- hyperpocket_anthropic-0.1.7/pyproject.toml +0 -16
- {hyperpocket_anthropic-0.1.7 → hyperpocket_anthropic-0.1.8}/hyperpocket_anthropic/__init__.py +0 -0
- {hyperpocket_anthropic-0.1.7 → hyperpocket_anthropic-0.1.8}/hyperpocket_anthropic/util/__init__.py +0 -0
- {hyperpocket_anthropic-0.1.7 → hyperpocket_anthropic-0.1.8}/hyperpocket_anthropic/util/tool_to_anthropic_spec.py +0 -0
@@ -0,0 +1,157 @@
|
|
1
|
+
.vs/
|
2
|
+
.vscode/
|
3
|
+
.idea/
|
4
|
+
# Byte-compiled / optimized / DLL files
|
5
|
+
__pycache__/
|
6
|
+
*.py[cod]
|
7
|
+
*$py.class
|
8
|
+
|
9
|
+
# C extensions
|
10
|
+
*.so
|
11
|
+
|
12
|
+
# Distribution / packaging
|
13
|
+
.Python
|
14
|
+
build/
|
15
|
+
develop-eggs/
|
16
|
+
dist/
|
17
|
+
downloads/
|
18
|
+
eggs/
|
19
|
+
.eggs/
|
20
|
+
lib/
|
21
|
+
lib64/
|
22
|
+
parts/
|
23
|
+
sdist/
|
24
|
+
var/
|
25
|
+
wheels/
|
26
|
+
pip-wheel-metadata/
|
27
|
+
share/python-wheels/
|
28
|
+
*.egg-info/
|
29
|
+
.installed.cfg
|
30
|
+
*.egg
|
31
|
+
MANIFEST
|
32
|
+
|
33
|
+
# Google GitHub Actions credentials files created by:
|
34
|
+
# https://github.com/google-github-actions/auth
|
35
|
+
#
|
36
|
+
# That action recommends adding this gitignore to prevent accidentally committing keys.
|
37
|
+
gha-creds-*.json
|
38
|
+
|
39
|
+
# PyInstaller
|
40
|
+
# Usually these files are written by a python script from a template
|
41
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
42
|
+
*.manifest
|
43
|
+
*.spec
|
44
|
+
|
45
|
+
# Unit test / coverage reports
|
46
|
+
htmlcov/
|
47
|
+
.tox/
|
48
|
+
.nox/
|
49
|
+
.coverage
|
50
|
+
.coverage.*
|
51
|
+
.cache
|
52
|
+
nosetests.xml
|
53
|
+
coverage.xml
|
54
|
+
*.cover
|
55
|
+
*.py,cover
|
56
|
+
.hypothesis/
|
57
|
+
.pytest_cache/
|
58
|
+
|
59
|
+
# Translations
|
60
|
+
*.mo
|
61
|
+
*.pot
|
62
|
+
|
63
|
+
# Django stuff:
|
64
|
+
*.log
|
65
|
+
local_settings.py
|
66
|
+
db.sqlite3
|
67
|
+
db.sqlite3-journal
|
68
|
+
|
69
|
+
# Flask stuff:
|
70
|
+
instance/
|
71
|
+
.webassets-cache
|
72
|
+
|
73
|
+
# Scrapy stuff:
|
74
|
+
.scrapy
|
75
|
+
|
76
|
+
|
77
|
+
# Jupyter Notebook
|
78
|
+
.ipynb_checkpoints
|
79
|
+
notebooks/
|
80
|
+
|
81
|
+
# IPython
|
82
|
+
profile_default/
|
83
|
+
ipython_config.py
|
84
|
+
|
85
|
+
# pyenv
|
86
|
+
.python-version
|
87
|
+
|
88
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
|
89
|
+
__pypackages__/
|
90
|
+
|
91
|
+
# Celery stuff
|
92
|
+
celerybeat-schedule
|
93
|
+
celerybeat.pid
|
94
|
+
|
95
|
+
# SageMath parsed files
|
96
|
+
*.sage.py
|
97
|
+
|
98
|
+
# Environments
|
99
|
+
.env
|
100
|
+
.envrc
|
101
|
+
.venv*
|
102
|
+
venv*
|
103
|
+
env/
|
104
|
+
ENV/
|
105
|
+
env.bak/
|
106
|
+
|
107
|
+
# Spyder project settings
|
108
|
+
.spyderproject
|
109
|
+
.spyproject
|
110
|
+
|
111
|
+
# Rope project settings
|
112
|
+
.ropeproject
|
113
|
+
|
114
|
+
# mkdocs documentation
|
115
|
+
/site
|
116
|
+
|
117
|
+
# mypy
|
118
|
+
.mypy_cache/
|
119
|
+
.mypy_cache_test/
|
120
|
+
.dmypy.json
|
121
|
+
dmypy.json
|
122
|
+
|
123
|
+
# Pyre type checker
|
124
|
+
.pyre/
|
125
|
+
|
126
|
+
# macOS display setting files
|
127
|
+
.DS_Store
|
128
|
+
|
129
|
+
# Wandb directory
|
130
|
+
wandb/
|
131
|
+
|
132
|
+
# asdf tool versions
|
133
|
+
.tool-versions
|
134
|
+
/.ruff_cache/
|
135
|
+
|
136
|
+
*.pkl
|
137
|
+
*.bin
|
138
|
+
|
139
|
+
# integration test artifacts
|
140
|
+
data_map*
|
141
|
+
\[('_type', 'fake'), ('stop', None)]
|
142
|
+
|
143
|
+
# Replit files
|
144
|
+
*replit*
|
145
|
+
|
146
|
+
|
147
|
+
prof
|
148
|
+
virtualenv/
|
149
|
+
|
150
|
+
# Ignore dynaconf secret files
|
151
|
+
**/.secrets.toml
|
152
|
+
*.xml
|
153
|
+
*.iml
|
154
|
+
pocket.lock
|
155
|
+
.log/
|
156
|
+
.pocket/
|
157
|
+
_build/
|
@@ -1,16 +1,10 @@
|
|
1
|
-
Metadata-Version: 2.
|
1
|
+
Metadata-Version: 2.4
|
2
2
|
Name: hyperpocket-anthropic
|
3
|
-
Version: 0.1.
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
Requires-
|
8
|
-
Classifier: Programming Language :: Python :: 3
|
9
|
-
Classifier: Programming Language :: Python :: 3.11
|
10
|
-
Classifier: Programming Language :: Python :: 3.12
|
11
|
-
Classifier: Programming Language :: Python :: 3.13
|
12
|
-
Requires-Dist: anthropic (>=0.40.0,<0.41.0)
|
13
|
-
Requires-Dist: hyperpocket (>=0.0.3,<0.0.4)
|
3
|
+
Version: 0.1.8
|
4
|
+
Author-email: moon <moon@vessl.ai>
|
5
|
+
Requires-Python: >=3.10
|
6
|
+
Requires-Dist: anthropic>=0.40.0
|
7
|
+
Requires-Dist: hyperpocket>=0.0.3
|
14
8
|
Description-Content-Type: text/markdown
|
15
9
|
|
16
10
|
## Anthropic extensions
|
@@ -18,13 +12,15 @@ Description-Content-Type: text/markdown
|
|
18
12
|
### Get Pocket Anthropic Tool Spec
|
19
13
|
|
20
14
|
```python
|
21
|
-
|
22
|
-
|
15
|
+
from hyperpocket.tool import from_git
|
16
|
+
|
17
|
+
from hyperpocket_anthropic import PocketAnthropic
|
23
18
|
|
24
19
|
pocket = PocketAnthropic(tools=[
|
25
|
-
|
26
|
-
|
27
|
-
"https://github.com/
|
20
|
+
"https://github.com/my-org/some-awesome-tool",
|
21
|
+
from_git("https://github.com/vessl-ai/hyperawesometools", "main", "managed-tools/slack/get-message"),
|
22
|
+
from_git("https://github.com/vessl-ai/hyperawesometools", "main", "managed-tools/slack/post-message"),
|
23
|
+
]
|
28
24
|
)
|
29
25
|
|
30
26
|
# get anthropic compatible tool specs from pocket
|
@@ -90,14 +86,15 @@ response_after_tool_call = llm.messages.create(
|
|
90
86
|
import os
|
91
87
|
|
92
88
|
from anthropic import Anthropic
|
89
|
+
from hyperpocket.tool import from_git
|
93
90
|
|
94
|
-
|
95
|
-
from pocket_anthropic import PocketAnthropic
|
91
|
+
from hyperpocket_anthropic import PocketAnthropic
|
96
92
|
|
97
93
|
pocket = PocketAnthropic(tools=[
|
98
|
-
|
99
|
-
|
100
|
-
"https://github.com/
|
94
|
+
"https://github.com/my-org/some-awesome-tool",
|
95
|
+
from_git("https://github.com/vessl-ai/hyperawesometools", "main", "managed-tools/slack/get-message"),
|
96
|
+
from_git("https://github.com/vessl-ai/hyperawesometools", "main", "managed-tools/slack/post-message"),
|
97
|
+
]
|
101
98
|
)
|
102
99
|
|
103
100
|
# get anthropic compatible tool specs from pocket
|
@@ -141,16 +138,16 @@ response_after_tool_call = llm.messages.create(
|
|
141
138
|
import os
|
142
139
|
|
143
140
|
from anthropic import Anthropic
|
141
|
+
from hyperpocket.tool import from_git
|
144
142
|
|
145
|
-
|
146
|
-
from pocket_anthropic import PocketAnthropic
|
143
|
+
from hyperpocket_anthropic import PocketAnthropic
|
147
144
|
|
148
145
|
client = Anthropic()
|
149
|
-
pocket = PocketAnthropic(
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
146
|
+
pocket = PocketAnthropic(tools=[
|
147
|
+
"https://github.com/my-org/some-awesome-tool",
|
148
|
+
from_git("https://github.com/vessl-ai/hyperawesometools", "main", "managed-tools/slack/get-message"),
|
149
|
+
from_git("https://github.com/vessl-ai/hyperawesometools", "main", "managed-tools/slack/post-message"),
|
150
|
+
]
|
154
151
|
)
|
155
152
|
|
156
153
|
tool_specs = pocket.get_anthropic_tool_specs()
|
@@ -191,4 +188,4 @@ while True:
|
|
191
188
|
|
192
189
|
if response.stop_reason != "tool_use":
|
193
190
|
break
|
194
|
-
```
|
191
|
+
```
|
@@ -3,13 +3,15 @@
|
|
3
3
|
### Get Pocket Anthropic Tool Spec
|
4
4
|
|
5
5
|
```python
|
6
|
-
|
7
|
-
|
6
|
+
from hyperpocket.tool import from_git
|
7
|
+
|
8
|
+
from hyperpocket_anthropic import PocketAnthropic
|
8
9
|
|
9
10
|
pocket = PocketAnthropic(tools=[
|
10
|
-
|
11
|
-
|
12
|
-
"https://github.com/
|
11
|
+
"https://github.com/my-org/some-awesome-tool",
|
12
|
+
from_git("https://github.com/vessl-ai/hyperawesometools", "main", "managed-tools/slack/get-message"),
|
13
|
+
from_git("https://github.com/vessl-ai/hyperawesometools", "main", "managed-tools/slack/post-message"),
|
14
|
+
]
|
13
15
|
)
|
14
16
|
|
15
17
|
# get anthropic compatible tool specs from pocket
|
@@ -75,14 +77,15 @@ response_after_tool_call = llm.messages.create(
|
|
75
77
|
import os
|
76
78
|
|
77
79
|
from anthropic import Anthropic
|
80
|
+
from hyperpocket.tool import from_git
|
78
81
|
|
79
|
-
|
80
|
-
from pocket_anthropic import PocketAnthropic
|
82
|
+
from hyperpocket_anthropic import PocketAnthropic
|
81
83
|
|
82
84
|
pocket = PocketAnthropic(tools=[
|
83
|
-
|
84
|
-
|
85
|
-
"https://github.com/
|
85
|
+
"https://github.com/my-org/some-awesome-tool",
|
86
|
+
from_git("https://github.com/vessl-ai/hyperawesometools", "main", "managed-tools/slack/get-message"),
|
87
|
+
from_git("https://github.com/vessl-ai/hyperawesometools", "main", "managed-tools/slack/post-message"),
|
88
|
+
]
|
86
89
|
)
|
87
90
|
|
88
91
|
# get anthropic compatible tool specs from pocket
|
@@ -126,16 +129,16 @@ response_after_tool_call = llm.messages.create(
|
|
126
129
|
import os
|
127
130
|
|
128
131
|
from anthropic import Anthropic
|
132
|
+
from hyperpocket.tool import from_git
|
129
133
|
|
130
|
-
|
131
|
-
from pocket_anthropic import PocketAnthropic
|
134
|
+
from hyperpocket_anthropic import PocketAnthropic
|
132
135
|
|
133
136
|
client = Anthropic()
|
134
|
-
pocket = PocketAnthropic(
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
137
|
+
pocket = PocketAnthropic(tools=[
|
138
|
+
"https://github.com/my-org/some-awesome-tool",
|
139
|
+
from_git("https://github.com/vessl-ai/hyperawesometools", "main", "managed-tools/slack/get-message"),
|
140
|
+
from_git("https://github.com/vessl-ai/hyperawesometools", "main", "managed-tools/slack/post-message"),
|
141
|
+
]
|
139
142
|
)
|
140
143
|
|
141
144
|
tool_specs = pocket.get_anthropic_tool_specs()
|
File without changes
|
@@ -66,7 +66,7 @@ class PocketAnthropic(Pocket):
|
|
66
66
|
|
67
67
|
def get_anthropic_tool_specs(self) -> List[dict]:
|
68
68
|
specs = []
|
69
|
-
for tool in self.tools.values():
|
69
|
+
for tool in self.core.tools.values():
|
70
70
|
spec = self.get_anthropic_tool_spec(tool)
|
71
71
|
specs.append(spec)
|
72
72
|
return specs
|
@@ -0,0 +1,18 @@
|
|
1
|
+
[project]
|
2
|
+
name = "hyperpocket-anthropic"
|
3
|
+
version = "0.1.8"
|
4
|
+
description = ""
|
5
|
+
authors = [{ name = "moon", email = "moon@vessl.ai" }]
|
6
|
+
requires-python = ">=3.10"
|
7
|
+
readme = "README.md"
|
8
|
+
dependencies = ["anthropic>=0.40.0", "hyperpocket>=0.0.3"]
|
9
|
+
|
10
|
+
[tool.uv.sources]
|
11
|
+
hyperpocket = { path = "../../hyperpocket", editable = true }
|
12
|
+
|
13
|
+
[dependency-groups]
|
14
|
+
dev = ["pytest>=8.3.4", "ruff>=0.8.6"]
|
15
|
+
|
16
|
+
[build-system]
|
17
|
+
requires = ["hatchling"]
|
18
|
+
build-backend = "hatchling.build"
|
File without changes
|
@@ -0,0 +1,147 @@
|
|
1
|
+
from unittest.async_case import IsolatedAsyncioTestCase
|
2
|
+
|
3
|
+
from anthropic import Anthropic
|
4
|
+
from pydantic import BaseModel
|
5
|
+
|
6
|
+
from hyperpocket.config import config, secret
|
7
|
+
from hyperpocket.tool import from_git
|
8
|
+
from hyperpocket_anthropic import PocketAnthropic
|
9
|
+
|
10
|
+
|
11
|
+
class TestPocketAnthropic(IsolatedAsyncioTestCase):
|
12
|
+
@staticmethod
|
13
|
+
def add(a: int, b: int) -> int:
|
14
|
+
"""
|
15
|
+
Add two numbers
|
16
|
+
|
17
|
+
Args:
|
18
|
+
a(int): first number
|
19
|
+
b(int): second number
|
20
|
+
|
21
|
+
"""
|
22
|
+
|
23
|
+
return a + b
|
24
|
+
|
25
|
+
class FirstNumber(BaseModel):
|
26
|
+
first: int
|
27
|
+
|
28
|
+
class SecondNumber(BaseModel):
|
29
|
+
second: int
|
30
|
+
|
31
|
+
@staticmethod
|
32
|
+
def sub_pydantic_args(a: FirstNumber, b: SecondNumber):
|
33
|
+
"""
|
34
|
+
sub two numbers
|
35
|
+
|
36
|
+
Args:
|
37
|
+
a(FirstNumber): first number
|
38
|
+
b(SecondNumber): second number
|
39
|
+
"""
|
40
|
+
return a.first - b.second
|
41
|
+
|
42
|
+
async def asyncSetUp(self):
|
43
|
+
config.public_server_port = "https"
|
44
|
+
config.public_hostname = "localhost"
|
45
|
+
config.public_server_port = 8001
|
46
|
+
config.internal_server_port = 8000
|
47
|
+
config.enable_local_callback_proxy = True
|
48
|
+
|
49
|
+
self.pocket = PocketAnthropic(
|
50
|
+
tools=[
|
51
|
+
from_git("https://github.com/vessl-ai/hyperawesometools", "main", "managed-tools/simple-echo-tool"),
|
52
|
+
self.add,
|
53
|
+
self.sub_pydantic_args
|
54
|
+
],
|
55
|
+
)
|
56
|
+
self.tool_specs = self.pocket.get_anthropic_tool_specs()
|
57
|
+
self.client = Anthropic(api_key=secret["ANTHROPIC_API_KEY"])
|
58
|
+
|
59
|
+
async def asyncTearDown(self):
|
60
|
+
self.pocket._teardown_server()
|
61
|
+
|
62
|
+
def test_get_tools_from_pocket(self):
|
63
|
+
# given
|
64
|
+
pocket = PocketAnthropic(tools=[
|
65
|
+
from_git("https://github.com/vessl-ai/hyperawesometools", "main", "managed-tools/slack/get-message"),
|
66
|
+
from_git("https://github.com/vessl-ai/hyperawesometools", "main", "managed-tools/slack/post-message"),
|
67
|
+
])
|
68
|
+
|
69
|
+
# when
|
70
|
+
specs = pocket.get_anthropic_tool_specs()
|
71
|
+
get_tool, send_tool = specs[0], specs[1]
|
72
|
+
|
73
|
+
# then
|
74
|
+
self.assertIsInstance(get_tool, dict)
|
75
|
+
self.assertEqual(get_tool["name"], 'slack_get_messages')
|
76
|
+
self.assertTrue("body" in get_tool["input_schema"]["properties"])
|
77
|
+
self.assertTrue("channel" in get_tool["input_schema"]["properties"]["body"]["properties"])
|
78
|
+
self.assertTrue("limit" in get_tool["input_schema"]["properties"]["body"]["properties"])
|
79
|
+
|
80
|
+
self.assertIsInstance(send_tool, dict)
|
81
|
+
self.assertEqual(send_tool["name"], 'slack_send_messages')
|
82
|
+
self.assertTrue("body" in send_tool["input_schema"]["properties"])
|
83
|
+
self.assertTrue("channel" in send_tool["input_schema"]["properties"]["body"]["properties"])
|
84
|
+
self.assertTrue("text" in send_tool["input_schema"]["properties"]["body"]["properties"])
|
85
|
+
|
86
|
+
async def test_function_tool(self):
|
87
|
+
response = self.client.messages.create(
|
88
|
+
model="claude-3-5-haiku-latest",
|
89
|
+
max_tokens=500,
|
90
|
+
messages=[{
|
91
|
+
"role": "user",
|
92
|
+
"content": "add 1, 2"
|
93
|
+
}],
|
94
|
+
tools=self.tool_specs,
|
95
|
+
)
|
96
|
+
|
97
|
+
tool_result_block = None
|
98
|
+
for block in response.content:
|
99
|
+
if block.type == "tool_use":
|
100
|
+
tool_result_block = await self.pocket.ainvoke(block)
|
101
|
+
|
102
|
+
# then
|
103
|
+
self.assertEqual(response.stop_reason, "tool_use")
|
104
|
+
self.assertIsNotNone(tool_result_block)
|
105
|
+
self.assertEqual(tool_result_block["content"], "3")
|
106
|
+
|
107
|
+
async def test_pydantic_function_tool(self):
|
108
|
+
response = self.client.messages.create(
|
109
|
+
model="claude-3-5-haiku-latest",
|
110
|
+
max_tokens=500,
|
111
|
+
messages=[{
|
112
|
+
"role": "user",
|
113
|
+
"content": "sub 1, 2"
|
114
|
+
}],
|
115
|
+
tools=self.tool_specs,
|
116
|
+
)
|
117
|
+
|
118
|
+
tool_result_block = None
|
119
|
+
for block in response.content:
|
120
|
+
if block.type == "tool_use":
|
121
|
+
tool_result_block = await self.pocket.ainvoke(block)
|
122
|
+
|
123
|
+
# then
|
124
|
+
self.assertEqual(response.stop_reason, "tool_use")
|
125
|
+
self.assertIsNotNone(tool_result_block)
|
126
|
+
self.assertEqual(tool_result_block["content"], "-1")
|
127
|
+
|
128
|
+
async def test_wasm_tool(self):
|
129
|
+
response = self.client.messages.create(
|
130
|
+
model="claude-3-5-haiku-latest",
|
131
|
+
max_tokens=500,
|
132
|
+
messages=[{
|
133
|
+
"role": "user",
|
134
|
+
"content": "echo 'hello world'"
|
135
|
+
}],
|
136
|
+
tools=self.tool_specs,
|
137
|
+
)
|
138
|
+
|
139
|
+
tool_result_block = None
|
140
|
+
for block in response.content:
|
141
|
+
if block.type == "tool_use":
|
142
|
+
tool_result_block = await self.pocket.ainvoke(block)
|
143
|
+
|
144
|
+
# then
|
145
|
+
self.assertEqual(response.stop_reason, "tool_use")
|
146
|
+
self.assertIsNotNone(tool_result_block)
|
147
|
+
self.assertTrue(tool_result_block["content"].startswith("echo message : hello world"))
|