pycoze 0.1.300__py3-none-any.whl → 0.1.301__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.
- pycoze/reference/bot.py +5 -7
- pycoze/reference/lib.py +4 -5
- pycoze/reference/tool.py +5 -19
- pycoze/reference/workflow.py +7 -21
- {pycoze-0.1.300.dist-info → pycoze-0.1.301.dist-info}/METADATA +1 -1
- {pycoze-0.1.300.dist-info → pycoze-0.1.301.dist-info}/RECORD +9 -9
- {pycoze-0.1.300.dist-info → pycoze-0.1.301.dist-info}/LICENSE +0 -0
- {pycoze-0.1.300.dist-info → pycoze-0.1.301.dist-info}/WHEEL +0 -0
- {pycoze-0.1.300.dist-info → pycoze-0.1.301.dist-info}/top_level.txt +0 -0
pycoze/reference/bot.py
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
import os
|
2
|
-
from langchain.agents import tool as to_agent_tool
|
3
2
|
from .lib import ModuleManager, wrapped_func
|
4
3
|
import json
|
5
4
|
from pycoze import utils
|
@@ -9,7 +8,7 @@ bot_index = 0
|
|
9
8
|
params = utils.params
|
10
9
|
|
11
10
|
|
12
|
-
def ref_bot(bot_id,
|
11
|
+
def ref_bot(bot_id, workspace_path=None):
|
13
12
|
global bot_index
|
14
13
|
if workspace_path is None:
|
15
14
|
workspace_path = params["workspacePath"]
|
@@ -51,11 +50,10 @@ def {random_name}(command:str) -> str:
|
|
51
50
|
return result
|
52
51
|
"""
|
53
52
|
exec(function_code)
|
54
|
-
tool =
|
55
|
-
tool
|
56
|
-
|
57
|
-
|
58
|
-
return tool if as_agent_tool else tool.func
|
53
|
+
tool = eval(random_name)
|
54
|
+
tool = wrapped_func(tool, module_path)
|
55
|
+
|
56
|
+
return tool
|
59
57
|
except Exception as e:
|
60
58
|
print(f"Error loading bot {bot_id}: {e}")
|
61
59
|
return None
|
pycoze/reference/lib.py
CHANGED
@@ -48,20 +48,19 @@ class ModuleManager:
|
|
48
48
|
del sys.modules[key]
|
49
49
|
|
50
50
|
|
51
|
-
def wrapped_func(
|
52
|
-
original_tool_function = item.func
|
51
|
+
def wrapped_func(func, module_path):
|
53
52
|
|
54
53
|
def _wrapped(*args, **kwargs):
|
55
54
|
try:
|
56
|
-
print(f"调用了 {
|
55
|
+
print(f"调用了 {func.__name__}")
|
57
56
|
except:
|
58
57
|
print(f"called unknown")
|
59
58
|
with ChangeDirectoryAndPath(module_path):
|
60
|
-
result =
|
59
|
+
result = func(*args, **kwargs)
|
61
60
|
try:
|
62
61
|
if isinstance(result, types.GeneratorType):
|
63
62
|
result = list(result)
|
64
|
-
print(f"{
|
63
|
+
print(f"{func.__name__} 调用完毕,结果为:", result)
|
65
64
|
except:
|
66
65
|
pass
|
67
66
|
return result
|
pycoze/reference/tool.py
CHANGED
@@ -1,8 +1,5 @@
|
|
1
1
|
import os
|
2
2
|
import importlib
|
3
|
-
from langchain.agents import tool as to_agent_tool
|
4
|
-
import types
|
5
|
-
import langchain_core
|
6
3
|
from .lib import ModuleManager, wrapped_func
|
7
4
|
from pycoze import utils
|
8
5
|
|
@@ -10,7 +7,7 @@ from pycoze import utils
|
|
10
7
|
params = utils.params
|
11
8
|
|
12
9
|
|
13
|
-
def ref_tools(tool_id,
|
10
|
+
def ref_tools(tool_id, workspace_path=None):
|
14
11
|
if workspace_path is None:
|
15
12
|
workspace_path = params["workspacePath"]
|
16
13
|
tool_base_path = os.path.join(workspace_path, "User/Local/tool")
|
@@ -25,25 +22,14 @@ def ref_tools(tool_id, as_agent_tool=False, workspace_path=None):
|
|
25
22
|
with ModuleManager(module_path) as manager:
|
26
23
|
module = importlib.import_module("tool")
|
27
24
|
export_tools = getattr(module, "export_tools")
|
28
|
-
valid_tools = []
|
29
|
-
for tool in export_tools:
|
30
|
-
assert isinstance(
|
31
|
-
tool, langchain_core.tools.StructuredTool
|
32
|
-
) or isinstance(
|
33
|
-
tool, types.FunctionType
|
34
|
-
), f"Tool is not a StructuredTool or function: {tool}"
|
35
|
-
if not isinstance(tool, langchain_core.tools.StructuredTool):
|
36
|
-
tool = to_agent_tool(tool)
|
37
|
-
valid_tools.append(tool)
|
38
|
-
export_tools = valid_tools
|
39
25
|
|
40
26
|
except Exception as e:
|
41
27
|
print(f"Error loading tool {tool_id}: {e}")
|
42
28
|
return []
|
43
29
|
|
44
30
|
for tool in export_tools:
|
45
|
-
tool
|
46
|
-
if tool.
|
47
|
-
tool.
|
31
|
+
tool = wrapped_func(tool, module_path)
|
32
|
+
if tool.__doc__ is None:
|
33
|
+
tool.__doc__ = "This tool is used to " + tool.name + "."
|
48
34
|
|
49
|
-
return
|
35
|
+
return [tool.func for tool in export_tools]
|
pycoze/reference/workflow.py
CHANGED
@@ -1,8 +1,5 @@
|
|
1
1
|
import os
|
2
2
|
import importlib
|
3
|
-
from langchain.agents import tool as to_agent_tool
|
4
|
-
import types
|
5
|
-
import langchain_core
|
6
3
|
from .lib import ModuleManager, wrapped_func
|
7
4
|
from pycoze import utils
|
8
5
|
|
@@ -10,7 +7,7 @@ from pycoze import utils
|
|
10
7
|
params = utils.params
|
11
8
|
|
12
9
|
|
13
|
-
def _ref_workflows(workflow_id,
|
10
|
+
def _ref_workflows(workflow_id, workspace_path=None):
|
14
11
|
if workspace_path is None:
|
15
12
|
workspace_path = params["workspacePath"]
|
16
13
|
tool_base_path = os.path.join(workspace_path, "User/Local/workflow")
|
@@ -25,33 +22,22 @@ def _ref_workflows(workflow_id, as_agent_tool=False, workspace_path=None):
|
|
25
22
|
with ModuleManager(module_path) as manager:
|
26
23
|
module = importlib.import_module("tool")
|
27
24
|
export_tools = getattr(module, "export_tools")
|
28
|
-
valid_tools = []
|
29
|
-
for tool in export_tools:
|
30
|
-
assert isinstance(
|
31
|
-
tool, langchain_core.tools.StructuredTool
|
32
|
-
) or isinstance(
|
33
|
-
tool, types.FunctionType
|
34
|
-
), f"Tool is not a StructuredTool or function: {tool}"
|
35
|
-
if not isinstance(tool, langchain_core.tools.StructuredTool):
|
36
|
-
tool = to_agent_tool(tool)
|
37
|
-
valid_tools.append(tool)
|
38
|
-
export_tools = valid_tools
|
39
25
|
|
40
26
|
except Exception as e:
|
41
27
|
print(f"Error loading workflow {workflow_id}: {e}")
|
42
28
|
return []
|
43
29
|
|
44
30
|
for tool in export_tools:
|
45
|
-
tool
|
46
|
-
if tool.
|
47
|
-
tool.
|
31
|
+
tool = wrapped_func(tool, module_path)
|
32
|
+
if tool.__doc__ is None:
|
33
|
+
tool.__doc__ = "This tool is used to " + tool.name + "."
|
48
34
|
|
49
|
-
return
|
35
|
+
return [tool.func for tool in export_tools]
|
50
36
|
|
51
37
|
|
52
|
-
def ref_workflow(workflow_id,
|
38
|
+
def ref_workflow(workflow_id, workspace_path=None):
|
53
39
|
tools = _ref_workflows(
|
54
|
-
workflow_id,
|
40
|
+
workflow_id, workspace_path=workspace_path
|
55
41
|
)
|
56
42
|
if len(tools) > 0:
|
57
43
|
return tools[0]
|
@@ -22,10 +22,10 @@ pycoze/bot/agent/agent_types/__init__.py,sha256=zmU2Kmrv5mCdfg-QlPn2H6pWxbGeq8s7
|
|
22
22
|
pycoze/bot/agent/agent_types/const.py,sha256=BfUKPrhAHREoMLHuFNG2bCIEkC1-f7K0LEqNg4RwiRE,70
|
23
23
|
pycoze/bot/agent/agent_types/openai_func_call_agent.py,sha256=3qOyrddujtJ50W9SbH5bapbVTwjgE_LC2TnYJWUH9yc,6649
|
24
24
|
pycoze/reference/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
25
|
-
pycoze/reference/bot.py,sha256=
|
26
|
-
pycoze/reference/lib.py,sha256=
|
27
|
-
pycoze/reference/tool.py,sha256=
|
28
|
-
pycoze/reference/workflow.py,sha256=
|
25
|
+
pycoze/reference/bot.py,sha256=pxHVYo0G3P3YZ--vBYbMEiEyBoxxPwaO5dMTf9WFMSc,2014
|
26
|
+
pycoze/reference/lib.py,sha256=CCqJFUXy0v9x8A54uDERmKjJQcteWBEGev6sTQQjH-I,2105
|
27
|
+
pycoze/reference/tool.py,sha256=wZCP3Ieko0nzWyx_aG-Cqsv9wTedH1WsIpFvP2im7YM,1041
|
28
|
+
pycoze/reference/workflow.py,sha256=dgZFVEiTv-YoGp7oljHRDbsfQP1fANgdm34tABOgbOs,1290
|
29
29
|
pycoze/ui/__init__.py,sha256=uaXet23wUk64TcZjpBX8qOx4aUhwA_ucrmcxy7Q4Qr4,929
|
30
30
|
pycoze/ui/base.py,sha256=bz9mHZwIXA8LErEHTIonH347u6LP7rxV2EADMMjNZos,1081
|
31
31
|
pycoze/ui/color.py,sha256=cT9Ib8uNzkOKxyW0IwVj46o4LwdB1xgNCj1_Rou9d_4,854
|
@@ -36,8 +36,8 @@ pycoze/utils/arg.py,sha256=jop1tBfe5hYkHW1NSpCeaZBEznkgguBscj_7M2dWfrs,503
|
|
36
36
|
pycoze/utils/env.py,sha256=5pWlXfM1F5ZU9hhv1rHlDEanjEW5wf0nbyez9bNRqqA,559
|
37
37
|
pycoze/utils/socket.py,sha256=bZbFFRH4mfThzRqt55BAAGQ6eICx_ja4x8UGGrUdAm8,2428
|
38
38
|
pycoze/utils/text_or_file.py,sha256=gpxZVWt2DW6YiEg_MnMuwg36VNf3TX383QD_1oZNB0Y,551
|
39
|
-
pycoze-0.1.
|
40
|
-
pycoze-0.1.
|
41
|
-
pycoze-0.1.
|
42
|
-
pycoze-0.1.
|
43
|
-
pycoze-0.1.
|
39
|
+
pycoze-0.1.301.dist-info/LICENSE,sha256=QStd_Qsd0-kAam_-sOesCIp_uKrGWeoKwt9M49NVkNU,1090
|
40
|
+
pycoze-0.1.301.dist-info/METADATA,sha256=VkkIT7B6AU3gWBW5n-tlUJeXena8B3CCu-QIFQWGuRA,854
|
41
|
+
pycoze-0.1.301.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
42
|
+
pycoze-0.1.301.dist-info/top_level.txt,sha256=76dPeDhKvOCleL3ZC5gl1-y4vdS1tT_U1hxWVAn7sFo,7
|
43
|
+
pycoze-0.1.301.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|