hyperpocket-anthropic 0.1.7__py3-none-any.whl → 0.1.9__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- hyperpocket_anthropic/pocket_anthropic.py +49 -23
- hyperpocket_anthropic/util/tool_to_anthropic_spec.py +3 -3
- {hyperpocket_anthropic-0.1.7.dist-info → hyperpocket_anthropic-0.1.9.dist-info}/METADATA +27 -30
- hyperpocket_anthropic-0.1.9.dist-info/RECORD +7 -0
- {hyperpocket_anthropic-0.1.7.dist-info → hyperpocket_anthropic-0.1.9.dist-info}/WHEEL +1 -1
- hyperpocket_anthropic-0.1.7.dist-info/RECORD +0 -7
@@ -1,5 +1,7 @@
|
|
1
1
|
import json
|
2
|
-
from typing import List
|
2
|
+
from typing import List, Optional
|
3
|
+
|
4
|
+
from pydantic import BaseModel
|
3
5
|
|
4
6
|
try:
|
5
7
|
from anthropic.types import ToolResultBlockParam, ToolUseBlock
|
@@ -14,9 +16,27 @@ from hyperpocket_anthropic.util import tool_to_anthropic_spec
|
|
14
16
|
|
15
17
|
class PocketAnthropic(Pocket):
|
16
18
|
def invoke(self, tool_use_block: ToolUseBlock, **kwargs) -> ToolResultBlockParam:
|
17
|
-
|
19
|
+
if isinstance(tool_use_block.input, str):
|
20
|
+
arg = json.loads(tool_use_block.input)
|
21
|
+
else:
|
22
|
+
arg = tool_use_block.input
|
23
|
+
|
24
|
+
if self.use_profile:
|
25
|
+
body = arg.pop("body")
|
26
|
+
thread_id = arg.pop("thread_id", "default")
|
27
|
+
profile = arg.pop("profile", "default")
|
28
|
+
else:
|
29
|
+
body = arg
|
30
|
+
thread_id = "default"
|
31
|
+
profile = "default"
|
32
|
+
|
33
|
+
if isinstance(body, BaseModel):
|
34
|
+
body = body.model_dump()
|
35
|
+
elif isinstance(body, str):
|
36
|
+
body = json.loads(body)
|
37
|
+
|
18
38
|
result, interrupted = self.invoke_with_state(
|
19
|
-
tool_use_block.name, body=body, **kwargs
|
39
|
+
tool_use_block.name, body=body, thread_id=thread_id, profile=profile, **kwargs
|
20
40
|
)
|
21
41
|
say = result
|
22
42
|
if interrupted:
|
@@ -33,9 +53,27 @@ class PocketAnthropic(Pocket):
|
|
33
53
|
async def ainvoke(
|
34
54
|
self, tool_use_block: ToolUseBlock, **kwargs
|
35
55
|
) -> ToolResultBlockParam:
|
36
|
-
|
56
|
+
if isinstance(tool_use_block.input, str):
|
57
|
+
arg = json.loads(tool_use_block.input)
|
58
|
+
else:
|
59
|
+
arg = tool_use_block.input
|
60
|
+
|
61
|
+
if self.use_profile:
|
62
|
+
body = arg.pop("body")
|
63
|
+
thread_id = arg.pop("thread_id", "default")
|
64
|
+
profile = arg.pop("profile", "default")
|
65
|
+
else:
|
66
|
+
body = arg
|
67
|
+
thread_id = "default"
|
68
|
+
profile = "default"
|
69
|
+
|
70
|
+
if isinstance(body, BaseModel):
|
71
|
+
body = body.model_dump()
|
72
|
+
elif isinstance(body, str):
|
73
|
+
body = json.loads(body)
|
74
|
+
|
37
75
|
result, interrupted = await self.ainvoke_with_state(
|
38
|
-
tool_use_block.name, body=body, **kwargs
|
76
|
+
tool_use_block.name, body=body, thread_id=thread_id, profile=profile, **kwargs
|
39
77
|
)
|
40
78
|
say = result
|
41
79
|
|
@@ -50,28 +88,16 @@ class PocketAnthropic(Pocket):
|
|
50
88
|
|
51
89
|
return tool_result_block
|
52
90
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
arg = json.loads(tool_use_block.input)
|
57
|
-
body = arg["body"]
|
58
|
-
else:
|
59
|
-
arg = tool_use_block.input
|
60
|
-
body = arg["body"]
|
61
|
-
|
62
|
-
if isinstance(body, str):
|
63
|
-
body = json.loads(body)
|
64
|
-
|
65
|
-
return body
|
91
|
+
def get_anthropic_tool_specs(self, use_profile: Optional[bool] = None) -> List[dict]:
|
92
|
+
if use_profile is not None:
|
93
|
+
self.use_profile = use_profile
|
66
94
|
|
67
|
-
def get_anthropic_tool_specs(self) -> List[dict]:
|
68
95
|
specs = []
|
69
|
-
for tool in self.tools.values():
|
96
|
+
for tool in self.core.tools.values():
|
70
97
|
spec = self.get_anthropic_tool_spec(tool)
|
71
98
|
specs.append(spec)
|
72
99
|
return specs
|
73
100
|
|
74
|
-
|
75
|
-
|
76
|
-
spec = tool_to_anthropic_spec(tool)
|
101
|
+
def get_anthropic_tool_spec(self, tool: Tool) -> dict:
|
102
|
+
spec = tool_to_anthropic_spec(tool, use_profile=self.use_profile)
|
77
103
|
return spec
|
@@ -2,10 +2,10 @@ from hyperpocket.tool import Tool
|
|
2
2
|
from hyperpocket.util.flatten_json_schema import flatten_json_schema
|
3
3
|
|
4
4
|
|
5
|
-
def tool_to_anthropic_spec(tool: Tool) -> dict:
|
5
|
+
def tool_to_anthropic_spec(tool: Tool, use_profile: bool) -> dict:
|
6
6
|
name = tool.name
|
7
|
-
description = tool.
|
8
|
-
arg_schema = tool.schema_model()
|
7
|
+
description = tool.get_description(use_profile=use_profile)
|
8
|
+
arg_schema = tool.schema_model(use_profile=use_profile)
|
9
9
|
json_schema = flatten_json_schema(arg_schema.model_json_schema())
|
10
10
|
|
11
11
|
anthropic_spec = {
|
@@ -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.9
|
4
|
+
Author-email: Hyperpocket Team <hyperpocket@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
|
+
```
|
@@ -0,0 +1,7 @@
|
|
1
|
+
hyperpocket_anthropic/__init__.py,sha256=XZl2uODSPMjSOO1LwrJOVMUD1qmGCuykx9SDePN7gLo,98
|
2
|
+
hyperpocket_anthropic/pocket_anthropic.py,sha256=UViv8vIWJ88eItWMAIGUBhCXZQWCn2PYc2EuQdgoAPs,3263
|
3
|
+
hyperpocket_anthropic/util/__init__.py,sha256=U8x3PBHTFMpbtbAA5-pQVsggQ3Yph4oeC13wfyzK21I,123
|
4
|
+
hyperpocket_anthropic/util/tool_to_anthropic_spec.py,sha256=Lnxs-RMdHkpswjG1aJeEXGuJe8vQfWsbZccsbdPb3_U,749
|
5
|
+
hyperpocket_anthropic-0.1.9.dist-info/METADATA,sha256=W9Tc1Ltb1bNVCE3SWqk2MYWy8O-6x1xH0_46u3e9Jqw,4826
|
6
|
+
hyperpocket_anthropic-0.1.9.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
7
|
+
hyperpocket_anthropic-0.1.9.dist-info/RECORD,,
|
@@ -1,7 +0,0 @@
|
|
1
|
-
hyperpocket_anthropic/__init__.py,sha256=XZl2uODSPMjSOO1LwrJOVMUD1qmGCuykx9SDePN7gLo,98
|
2
|
-
hyperpocket_anthropic/pocket_anthropic.py,sha256=gv7K6tfqDylYgn-SyBvySzwZTkz4G1mhJyQi5-6NHKM,2304
|
3
|
-
hyperpocket_anthropic/util/__init__.py,sha256=U8x3PBHTFMpbtbAA5-pQVsggQ3Yph4oeC13wfyzK21I,123
|
4
|
-
hyperpocket_anthropic/util/tool_to_anthropic_spec.py,sha256=lMq1QiWDPhPjJ3dPzQOJhJdF_F4Y-HwXiBC2dQf_ul4,678
|
5
|
-
hyperpocket_anthropic-0.1.7.dist-info/METADATA,sha256=gBPSSGKj27mq8UfrTfF-tSJCwlh26569EfT3JmB5PE4,4710
|
6
|
-
hyperpocket_anthropic-0.1.7.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
7
|
-
hyperpocket_anthropic-0.1.7.dist-info/RECORD,,
|