hyperpocket-anthropic 0.1.10__tar.gz → 0.2.1__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hyperpocket-anthropic
3
- Version: 0.1.10
3
+ Version: 0.2.1
4
4
  Author-email: Hyperpocket Team <hyperpocket@vessl.ai>
5
5
  Requires-Python: >=3.10
6
6
  Requires-Dist: anthropic>=0.40.0
@@ -36,7 +36,11 @@ class PocketAnthropic(Pocket):
36
36
  body = json.loads(body)
37
37
 
38
38
  result, interrupted = self.invoke_with_state(
39
- tool_use_block.name, body=body, thread_id=thread_id, profile=profile, **kwargs
39
+ tool_use_block.name,
40
+ body=body,
41
+ thread_id=thread_id,
42
+ profile=profile,
43
+ **kwargs,
40
44
  )
41
45
  say = result
42
46
  if interrupted:
@@ -51,7 +55,7 @@ class PocketAnthropic(Pocket):
51
55
  return tool_result_block
52
56
 
53
57
  async def ainvoke(
54
- self, tool_use_block: ToolUseBlock, **kwargs
58
+ self, tool_use_block: ToolUseBlock, **kwargs
55
59
  ) -> ToolResultBlockParam:
56
60
  if isinstance(tool_use_block.input, str):
57
61
  arg = json.loads(tool_use_block.input)
@@ -73,7 +77,11 @@ class PocketAnthropic(Pocket):
73
77
  body = json.loads(body)
74
78
 
75
79
  result, interrupted = await self.ainvoke_with_state(
76
- tool_use_block.name, body=body, thread_id=thread_id, profile=profile, **kwargs
80
+ tool_use_block.name,
81
+ body=body,
82
+ thread_id=thread_id,
83
+ profile=profile,
84
+ **kwargs,
77
85
  )
78
86
  say = result
79
87
 
@@ -88,7 +96,9 @@ class PocketAnthropic(Pocket):
88
96
 
89
97
  return tool_result_block
90
98
 
91
- def get_anthropic_tool_specs(self, use_profile: Optional[bool] = None) -> List[dict]:
99
+ def get_anthropic_tool_specs(
100
+ self, use_profile: Optional[bool] = None
101
+ ) -> List[dict]:
92
102
  if use_profile is not None:
93
103
  self.use_profile = use_profile
94
104
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "hyperpocket-anthropic"
3
- version = "0.1.10"
3
+ version = "0.2.1"
4
4
  description = ""
5
5
  authors = [{ name = "Hyperpocket Team", email = "hyperpocket@vessl.ai" }]
6
6
  requires-python = ">=3.10"
@@ -16,3 +16,6 @@ dev = ["pytest>=8.3.4", "ruff>=0.8.6"]
16
16
  [build-system]
17
17
  requires = ["hatchling"]
18
18
  build-backend = "hatchling.build"
19
+
20
+ [tool.ruff]
21
+ extend = "../../../.ruff.toml"
@@ -2,10 +2,10 @@ import ast
2
2
  from unittest.async_case import IsolatedAsyncioTestCase
3
3
 
4
4
  from anthropic import Anthropic
5
- from pydantic import BaseModel
6
-
7
5
  from hyperpocket.config import config, secret
8
6
  from hyperpocket.tool import from_git
7
+ from pydantic import BaseModel
8
+
9
9
  from hyperpocket_anthropic import PocketAnthropic
10
10
 
11
11
 
@@ -49,13 +49,18 @@ class TestPocketAnthropicNoProfile(IsolatedAsyncioTestCase):
49
49
 
50
50
  self.pocket = PocketAnthropic(
51
51
  tools=[
52
- from_git("https://github.com/vessl-ai/hyperawesometools", "main",
53
- "managed-tools/none/simple-echo-tool"),
52
+ from_git(
53
+ "https://github.com/vessl-ai/hyperawesometools",
54
+ "main",
55
+ "managed-tools/none/simple-echo-tool",
56
+ ),
54
57
  self.add,
55
- self.sub_pydantic_args
58
+ self.sub_pydantic_args,
56
59
  ],
57
60
  )
58
- self.tool_specs_no_profile = self.pocket.get_anthropic_tool_specs(use_profile=False)
61
+ self.tool_specs_no_profile = self.pocket.get_anthropic_tool_specs(
62
+ use_profile=False
63
+ )
59
64
  self.client = Anthropic(api_key=secret["ANTHROPIC_API_KEY"])
60
65
 
61
66
  async def asyncTearDown(self):
@@ -63,10 +68,20 @@ class TestPocketAnthropicNoProfile(IsolatedAsyncioTestCase):
63
68
 
64
69
  def test_get_tools_from_pocket_no_profile(self):
65
70
  # given
