hyperpocket-llamaindex 0.1.8__py3-none-any.whl → 0.1.10__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,6 @@
1
- from typing import List, Any
1
+ from typing import List, Optional
2
+
3
+ from pydantic import BaseModel
2
4
 
3
5
  try:
4
6
  from llama_index.core.tools import FunctionTool, BaseTool, ToolMetadata
@@ -12,12 +14,27 @@ from hyperpocket.tool import Tool
12
14
 
13
15
 
14
16
  class PocketLlamaindex(Pocket):
15
- def get_tools(self) -> List[BaseTool]:
17
+ def get_tools(self, use_profile: Optional[bool] = None) -> List[BaseTool]:
18
+ if use_profile is not None:
19
+ self.use_profile = use_profile
20
+
16
21
  tools = [self.get_tool(pk) for pk in self.core.tools.values()]
17
22
  return tools
18
23
 
19
24
  def get_tool(self, pocket_tool: Tool) -> BaseTool:
20
- def _invoke(body: Any, thread_id: str = 'default', profile: str = 'default', **kwargs) -> str:
25
+ def _invoke(**kwargs) -> str:
26
+ if self.use_profile:
27
+ body = kwargs["body"]
28
+ thread_id = kwargs.pop("thread_id", "default")
29
+ profile = kwargs.pop("profile", "default")
30
+ else:
31
+ body = kwargs
32
+ thread_id = "default"
33
+ profile = "default"
34
+
35
+ if isinstance(body, BaseModel):
36
+ body = body.model_dump()
37
+
21
38
  result, interrupted = self.invoke_with_state(pocket_tool.name, body=body, thread_id=thread_id,
22
39
  profile=profile, **kwargs)
23
40
  say = result
@@ -25,7 +42,19 @@ class PocketLlamaindex(Pocket):
25
42
  say = f'{say}\n\nThe tool execution interrupted. Please talk to me to resume.'
26
43
  return say
27
44
 
28
- async def _ainvoke(body: Any, thread_id: str = 'default', profile: str = 'default', **kwargs) -> str:
45
+ async def _ainvoke(**kwargs) -> str:
46
+ if self.use_profile:
47
+ body = kwargs["body"]
48
+ thread_id = kwargs.pop("thread_id", "default")
49
+ profile = kwargs.pop("profile", "default")
50
+ else:
51
+ body = kwargs
52
+ thread_id = "default"
53
+ profile = "default"
54
+
55
+ if isinstance(body, BaseModel):
56
+ body = body.model_dump()
57
+
29
58
  result, interrupted = await self.ainvoke_with_state(pocket_tool.name, body=body,
30
59
  thread_id=thread_id, profile=profile, **kwargs)
31
60
  say = result
@@ -37,8 +66,8 @@ class PocketLlamaindex(Pocket):
37
66
  fn=_invoke,
38
67
  async_fn=_ainvoke,
39
68
  tool_metadata=ToolMetadata(
40
- description=pocket_tool.description,
41
69
  name=pocket_tool.name,
42
- fn_schema=pocket_tool.schema_model(),
70
+ description=pocket_tool.get_description(use_profile=self.use_profile),
71
+ fn_schema=pocket_tool.schema_model(use_profile=self.use_profile),
43
72
  )
44
73
  )
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hyperpocket-llamaindex
3
- Version: 0.1.8
4
- Author-email: moon <moon@vessl.ai>
3
+ Version: 0.1.10
4
+ Author-email: Hyperpocket Team <hyperpocket@vessl.ai>
5
5
  Requires-Python: >=3.10
6
6
  Requires-Dist: hyperpocket>=0.0.3
7
7
  Requires-Dist: llama-index>=0.12.5
@@ -0,0 +1,5 @@
1
+ hyperpocket_llamaindex/__init__.py,sha256=tZQ6ZnSlrc6zkUafpiYTbknXy7cac1fRLGJ6lBsGtvw,102
2
+ hyperpocket_llamaindex/pocket_llamaindex.py,sha256=36O1S64e_4XgRb-WDx-lCTaaDqMvy4M_XCj4UdIUdtQ,2668
3
+ hyperpocket_llamaindex-0.1.10.dist-info/METADATA,sha256=nbT8oxhT1TYB57-J5hBKgTJhMNab04e3HD0Hxi3VN1k,1240
4
+ hyperpocket_llamaindex-0.1.10.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
5
+ hyperpocket_llamaindex-0.1.10.dist-info/RECORD,,
@@ -1,5 +0,0 @@
1
- hyperpocket_llamaindex/__init__.py,sha256=tZQ6ZnSlrc6zkUafpiYTbknXy7cac1fRLGJ6lBsGtvw,102
2
- hyperpocket_llamaindex/pocket_llamaindex.py,sha256=91l-gPUDQUV8MATXZekRor9PL4sSdamWuCQhT7SkXh4,1779
3
- hyperpocket_llamaindex-0.1.8.dist-info/METADATA,sha256=MT4LEDDolZ8jMtO3XJltEz_RlSiVfR-clC5yNzecuSc,1220
4
- hyperpocket_llamaindex-0.1.8.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
5
- hyperpocket_llamaindex-0.1.8.dist-info/RECORD,,