pycoze 0.1.44__tar.gz → 0.1.45__tar.gz

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.
Files changed (34) hide show
  1. {pycoze-0.1.44 → pycoze-0.1.45}/PKG-INFO +1 -1
  2. pycoze-0.1.45/pycoze/access/tool_for_bot.py +84 -0
  3. {pycoze-0.1.44 → pycoze-0.1.45}/pycoze/bot/bot.py +7 -7
  4. {pycoze-0.1.44 → pycoze-0.1.45}/pycoze.egg-info/PKG-INFO +1 -1
  5. {pycoze-0.1.44 → pycoze-0.1.45}/setup.py +1 -1
  6. pycoze-0.1.44/pycoze/access/tool_for_bot.py +0 -158
  7. {pycoze-0.1.44 → pycoze-0.1.45}/LICENSE +0 -0
  8. {pycoze-0.1.44 → pycoze-0.1.45}/README.md +0 -0
  9. {pycoze-0.1.44 → pycoze-0.1.45}/pycoze/__init__.py +0 -0
  10. {pycoze-0.1.44 → pycoze-0.1.45}/pycoze/access/__init__.py +0 -0
  11. {pycoze-0.1.44 → pycoze-0.1.45}/pycoze/bot/__init__.py +0 -0
  12. {pycoze-0.1.44 → pycoze-0.1.45}/pycoze/bot/agent/__init__.py +0 -0
  13. {pycoze-0.1.44 → pycoze-0.1.45}/pycoze/bot/agent/agent.py +0 -0
  14. {pycoze-0.1.44 → pycoze-0.1.45}/pycoze/bot/agent/agent_types/__init__.py +0 -0
  15. {pycoze-0.1.44 → pycoze-0.1.45}/pycoze/bot/agent/agent_types/openai_func_call_agent.py +0 -0
  16. {pycoze-0.1.44 → pycoze-0.1.45}/pycoze/bot/agent/agent_types/react_agent.py +0 -0
  17. {pycoze-0.1.44 → pycoze-0.1.45}/pycoze/bot/agent/agent_types/react_prompt.py +0 -0
  18. {pycoze-0.1.44 → pycoze-0.1.45}/pycoze/bot/agent/assistant.py +0 -0
  19. {pycoze-0.1.44 → pycoze-0.1.45}/pycoze/bot/agent/chat.py +0 -0
  20. {pycoze-0.1.44 → pycoze-0.1.45}/pycoze/gpu/__init__.py +0 -0
  21. {pycoze-0.1.44 → pycoze-0.1.45}/pycoze/gpu/gpu_reserve.py +0 -0
  22. {pycoze-0.1.44 → pycoze-0.1.45}/pycoze/module.py +0 -0
  23. {pycoze-0.1.44 → pycoze-0.1.45}/pycoze/ui/__init__.py +0 -0
  24. {pycoze-0.1.44 → pycoze-0.1.45}/pycoze/ui/base.py +0 -0
  25. {pycoze-0.1.44 → pycoze-0.1.45}/pycoze/ui/color.py +0 -0
  26. {pycoze-0.1.44 → pycoze-0.1.45}/pycoze/ui/typ.py +0 -0
  27. {pycoze-0.1.44 → pycoze-0.1.45}/pycoze/ui/ui_def.py +0 -0
  28. {pycoze-0.1.44 → pycoze-0.1.45}/pycoze/utils/__init__.py +0 -0
  29. {pycoze-0.1.44 → pycoze-0.1.45}/pycoze/utils/arg.py +0 -0
  30. {pycoze-0.1.44 → pycoze-0.1.45}/pycoze/utils/text_or_file.py +0 -0
  31. {pycoze-0.1.44 → pycoze-0.1.45}/pycoze.egg-info/SOURCES.txt +0 -0
  32. {pycoze-0.1.44 → pycoze-0.1.45}/pycoze.egg-info/dependency_links.txt +0 -0
  33. {pycoze-0.1.44 → pycoze-0.1.45}/pycoze.egg-info/top_level.txt +0 -0
  34. {pycoze-0.1.44 → pycoze-0.1.45}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pycoze
3
- Version: 0.1.44
3
+ Version: 0.1.45
4
4
  Summary: Package for pycoze only!
5
5
  Author: Yuan Jie Xiong
6
6
  Author-email: aiqqqqqqq@qq.com
