hyperpocket-anthropic 0.1.8__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 +48 -22
- hyperpocket_anthropic/util/tool_to_anthropic_spec.py +3 -3
- {hyperpocket_anthropic-0.1.8.dist-info → hyperpocket_anthropic-0.1.9.dist-info}/METADATA +2 -2
- hyperpocket_anthropic-0.1.9.dist-info/RECORD +7 -0
- hyperpocket_anthropic-0.1.8.dist-info/RECORD +0 -7
- {hyperpocket_anthropic-0.1.8.dist-info → hyperpocket_anthropic-0.1.9.dist-info}/WHEEL +0 -0
@@ -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
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,7 +1,7 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: hyperpocket-anthropic
|
3
|
-
Version: 0.1.
|
4
|
-
Author-email:
|
3
|
+
Version: 0.1.9
|
4
|
+
Author-email: Hyperpocket Team <hyperpocket@vessl.ai>
|
5
5
|
Requires-Python: >=3.10
|
6
6
|
Requires-Dist: anthropic>=0.40.0
|
7
7
|
Requires-Dist: hyperpocket>=0.0.3
|
@@ -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=XBSxxSeHjzvWx-jiqozf64e8CtBzz3I-dDQ4pBBHnNU,2309
|
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.8.dist-info/METADATA,sha256=Bf6m9nu8oSigeDXx-ND1VGnngCmE0SeauiK7kr0gt0s,4807
|
6
|
-
hyperpocket_anthropic-0.1.8.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
7
|
-
hyperpocket_anthropic-0.1.8.dist-info/RECORD,,
|
File without changes
|