hyperpocket 0.5.1__py3-none-any.whl → 0.5.2__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/pocket_main.py +58 -18
- {hyperpocket-0.5.1.dist-info → hyperpocket-0.5.2.dist-info}/METADATA +1 -1
- {hyperpocket-0.5.1.dist-info → hyperpocket-0.5.2.dist-info}/RECORD +5 -5
- {hyperpocket-0.5.1.dist-info → hyperpocket-0.5.2.dist-info}/WHEEL +0 -0
- {hyperpocket-0.5.1.dist-info → hyperpocket-0.5.2.dist-info}/entry_points.txt +0 -0
hyperpocket/pocket_main.py
CHANGED
@@ -32,18 +32,22 @@ class Pocket(object):
|
|
32
32
|
|
33
33
|
def __init__(
|
34
34
|
self,
|
35
|
-
tools: list[ToolLike],
|
35
|
+
tools: list[ToolLike] = None,
|
36
36
|
auth: PocketAuth = None,
|
37
37
|
use_profile: bool = False,
|
38
38
|
):
|
39
39
|
try:
|
40
40
|
if auth is None:
|
41
41
|
auth = PocketAuth()
|
42
|
+
if tools is None:
|
43
|
+
tools = []
|
44
|
+
|
42
45
|
self.auth = auth
|
43
46
|
self.use_profile = use_profile
|
44
47
|
self.server = PocketServer.get_instance()
|
48
|
+
self.tools = {}
|
45
49
|
|
46
|
-
self.
|
50
|
+
self.load_tools(tools)
|
47
51
|
pocket_logger.info(
|
48
52
|
f"All Registered Tools Loaded successfully. total registered tools : {len(self.tools)}"
|
49
53
|
)
|
@@ -468,25 +472,61 @@ class Pocket(object):
|
|
468
472
|
tool_by_provider[auth_provider_name] = [tool]
|
469
473
|
return tool_by_provider
|
470
474
|
|
471
|
-
def
|
472
|
-
|
473
|
-
|
475
|
+
def load_tools(self, tools: Union[List[ToolLike], ToolLike]) -> List[Tool]:
|
476
|
+
"""
|
477
|
+
Load a list of tools into the pocket.
|
474
478
|
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
479
|
+
This method takes a list of tool identifiers(tool like) and loads them into the
|
480
|
+
pocket for use.
|
481
|
+
|
482
|
+
Args:
|
483
|
+
tools (Union[List[ToolLike], ToolLike]): A list of tool identifiers to be loaded.
|
484
|
+
"""
|
485
|
+
dock = self._default_dock()
|
486
|
+
if not isinstance(tools, list):
|
487
|
+
tools = [tools]
|
484
488
|
|
489
|
+
loaded_tools = []
|
485
490
|
with concurrent.futures.ThreadPoolExecutor(max_workers=10, thread_name_prefix="tool-loader") as executor:
|
486
|
-
futures = [executor.submit(
|
487
|
-
for future in concurrent.futures.as_completed(futures)
|
488
|
-
|
489
|
-
|
491
|
+
futures = [executor.submit(self._load_tool, tool_like, dock) for tool_like in tools]
|
492
|
+
loaded_tools = [future.result() for future in concurrent.futures.as_completed(futures)]
|
493
|
+
|
494
|
+
for tool in loaded_tools:
|
495
|
+
if tool.name in self.tools:
|
496
|
+
raise RuntimeError(f"{tool.name} already exists. duplicated tool name.")
|
497
|
+
self.tools[tool.name] = tool
|
498
|
+
|
499
|
+
return loaded_tools
|
500
|
+
|
501
|
+
def _load_tool(self, tool_like, dock: Dock = None) -> Tool:
|
502
|
+
if dock is None:
|
503
|
+
dock = self._default_dock()
|
504
|
+
|
505
|
+
if isinstance(tool_like, str) or isinstance(tool_like, tuple):
|
506
|
+
return dock(tool_like)
|
507
|
+
elif isinstance(tool_like, Tool):
|
508
|
+
return tool_like
|
509
|
+
elif isinstance(tool_like, Callable):
|
510
|
+
return from_func(tool_like)
|
511
|
+
else:
|
512
|
+
raise ValueError(f"Invalid tool type: {type(tool_like)}")
|
513
|
+
|
514
|
+
def remove_tool(self, tool_name: str) -> bool:
|
515
|
+
"""
|
516
|
+
Remove a tool from the pocket.
|
517
|
+
|
518
|
+
This method removes a tool identified by the given tool_name.
|
519
|
+
|
520
|
+
Args:
|
521
|
+
tool_name (str): The tool name to be removed.
|
522
|
+
|
523
|
+
Returns:
|
524
|
+
bool: True if the tool is removed successfully, False otherwise.
|
525
|
+
"""
|
526
|
+
if not tool_name in self.tools:
|
527
|
+
return False
|
528
|
+
del self.tools[tool_name]
|
529
|
+
return True
|
490
530
|
|
491
531
|
def _tool_instance(self, tool_name: str) -> Tool:
|
492
532
|
return self.tools[tool_name]
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: hyperpocket
|
3
|
-
Version: 0.5.
|
3
|
+
Version: 0.5.2
|
4
4
|
Summary: Building AI agent with hyperpocket tool in a flash
|
5
5
|
Project-URL: Homepage, https://vessl-ai.github.io/hyperpocket
|
6
6
|
Project-URL: Repository, https://github.com/vessl-ai/hyperpocket
|
@@ -2,7 +2,7 @@ hyperpocket/__init__.py,sha256=VVLbApRTiULqEVQp6lCNOcuXKx9V62O_7C9VNKBQ0G0,137
|
|
2
2
|
hyperpocket/builtin.py,sha256=w7OLxf5RCKVpLma9HieSdw6Uky5701ae6g31VPvFoZk,2439
|
3
3
|
hyperpocket/constants.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
4
4
|
hyperpocket/pocket_auth.py,sha256=eRRTzJh3et65EDJnQHB_Kpmco4dgCR2KL8f-FnbuGX0,17819
|
5
|
-
hyperpocket/pocket_main.py,sha256=
|
5
|
+
hyperpocket/pocket_main.py,sha256=1kNesVy5Z-WRET6-GfnRFpPtUdyxQaPBsjhXRflzh18,17702
|
6
6
|
hyperpocket/prompts.py,sha256=N1bCzCLZvGUVhH1Vn_cgeBPsdY3MdIU7ZGqVgexoj5E,472
|
7
7
|
hyperpocket/tool_like.py,sha256=Foa-iWTnVb54JEq20Becadbz-TSbYkZk6TxexSzaaRM,116
|
8
8
|
hyperpocket/auth/README.md,sha256=zn4QqnFZCA_4X3x8Wb6lE3OP5otYxpByZaCiUkBvaNs,11562
|
@@ -597,7 +597,7 @@ hyperpocket/util/get_objects_from_subpackage.py,sha256=4mR_S8eaJSdU68YfCkiXeIcXx
|
|
597
597
|
hyperpocket/util/git_parser.py,sha256=y96nhgZXtRgA_u_0GTPo95PGkpG-n_oMIrkbckdxiR8,2496
|
598
598
|
hyperpocket/util/json_schema_to_model.py,sha256=nc5AmnqkrdeFLELu-7_O9sEAaUaD8_KGlvIMDRobt-4,3751
|
599
599
|
hyperpocket/util/short_hashing_str.py,sha256=ahLUT8iQr-MJVbDJXrSt0cXnnSEeJ8EU3A0PDn6e0gs,119
|
600
|
-
hyperpocket-0.5.
|
601
|
-
hyperpocket-0.5.
|
602
|
-
hyperpocket-0.5.
|
603
|
-
hyperpocket-0.5.
|
600
|
+
hyperpocket-0.5.2.dist-info/METADATA,sha256=OBQOkr9W9KmvlePHr68rsnhFkf_OV_BxiV12-H3LQbM,13078
|
601
|
+
hyperpocket-0.5.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
602
|
+
hyperpocket-0.5.2.dist-info/entry_points.txt,sha256=KpBleaYr0SaENXOa-dFvJ_cvFCHYFEQ4LMl11ShAcBI,61
|
603
|
+
hyperpocket-0.5.2.dist-info/RECORD,,
|
File without changes
|
File without changes
|