@@ -0,0 +1,84 @@
1
+ import sys
2
+ import os
3
+ import importlib
4
+ from langchain.agents import tool as _tool
5
+ import types
6
+ import langchain_core
7
+
8
+
9
+ def change_directory_and_path(module_path):
10
+ """Change the current working directory and sys.path."""
11
+ sys.path.insert(0, module_path)
12
+ os.chdir(module_path)
13
+
14
+
15
+ def restore_directory_and_path(module_path, old_path):
16
+ """Restore the original working directory and sys.path."""
17
+ sys.path.remove(module_path)
18
+ os.chdir(old_path)
19
+
20
+
21
+ def wrapped_tool(tool, module_path):
22
+ """Wrap the tool function to include additional logging and path management."""
23
+ original_tool_function = tool.func
24
+
25
+ def _wrapped_tool(*args, **kwargs):
26
+ print(f"调用了{tool.name}")
27
+ old_path = os.getcwd()
28
+ try:
29
+ change_directory_and_path(module_path)
30
+ result = original_tool_function(*args, **kwargs)
31
+ finally:
32
+ restore_directory_and_path(module_path, old_path)
33
+ print(f"{tool.name}调用完毕,结果为:", result)
34
+ return result
35
+
36
+ return _wrapped_tool
37
+
38
+
39
+ def import_tools(tool_id):
40
+ """Import tools from a specified tool_id."""
41
+ tool_base_path = "../../tool"
42
+ old_path = os.getcwd()
43
+ module_path = os.path.join(tool_base_path, tool_id)
44
+ module_path = os.path.normpath(os.path.abspath(module_path))
45
+
46
+ if not os.path.exists(module_path):
47
+ print(f"Tool {tool_id} not found")
48
+ return []
49
+
50
+ # Save the current sys.modules state
51
+ original_modules = sys.modules.copy()
52
+
53
+ try:
54
+ change_directory_and_path(module_path)
55
+ module = importlib.import_module("tool")
56
+ export_tools = getattr(module, "export_tools")
57
+ valid_tools = []
58
+ for tool in export_tools:
59
+ assert isinstance(tool, langchain_core.tools.StructuredTool) or isinstance(
60
+ tool, types.FunctionType
61
+ ), f"Tool is not a StructuredTool or function: {tool}"
62
+ if isinstance(tool, types.FunctionType) and not isinstance(
63
+ tool, langchain_core.tools.StructuredTool
64
+ ):
65
+ valid_tools.append(_tool(tool))
66
+ export_tools = valid_tools
67
+
68
+ except Exception as e:
69
+ print(f"Error loading tool {tool_id}: {e}")
70
+ restore_directory_and_path(module_path, old_path)
71
+ return []
72
+
73
+ # Unload modules and restore sys.modules state
74
+ importlib.invalidate_caches()
75
+ for key in list(sys.modules.keys()):
76
+ if key not in original_modules:
77
+ del sys.modules[key]
78
+
79
+ restore_directory_and_path(module_path, old_path)
80
+
81
+ for tool in export_tools:
82
+ tool.func = wrapped_tool(tool, module_path)
83
+
84
+ return export_tools
@@ -45,13 +45,13 @@ def agent_chat(bot_setting_file, history):
45
45
  ], # 停用deepseek的工具调用标记,不然会虚构工具调用过程和结果
46
46
  )
47
47
  prompt = role_setting["prompt"]
