pycoze 0.1.41__tar.gz → 0.1.43__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.41 → pycoze-0.1.43}/PKG-INFO +1 -1
  2. pycoze-0.1.43/pycoze/access/tool_for_bot.py +157 -0
  3. {pycoze-0.1.41 → pycoze-0.1.43}/pycoze.egg-info/PKG-INFO +1 -1
  4. {pycoze-0.1.41 → pycoze-0.1.43}/setup.py +1 -1
  5. pycoze-0.1.41/pycoze/access/tool_for_bot.py +0 -75
  6. {pycoze-0.1.41 → pycoze-0.1.43}/LICENSE +0 -0
  7. {pycoze-0.1.41 → pycoze-0.1.43}/README.md +0 -0
  8. {pycoze-0.1.41 → pycoze-0.1.43}/pycoze/__init__.py +0 -0
  9. {pycoze-0.1.41 → pycoze-0.1.43}/pycoze/access/__init__.py +0 -0
  10. {pycoze-0.1.41 → pycoze-0.1.43}/pycoze/bot/__init__.py +0 -0
  11. {pycoze-0.1.41 → pycoze-0.1.43}/pycoze/bot/agent/__init__.py +0 -0
  12. {pycoze-0.1.41 → pycoze-0.1.43}/pycoze/bot/agent/agent.py +0 -0
  13. {pycoze-0.1.41 → pycoze-0.1.43}/pycoze/bot/agent/agent_types/__init__.py +0 -0
  14. {pycoze-0.1.41 → pycoze-0.1.43}/pycoze/bot/agent/agent_types/openai_func_call_agent.py +0 -0
  15. {pycoze-0.1.41 → pycoze-0.1.43}/pycoze/bot/agent/agent_types/react_agent.py +0 -0
  16. {pycoze-0.1.41 → pycoze-0.1.43}/pycoze/bot/agent/agent_types/react_prompt.py +0 -0
  17. {pycoze-0.1.41 → pycoze-0.1.43}/pycoze/bot/agent/assistant.py +0 -0
  18. {pycoze-0.1.41 → pycoze-0.1.43}/pycoze/bot/agent/chat.py +0 -0
  19. {pycoze-0.1.41 → pycoze-0.1.43}/pycoze/bot/bot.py +0 -0
  20. {pycoze-0.1.41 → pycoze-0.1.43}/pycoze/gpu/__init__.py +0 -0
  21. {pycoze-0.1.41 → pycoze-0.1.43}/pycoze/gpu/gpu_reserve.py +0 -0
  22. {pycoze-0.1.41 → pycoze-0.1.43}/pycoze/module.py +0 -0
  23. {pycoze-0.1.41 → pycoze-0.1.43}/pycoze/ui/__init__.py +0 -0
  24. {pycoze-0.1.41 → pycoze-0.1.43}/pycoze/ui/base.py +0 -0
  25. {pycoze-0.1.41 → pycoze-0.1.43}/pycoze/ui/color.py +0 -0
  26. {pycoze-0.1.41 → pycoze-0.1.43}/pycoze/ui/typ.py +0 -0
  27. {pycoze-0.1.41 → pycoze-0.1.43}/pycoze/ui/ui_def.py +0 -0
  28. {pycoze-0.1.41 → pycoze-0.1.43}/pycoze/utils/__init__.py +0 -0
  29. {pycoze-0.1.41 → pycoze-0.1.43}/pycoze/utils/arg.py +0 -0
  30. {pycoze-0.1.41 → pycoze-0.1.43}/pycoze/utils/text_or_file.py +0 -0
  31. {pycoze-0.1.41 → pycoze-0.1.43}/pycoze.egg-info/SOURCES.txt +0 -0
  32. {pycoze-0.1.41 → pycoze-0.1.43}/pycoze.egg-info/dependency_links.txt +0 -0
  33. {pycoze-0.1.41 → pycoze-0.1.43}/pycoze.egg-info/top_level.txt +0 -0
  34. {pycoze-0.1.41 → pycoze-0.1.43}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pycoze
3
- Version: 0.1.41
3
+ Version: 0.1.43
4
4
  Summary: Package for pycoze only!
5
5
  Author: Yuan Jie Xiong
6
6
  Author-email: aiqqqqqqq@qq.com
@@ -0,0 +1,157 @@
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
+ tool_path = "../../tool"
112
+ old_path = os.getcwd()
113
+ module_path = os.path.join(tool_path, tool_id)
114
+ module_path = os.path.normpath(os.path.abspath(module_path))
115
+
116
+ if not os.path.exists(module_path):
117
+ print(f"Tool {tool_id} not found")
118
+ return []
119
+
120
+ # 保存当前的 sys.modules 状态
121
+ original_modules = sys.modules.copy()
122
+
123
+ try:
124
+ sys.path.insert(0, module_path) # 插入到第一个位置
125
+ os.chdir(module_path)
126
+ module = importlib.import_module("tool")
127
+ export_tools = getattr(module, "export_tools")
128
+ temp_list = []
129
+ for tool in export_tools:
130
+ assert isinstance(tool, langchain_core.tools.StructuredTool) or isinstance(
131
+ tool, types.FunctionType
132
+ ), f"Tool is not a StructuredTool or function: {tool}"
133
+ if isinstance(tool, types.FunctionType) and not isinstance(
134
+ tool, langchain_core.tools.StructuredTool
135
+ ):
136
+ temp_list.append(_tool(tool))
137
+ export_tools = temp_list
138
+
139
+ except Exception as e:
140
+ print(f"Error loading tool {tool_id}: {e}")
141
+ sys.path.remove(module_path)
142
+ os.chdir(old_path)
143
+ return []
144
+
145
+ # 卸载模块并恢复 sys.modules 状态
146
+ importlib.invalidate_caches()
147
+ for key in list(sys.modules.keys()):
148
+ if key not in original_modules:
149
+ del sys.modules[key]
150
+
151
+ sys.path.remove(module_path)
152
+ os.chdir(old_path)
153
+
154
+ for tool in export_tools:
155
+ tool.func = wrapped_tool(tool, module_path)
156
+
157
+ return export_tools
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pycoze
3
- Version: 0.1.41
3
+ Version: 0.1.43
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.41",
5
+ version="0.1.43",
6
6
  packages=find_packages(),
7
7
  install_requires=[],
8
8
  author="Yuan Jie Xiong",
@@ -1,75 +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
-
9
- def wrapped_tool(tool, module_path):
10
- old_tool_fun = tool.func
11
-
12
- def _wrapped_tool(*args, **kwargs):
13
- print(f"调用了{tool.name}")
14
- old_path = os.getcwd()
15
- try:
16
- sys.path.insert(0, module_path) # 插入到第一个位置
17
- os.chdir(module_path)
18
- result = old_tool_fun(*args, **kwargs)
19
- finally:
20
- sys.path.remove(module_path)
21
- os.chdir(old_path)
22
- print(f"{tool.name}调用完毕,结果为:", result)
23
- return result
24
-
25
- return _wrapped_tool
26
-
27
-
28
- def import_tools(tool_id):
29
- tool_path = "../../tool"
30
- old_path = os.getcwd()
31
- module_path = os.path.join(tool_path, tool_id)
32
- module_path = os.path.normpath(os.path.abspath(module_path))
33
-
34
- if not os.path.exists(module_path):
35
- print(f"Tool {tool_id} not found")
36
- return []
37
-
38
- # 保存当前的 sys.modules 状态
39
- original_modules = sys.modules.copy()
40
-
41
- try:
42
- sys.path.insert(0, module_path) # 插入到第一个位置
43
- os.chdir(module_path)
44
- module = importlib.import_module("tool")
45
- export_tools = getattr(module, "export_tools")
46
- temp_list = []
47
- for tool in export_tools:
48
- assert isinstance(tool, langchain_core.tools.StructuredTool) or isinstance(
49
- tool, types.FunctionType
50
- ), f"Tool is not a StructuredTool or function: {tool}"
51
- if isinstance(tool, types.FunctionType) and not isinstance(
52
- tool, langchain_core.tools.StructuredTool
53
- ):
54
- temp_list.append(_tool(tool))
55
- export_tools = temp_list
56
-
57
- except Exception as e:
58
- print(f"Error loading tool {tool_id}: {e}")
59
- sys.path.remove(module_path)
60
- os.chdir(old_path)
61
- return []
62
-
63
- # 卸载模块并恢复 sys.modules 状态
64
- importlib.invalidate_caches()
65
- for key in list(sys.modules.keys()):
66
- if key not in original_modules:
67
- del sys.modules[key]
68
-
69
- sys.path.remove(module_path)
70
- os.chdir(old_path)
71
-
72
- for tool in export_tools:
73
- tool.func = wrapped_tool(tool, module_path)
74
-
75
- 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
File without changes