66
- pocket = PocketAnthropic(tools=[
67
- from_git("https://github.com/vessl-ai/hyperawesometools", "main", "managed-tools/slack/get-message"),
68
- from_git("https://github.com/vessl-ai/hyperawesometools", "main", "managed-tools/slack/post-message"),
69
- ])
71
+ pocket = PocketAnthropic(
72
+ tools=[
73
+ from_git(
74
+ "https://github.com/vessl-ai/hyperawesometools",
75
+ "main",
76
+ "managed-tools/slack/get-message",
77
+ ),
78
+ from_git(
79
+ "https://github.com/vessl-ai/hyperawesometools",
80
+ "main",
81
+ "managed-tools/slack/post-message",
82
+ ),
83
+ ]
84
+ )
70
85
 
71
86
  # when
72
87
  specs = pocket.get_anthropic_tool_specs()
@@ -74,12 +89,12 @@ class TestPocketAnthropicNoProfile(IsolatedAsyncioTestCase):
74
89
 
75
90
  # then
76
91
  self.assertIsInstance(get_tool, dict)
77
- self.assertEqual(get_tool["name"], 'slack_get_messages')
92
+ self.assertEqual(get_tool["name"], "slack_get_messages")
78
93
  self.assertTrue("channel" in get_tool["input_schema"]["properties"])
79
94
  self.assertTrue("limit" in get_tool["input_schema"]["properties"])
80
95
 
81
96
  self.assertIsInstance(send_tool, dict)
82
- self.assertEqual(send_tool["name"], 'slack_send_messages')
97
+ self.assertEqual(send_tool["name"], "slack_send_messages")
83
98
  self.assertTrue("channel" in send_tool["input_schema"]["properties"])
84
99
  self.assertTrue("text" in send_tool["input_schema"]["properties"])
85
100
 
@@ -87,10 +102,7 @@ class TestPocketAnthropicNoProfile(IsolatedAsyncioTestCase):
87
102
  response = self.client.messages.create(
88
103
  model="claude-3-5-haiku-latest",
89
104
  max_tokens=500,
90
- messages=[{
91
- "role": "user",
92
- "content": "add 1, 2"
93
- }],
105
+ messages=[{"role": "user", "content": "add 1, 2"}],
94
106
  tools=self.tool_specs_no_profile,
95
107
  )
96
108
 
@@ -108,10 +120,7 @@ class TestPocketAnthropicNoProfile(IsolatedAsyncioTestCase):
108
120
  response = self.client.messages.create(
109
121
  model="claude-3-5-haiku-latest",
110
122
  max_tokens=500,
111
- messages=[{
112
- "role": "user",
113
- "content": "sub 1, 2"
114
- }],
123
+ messages=[{"role": "user", "content": "sub 1, 2"}],
115
124
  tools=self.tool_specs_no_profile,
116
125
  )
117
126
 
@@ -129,10 +138,7 @@ class TestPocketAnthropicNoProfile(IsolatedAsyncioTestCase):
129
138
  response = self.client.messages.create(
130
139
  model="claude-3-5-haiku-latest",
131
140
  max_tokens=500,
132
- messages=[{
133
- "role": "user",
134
- "content": "echo 'hello world'"
135
- }],
141
+ messages=[{"role": "user", "content": "echo 'hello world'"}],
136
142
  tools=self.tool_specs_no_profile,
137
143
  )
138
144
 
@@ -2,10 +2,10 @@ import ast
2
2
  from unittest.async_case import IsolatedAsyncioTestCase
3
3
 
4
4
  from anthropic import Anthropic
5
- from pydantic import BaseModel
6
-
7
5
  from hyperpocket.config import config, secret
8
6
  from hyperpocket.tool import from_git
7
+ from pydantic import BaseModel
8
+
9
9
  from hyperpocket_anthropic import PocketAnthropic
10
10
 
11
11
 
@@ -49,13 +49,18 @@ class TestPocketAnthropicUseProfile(IsolatedAsyncioTestCase):
49
49
 
50
50
  self.pocket = PocketAnthropic(
51
51
  tools=[
52
- from_git("https://github.com/vessl-ai/hyperawesometools", "main",
53
- "managed-tools/none/simple-echo-tool"),
52
+ from_git(
53
+ "https://github.com/vessl-ai/hyperawesometools",
54
+ "main",
55
+ "managed-tools/none/simple-echo-tool",
56
+ ),
54
57
  self.add,
55
- self.sub_pydantic_args
58
+ self.sub_pydantic_args,
56
59
  ],
57
60
  )
58
- self.tool_specs_use_profile = self.pocket.get_anthropic_tool_specs(use_profile=True)
61
+ self.tool_specs_use_profile = self.pocket.get_anthropic_tool_specs(
62
+ use_profile=True
63
+ )
59
64
  self.client = Anthropic(api_key=secret["ANTHROPIC_API_KEY"])
60
65
 
61
66
  async def asyncTearDown(self):
@@ -63,10 +68,20 @@ class TestPocketAnthropicUseProfile(IsolatedAsyncioTestCase):
63
68
 
64
69
  def test_get_tools_from_pocket_use_profile(self):
65
70
  # given
66
- pocket = PocketAnthropic(tools=[
67
- from_git("https://github.com/vessl-ai/hyperawesometools", "main", "managed-tools/slack/get-message"),
68
- from_git("https://github.com/vessl-ai/hyperawesometools", "main", "managed-tools/slack/post-message"),
69
- ])
71
+ pocket = PocketAnthropic(
72
+ tools=[
73
+ from_git(
74
+ "https://github.com/vessl-ai/hyperawesometools",
75
+ "main",
76
+ "managed-tools/slack/get-message",
77
+ ),
78
+ from_git(
79
+ "https://github.com/vessl-ai/hyperawesometools",
80
+ "main",
81
+ "managed-tools/slack/post-message",
82
+ ),
83
+ ]
84
+ )
70
85
 
71
86
  # when
72
87
  specs = pocket.get_anthropic_tool_specs(use_profile=True)
@@ -74,26 +89,30 @@ class TestPocketAnthropicUseProfile(IsolatedAsyncioTestCase):
74
89
 
75
90
  # then
76
91
  self.assertIsInstance(get_tool, dict)
77
- self.assertEqual(get_tool["name"], 'slack_get_messages')
92
+ self.assertEqual(get_tool["name"], "slack_get_messages")
78
93
  self.assertTrue("body" in get_tool["input_schema"]["properties"])
79
- self.assertTrue("channel" in get_tool["input_schema"]["properties"]["body"]["properties"])
80
- self.assertTrue("limit" in get_tool["input_schema"]["properties"]["body"]["properties"])
94
+ self.assertTrue(
95
+ "channel" in get_tool["input_schema"]["properties"]["body"]["properties"]
96
+ )
97
+ self.assertTrue(
98
+ "limit" in get_tool["input_schema"]["properties"]["body"]["properties"]
99
+ )
81
100
 
82
101
  self.assertIsInstance(send_tool, dict)
83
- self.assertEqual(send_tool["name"], 'slack_send_messages')
102
+ self.assertEqual(send_tool["name"], "slack_send_messages")
84
103
  self.assertTrue("body" in send_tool["input_schema"]["properties"])
85
- self.assertTrue("channel" in send_tool["input_schema"]["properties"]["body"]["properties"])
86
- self.assertTrue("text" in send_tool["input_schema"]["properties"]["body"]["properties"])
87
-
104
+ self.assertTrue(
105
+ "channel" in send_tool["input_schema"]["properties"]["body"]["properties"]
106
+ )
107
+ self.assertTrue(
108
+ "text" in send_tool["input_schema"]["properties"]["body"]["properties"]
109
+ )
88
110
 
89
111
  async def test_function_tool_use_profile(self):
90
112
  response = self.client.messages.create(
91
113
  model="claude-3-5-haiku-latest",
92
114
  max_tokens=500,
93
- messages=[{
94
- "role": "user",
95
- "content": "add 1, 2"
96
- }],
115
+ messages=[{"role": "user", "content": "add 1, 2"}],
97
116
  tools=self.tool_specs_use_profile,
98
117
  )
99
118
 
@@ -107,15 +126,11 @@ class TestPocketAnthropicUseProfile(IsolatedAsyncioTestCase):
107
126
  self.assertIsNotNone(tool_result_block)
108
127
  self.assertEqual(tool_result_block["content"], "3")
109
128
 
110
-
111
129
  async def test_pydantic_function_tool_use_profile(self):
112
130
  response = self.client.messages.create(
113
131
  model="claude-3-5-haiku-latest",
114
132
  max_tokens=500,
115
- messages=[{
116
- "role": "user",
117
- "content": "sub 1, 2"
118
- }],
133
+ messages=[{"role": "user", "content": "sub 1, 2"}],
119
134
  tools=self.tool_specs_use_profile,
120
135
  )
121
136
 
@@ -129,15 +144,11 @@ class TestPocketAnthropicUseProfile(IsolatedAsyncioTestCase):
129
144
  self.assertIsNotNone(tool_result_block)
130
145
  self.assertEqual(tool_result_block["content"], "-1")
131
146
 
132
-
133
147
  async def test_wasm_tool_use_profile(self):
134
148
  response = self.client.messages.create(
135
149
  model="claude-3-5-haiku-latest",
136
150
  max_tokens=500,
137
- messages=[{
138
- "role": "user",
139
- "content": "echo 'hello world'"
140
- }],
151
+ messages=[{"role": "user", "content": "echo 'hello world'"}],
141
152
  tools=self.tool_specs_use_profile,
142
153
  )
143
154
 
@@ -151,4 +162,3 @@ class TestPocketAnthropicUseProfile(IsolatedAsyncioTestCase):
151
162
  self.assertEqual(response.stop_reason, "tool_use")
152
163
  self.assertIsNotNone(tool_result_block)
153
164
  self.assertTrue(output["stdout"].startswith("echo message : hello world"))
154
-