pycoze 0.1.300__py3-none-any.whl → 0.1.302__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/bot/agent_chat.py +8 -8
- 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.302.dist-info}/METADATA +1 -1
- {pycoze-0.1.300.dist-info → pycoze-0.1.302.dist-info}/RECORD +10 -10
- {pycoze-0.1.300.dist-info → pycoze-0.1.302.dist-info}/LICENSE +0 -0
- {pycoze-0.1.300.dist-info → pycoze-0.1.302.dist-info}/WHEEL +0 -0
- {pycoze-0.1.300.dist-info → pycoze-0.1.302.dist-info}/top_level.txt +0 -0
pycoze/bot/agent_chat.py
CHANGED
@@ -11,23 +11,23 @@ import os
|
|
11
11
|
|
12
12
|
cfg = utils.read_json_file("llm.json")
|
13
13
|
|
14
|
-
def
|
14
|
+
def load_bot_setting(bot_setting_file: str):
|
15
15
|
with open(bot_setting_file, "r", encoding="utf-8") as f:
|
16
16
|
return json.load(f)
|
17
17
|
|
18
18
|
|
19
19
|
def load_abilities(bot_setting_file: str):
|
20
20
|
with open(bot_setting_file, "r", encoding="utf-8") as f:
|
21
|
-
|
21
|
+
bot_setting = json.load(f)
|
22
22
|
|
23
23
|
abilities = []
|
24
|
-
for bot_id in
|
24
|
+
for bot_id in bot_setting["bots"]:
|
25
25
|
bot = ref_bot(bot_id, as_agent_tool=True)
|
26
26
|
if bot:
|
27
27
|
abilities.append(bot)
|
28
|
-
for tool_id in
|
28
|
+
for tool_id in bot_setting["tools"]:
|
29
29
|
abilities.extend(ref_tools(tool_id, as_agent_tool=True))
|
30
|
-
for workflow_id in
|
30
|
+
for workflow_id in bot_setting["workflows"]:
|
31
31
|
workflow = ref_workflow(workflow_id, as_agent_tool=True)
|
32
32
|
if workflow:
|
33
33
|
abilities.append(workflow)
|
@@ -67,20 +67,20 @@ async def run_with_interrupt_check(agent, history, tool_compatibility_mode, inte
|
|
67
67
|
pass # 忽略取消错误
|
68
68
|
|
69
69
|
async def agent_chat(bot_setting_file, history):
|
70
|
-
|
70
|
+
bot_setting = load_bot_setting(bot_setting_file)
|
71
71
|
abilities = load_abilities(bot_setting_file)
|
72
72
|
|
73
73
|
chat = ChatOpenAI(
|
74
74
|
api_key=cfg["apiKey"],
|
75
75
|
base_url=cfg["baseURL"],
|
76
76
|
model=cfg["model"],
|
77
|
-
temperature=
|
77
|
+
temperature=bot_setting["temperature"],
|
78
78
|
stop_sequences=[
|
79
79
|
"tool▁calls▁end",
|
80
80
|
"tool▁call▁end",
|
81
81
|
], # 不然会虚构工具调用过程和结果
|
82
82
|
)
|
83
|
-
prompt =
|
83
|
+
prompt = bot_setting["prompt"]
|
84
84
|
if cfg["toolCompatibilityMode"] and len(abilities) > 0:
|
85
85
|
prompt += """
|
86
86
|
作为一个AI,你如果不确定结果,请务必使用工具查询。
|
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__.split("_") + "."
|
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__.split("_") + "."
|
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]
|
@@ -12,7 +12,7 @@ pycoze/api/lib/view.py,sha256=_PIpTfeuTPPlMDKshMGsqFQYMq7ZiO4Hg5XwHwDoU60,7357
|
|
12
12
|
pycoze/api/lib/web.py,sha256=GWgtiTJOolKOX2drXcwuyqTcbo5FQVxa1NuBGcNyjyc,223
|
13
13
|
pycoze/api/lib/window.py,sha256=bTkQCzQZ7i3pYXB70bUSTBNJ9C4TW_X3yMae1VkquGk,1944
|
14
14
|
pycoze/bot/__init__.py,sha256=JxnRoCCqx_LFyVb3pLu0qYCsH8ZLuAaMXAtvVUuCHuE,78
|
15
|
-
pycoze/bot/agent_chat.py,sha256=
|
15
|
+
pycoze/bot/agent_chat.py,sha256=Wqv0xMb9SFqf-G0__uXyFz6579u_QUe0EqbhP9IS3yc,4160
|
16
16
|
pycoze/bot/bot.py,sha256=_qmUTZ09FmRLifHrW5stDZWGVK6yuMEMBC3fmeYJnqk,844
|
17
17
|
pycoze/bot/agent/__init__.py,sha256=3wE8_FFQS8j2BY-g9Cr-onV0POEvDRZaw_NCzpqrNus,265
|
18
18
|
pycoze/bot/agent/agent.py,sha256=qkLIRgSMNT1VD_UD0e6kYUuOTOqylQiYSCay6HZ12LA,3653
|
@@ -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=HDXZ1q8Bha9uX6TiZJlcKOM9LP2L9zuW5K16DBLrzQ4,1056
|
28
|
+
pycoze/reference/workflow.py,sha256=QQcJg-yYm-dpPkaR-gHm6NYY2dzXvLHaPWXlu8-HCRs,1305
|
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.302.dist-info/LICENSE,sha256=QStd_Qsd0-kAam_-sOesCIp_uKrGWeoKwt9M49NVkNU,1090
|
40
|
+
pycoze-0.1.302.dist-info/METADATA,sha256=8T5wWUH_McOeJREatzZjSh10q43-GUn-BLiYW3pbaFE,854
|
41
|
+
pycoze-0.1.302.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
42
|
+
pycoze-0.1.302.dist-info/top_level.txt,sha256=76dPeDhKvOCleL3ZC5gl1-y4vdS1tT_U1hxWVAn7sFo,7
|
43
|
+
pycoze-0.1.302.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|