48
- if cfg["model"].startswith("deepseek") and len(tools) > 0:
49
- prompt += """
50
- 如果需要调用工具,请使用以下面json格式进行结尾:
51
- ```json
52
- {"name": 函数名, "parameters": 参数词典}
53
- ```
54
- """
48
+ # if cfg["model"].startswith("deepseek") and len(tools) > 0:
49
+ # prompt += """
50
+ # 如果需要调用工具,请使用以下面json格式进行结尾:
51
+ # ```json
52
+ # {"name": 函数名, "parameters": 参数词典}
53
+ # ```
54
+ # """
55
55
  agent = Runnable(
56
56
  agent_execution_mode=(
57
57
  "ReAct" if cfg["model"] in ["command-r"] else "FuncCall"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pycoze
3
- Version: 0.1.44
3
+ Version: 0.1.45
4
4
  Summary: Package for pycoze only!
5
5
  Author: Yuan Jie Xiong
6
6
  Author-email: aiqqqqqqq@qq.com
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name="pycoze",
5
- version="0.1.44",
5
+ version="0.1.45",
6
6
  packages=find_packages(),
7
7
  install_requires=[],
8
8
  author="Yuan Jie Xiong",
@@ -1,158 +0,0 @@
1
- # import sys
2
- # import os
3
- # import importlib
4
- # from langchain.agents import tool as _tool
5
- # import types
6
- # import langchain_core
7
-
8
- # def change_directory_and_path(module_path):
9
- # """Change the current working directory and sys.path."""
10
- # sys.path.insert(0, module_path)
11
- # os.chdir(module_path)
12
-
13
- # def restore_directory_and_path(module_path, old_path):
14
- # """Restore the original working directory and sys.path."""
15
- # sys.path.remove(module_path)
16
- # os.chdir(old_path)
17
-
18
- # def wrapped_tool(tool, module_path):
19
- # """Wrap the tool function to include additional logging and path management."""
20
- # original_tool_function = tool.func
21
-
22
- # def _wrapped_tool(*args, **kwargs):
23
- # print(f"调用了{tool.name}")
24
- # old_path = os.getcwd()
25
- # try:
26
- # change_directory_and_path(module_path)
27
- # result = original_tool_function(*args, **kwargs)
28
- # finally:
29
- # restore_directory_and_path(module_path, old_path)
30
- # print(f"{tool.name}调用完毕,结果为:", result)
31
- # return result
32
-
33
- # return _wrapped_tool
34
-
35
- # def import_tools(tool_id):
36
- # """Import tools from a specified tool_id."""
37
- # tool_base_path = "../../tool"
38
- # old_path = os.getcwd()
39
- # module_path = os.path.join(tool_base_path, tool_id)
40
- # module_path = os.path.normpath(os.path.abspath(module_path))
41
-
42
- # if not os.path.exists(module_path):
43
- # print(f"Tool {tool_id} not found")
44
- # return []
45
-
46
- # # Save the current sys.modules state
47
- # original_modules = sys.modules.copy()
48
-
49
- # try:
50
- # change_directory_and_path(module_path)
51
- # module = importlib.import_module("tool")
52
- # export_tools = getattr(module, "export_tools")
53
- # valid_tools = []
54
- # for tool in export_tools:
55
- # assert isinstance(tool, langchain_core.tools.StructuredTool) or isinstance(
56
- # tool, types.FunctionType
57
- # ), f"Tool is not a StructuredTool or function: {tool}"
58
- # if isinstance(tool, types.FunctionType) and not isinstance(
59
- # tool, langchain_core.tools.StructuredTool
60
- # ):
61
- # valid_tools.append(_tool(tool))
62
- # export_tools = valid_tools
63
-
64
- # except Exception as e:
65
- # print(f"Error loading tool {tool_id}: {e}")
66
- # restore_directory_and_path(module_path, old_path)
67
- # return []
68
-
69
- # # Unload modules and restore sys.modules state
70
- # importlib.invalidate_caches()
71
- # for key in list(sys.modules.keys()):
72
- # if key not in original_modules:
73
- # del sys.modules[key]
74
-
75
- # restore_directory_and_path(module_path, old_path)
76
-
77
- # for tool in export_tools:
78
- # tool.func = wrapped_tool(tool, module_path)
79
-
80
- # return export_tools
81
-
82
- import sys
83
- import os
84
- import argparse
85
- import importlib
86
- from langchain.agents import tool as _tool
87
- import types
88
- import langchain_core
89
-
90
-
91
- def wrapped_tool(tool, module_path):
92
- old_tool_fun = tool.func
93
-
94
- def _wrapped_tool(*args, **kwargs):
95
- print(f"调用了{tool.name}")
96
- old_path = os.getcwd()
97
- try:
98
- sys.path.insert(0, module_path) # 插入到第一个位置
99
- os.chdir(module_path)
100
- result = old_tool_fun(*args, **kwargs)
101
- finally:
102
- sys.path.remove(module_path)
103
- os.chdir(old_path)
104
- print(f"{tool.name}调用完毕,结果为:", result)
105
- return result
106
-
107
- return _wrapped_tool
108
-
109
-
110
- def import_tools(tool_id):
111
- print("import_tools")
112
- tool_path = "../../tool"
113
- old_path = os.getcwd()
114
- module_path = os.path.join(tool_path, tool_id)
115
- module_path = os.path.normpath(os.path.abspath(module_path))
116
-
117
- if not os.path.exists(module_path):
118
- print(f"Tool {tool_id} not found")
119
- return []
120
-
121
- # 保存当前的 sys.modules 状态
122
- original_modules = sys.modules.copy()
123
-
124
- try:
125
- sys.path.insert(0, module_path) # 插入到第一个位置
126
- os.chdir(module_path)
127
- module = importlib.import_module("tool")
128
- export_tools = getattr(module, "export_tools")
129
- temp_list = []
130
- for tool in export_tools:
131
- assert isinstance(tool, langchain_core.tools.StructuredTool) or isinstance(
132
- tool, types.FunctionType
133
- ), f"Tool is not a StructuredTool or function: {tool}"
134
- if isinstance(tool, types.FunctionType) and not isinstance(
135
- tool, langchain_core.tools.StructuredTool
136
- ):
137
- temp_list.append(_tool(tool))
138
- export_tools = temp_list
139
-
140
- except Exception as e:
141
- print(f"Error loading tool {tool_id}: {e}")
142
- sys.path.remove(module_path)
143
- os.chdir(old_path)
144
- return []
145
-
146
- # 卸载模块并恢复 sys.modules 状态
147
- importlib.invalidate_caches()
148
- for key in list(sys.modules.keys()):
149
- if key not in original_modules:
150
- del sys.modules[key]
151
-
152
- sys.path.remove(module_path)
153
- os.chdir(old_path)
154
-
155
- for tool in export_tools:
156
- tool.func = wrapped_tool(tool, module_path)
157
-
158
- return export_tools
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes