hyperpocket-llamaindex 0.0.1__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.
@@ -0,0 +1,44 @@
|
|
1
|
+
from typing import List, Any
|
2
|
+
|
3
|
+
try:
|
4
|
+
from llama_index.core.tools import FunctionTool, BaseTool, ToolMetadata
|
5
|
+
except ImportError:
|
6
|
+
raise ImportError(
|
7
|
+
"You need to install llama-index to use pocket llamaindex"
|
8
|
+
)
|
9
|
+
|
10
|
+
from hyperpocket import Pocket
|
11
|
+
from hyperpocket.tool import Tool
|
12
|
+
|
13
|
+
|
14
|
+
class PocketLlamaindex(Pocket):
|
15
|
+
def get_tools(self) -> List[BaseTool]:
|
16
|
+
tools = [self.get_tool(pk) for pk in self.tools.values()]
|
17
|
+
return tools
|
18
|
+
|
19
|
+
def get_tool(self, pocket_tool: Tool) -> BaseTool:
|
20
|
+
def _invoke(body: Any, thread_id: str = 'default', profile: str = 'default', **kwargs) -> str:
|
21
|
+
result, interrupted = self.invoke_with_state(pocket_tool.name, body=body, thread_id=thread_id,
|
22
|
+
profile=profile, **kwargs)
|
23
|
+
say = result
|
24
|
+
if interrupted:
|
25
|
+
say = f'{say}\n\nThe tool execution interrupted. Please talk to me to resume.'
|
26
|
+
return say
|
27
|
+
|
28
|
+
async def _ainvoke(body: Any, thread_id: str = 'default', profile: str = 'default', **kwargs) -> str:
|
29
|
+
result, interrupted = await self.ainvoke_with_state(pocket_tool.name, body=body,
|
30
|
+
thread_id=thread_id, profile=profile, **kwargs)
|
31
|
+
say = result
|
32
|
+
if interrupted:
|
33
|
+
say = f'{say}\n\nThe tool execution interrupted. Please talk to me to resume.'
|
34
|
+
return say
|
35
|
+
|
36
|
+
return FunctionTool.from_defaults(
|
37
|
+
fn=_invoke,
|
38
|
+
async_fn=_ainvoke,
|
39
|
+
tool_metadata=ToolMetadata(
|
40
|
+
description=pocket_tool.description,
|
41
|
+
name=pocket_tool.name,
|
42
|
+
fn_schema=pocket_tool.schema_model(),
|
43
|
+
)
|
44
|
+
)
|
@@ -0,0 +1,59 @@
|
|
1
|
+
Metadata-Version: 2.1
|
2
|
+
Name: hyperpocket-llamaindex
|
3
|
+
Version: 0.0.1
|
4
|
+
Summary:
|
5
|
+
Author: moon
|
6
|
+
Author-email: moon@vessl.ai
|
7
|
+
Requires-Python: >=3.11,<4.0
|
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: hyperpocket (==0.0.3)
|
13
|
+
Requires-Dist: llama-index (>=0.12.5,<0.13.0)
|
14
|
+
Description-Content-Type: text/markdown
|
15
|
+
|
16
|
+
## Anthropic extensions
|
17
|
+
|
18
|
+
### Get Pocket Tools
|
19
|
+
|
20
|
+
```python
|
21
|
+
import hyperpocket as pk
|
22
|
+
from pocket_llamaindex import PocketLlamaindex
|
23
|
+
|
24
|
+
#
|
25
|
+
pocket = PocketLlamaindex(tools=[
|
26
|
+
*pk.curated_tools.SLACK, # SLACK = [slack_get_message, slack_post_message, ..]
|
27
|
+
*pk.curated_tools.LINEAR,
|
28
|
+
"https://github.com/my-org/some-awesome-tool"]
|
29
|
+
)
|
30
|
+
|
31
|
+
# get tools from pocket
|
32
|
+
tools = pocket.get_tools()
|
33
|
+
```
|
34
|
+
|
35
|
+
|
36
|
+
### Examples
|
37
|
+
|
38
|
+
```python
|
39
|
+
from llama_index.core.agent import FunctionCallingAgent
|
40
|
+
from llama_index.llms.openai import OpenAI
|
41
|
+
|
42
|
+
import hyperpocket as pk
|
43
|
+
from pocket_llamaindex import PocketLlamaindex
|
44
|
+
|
45
|
+
pocket = PocketLlamaindex(tools=[
|
46
|
+
*pk.curated_tools.SLACK, # SLACK = [slack_get_message, slack_post_message, ..]
|
47
|
+
*pk.curated_tools.LINEAR,
|
48
|
+
"https://github.com/my-org/some-awesome-tool"]
|
49
|
+
)
|
50
|
+
|
51
|
+
# get tools from pocket
|
52
|
+
tools = pocket.get_tools()
|
53
|
+
|
54
|
+
llm = OpenAI()
|
55
|
+
# pass tools get by pocket to an argument
|
56
|
+
agent = FunctionCallingAgent.from_tools(
|
57
|
+
tools=tools, llm=llm, verbose=True
|
58
|
+
)
|
59
|
+
```
|
@@ -0,0 +1,5 @@
|
|
1
|
+
hyperpocket_llamaindex/__init__.py,sha256=tZQ6ZnSlrc6zkUafpiYTbknXy7cac1fRLGJ6lBsGtvw,102
|
2
|
+
hyperpocket_llamaindex/pocket_llamaindex.py,sha256=AGKrJ8lO1wZPig0gEriQiBqlZ-Gk-r0N_cqZBDaWw1g,1774
|
3
|
+
hyperpocket_llamaindex-0.0.1.dist-info/METADATA,sha256=ClC4ekflbRsMAk7OGulxqL-7r3tst0sjPxhuK7k_jk0,1457
|
4
|
+
hyperpocket_llamaindex-0.0.1.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
5
|
+
hyperpocket_llamaindex-0.0.1.dist-info/RECORD,,
|