pycoze 0.1.93__tar.gz → 0.1.94__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {pycoze-0.1.93 → pycoze-0.1.94}/PKG-INFO +1 -1
- {pycoze-0.1.93 → pycoze-0.1.94}/pycoze/access/tool_for_bot.py +29 -31
- {pycoze-0.1.93 → pycoze-0.1.94}/pycoze.egg-info/PKG-INFO +1 -1
- {pycoze-0.1.93 → pycoze-0.1.94}/setup.py +1 -1
- {pycoze-0.1.93 → pycoze-0.1.94}/LICENSE +0 -0
- {pycoze-0.1.93 → pycoze-0.1.94}/README.md +0 -0
- {pycoze-0.1.93 → pycoze-0.1.94}/pycoze/__init__.py +0 -0
- {pycoze-0.1.93 → pycoze-0.1.94}/pycoze/access/__init__.py +0 -0
- {pycoze-0.1.93 → pycoze-0.1.94}/pycoze/ai/__init__.py +0 -0
- {pycoze-0.1.93 → pycoze-0.1.94}/pycoze/ai/vram_reserve.py +0 -0
- {pycoze-0.1.93 → pycoze-0.1.94}/pycoze/bot/__init__.py +0 -0
- {pycoze-0.1.93 → pycoze-0.1.94}/pycoze/bot/agent/__init__.py +0 -0
- {pycoze-0.1.93 → pycoze-0.1.94}/pycoze/bot/agent/agent.py +0 -0
- {pycoze-0.1.93 → pycoze-0.1.94}/pycoze/bot/agent/agent_types/__init__.py +0 -0
- {pycoze-0.1.93 → pycoze-0.1.94}/pycoze/bot/agent/agent_types/openai_func_call_agent.py +0 -0
- {pycoze-0.1.93 → pycoze-0.1.94}/pycoze/bot/agent/assistant.py +0 -0
- {pycoze-0.1.93 → pycoze-0.1.94}/pycoze/bot/agent/chat.py +0 -0
- {pycoze-0.1.93 → pycoze-0.1.94}/pycoze/bot/bot.py +0 -0
- {pycoze-0.1.93 → pycoze-0.1.94}/pycoze/module.py +0 -0
- {pycoze-0.1.93 → pycoze-0.1.94}/pycoze/ui/__init__.py +0 -0
- {pycoze-0.1.93 → pycoze-0.1.94}/pycoze/ui/base.py +0 -0
- {pycoze-0.1.93 → pycoze-0.1.94}/pycoze/ui/color.py +0 -0
- {pycoze-0.1.93 → pycoze-0.1.94}/pycoze/ui/typ.py +0 -0
- {pycoze-0.1.93 → pycoze-0.1.94}/pycoze/ui/ui_def.py +0 -0
- {pycoze-0.1.93 → pycoze-0.1.94}/pycoze/utils/__init__.py +0 -0
- {pycoze-0.1.93 → pycoze-0.1.94}/pycoze/utils/arg.py +0 -0
- {pycoze-0.1.93 → pycoze-0.1.94}/pycoze/utils/text_or_file.py +0 -0
- {pycoze-0.1.93 → pycoze-0.1.94}/pycoze.egg-info/SOURCES.txt +0 -0
- {pycoze-0.1.93 → pycoze-0.1.94}/pycoze.egg-info/dependency_links.txt +0 -0
- {pycoze-0.1.93 → pycoze-0.1.94}/pycoze.egg-info/top_level.txt +0 -0
- {pycoze-0.1.93 → pycoze-0.1.94}/setup.cfg +0 -0
@@ -6,16 +6,22 @@ import types
|
|
6
6
|
import langchain_core
|
7
7
|
|
8
8
|
|
9
|
-
|
10
|
-
"""
|
11
|
-
sys.path.insert(0, module_path)
|
12
|
-
os.chdir(module_path)
|
9
|
+
class ChangeDirectoryAndPath:
|
10
|
+
"""Context manager to change the current working directory and sys.path."""
|
13
11
|
|
12
|
+
def __init__(self, module_path):
|
13
|
+
self.module_path = module_path
|
14
|
+
self.old_path = None
|
14
15
|
|
15
|
-
def
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
def __enter__(self):
|
17
|
+
self.old_path = os.getcwd()
|
18
|
+
sys.path.insert(0, self.module_path)
|
19
|
+
os.chdir(self.module_path)
|
20
|
+
return self
|
21
|
+
|
22
|
+
def __exit__(self, exc_type, exc_value, traceback):
|
23
|
+
sys.path.remove(self.module_path)
|
24
|
+
os.chdir(self.old_path)
|
19
25
|
|
20
26
|
|
21
27
|
def wrapped_tool(tool, module_path):
|
@@ -24,12 +30,8 @@ def wrapped_tool(tool, module_path):
|
|
24
30
|
|
25
31
|
def _wrapped_tool(*args, **kwargs):
|
26
32
|
print(f"调用了{tool.name}")
|
27
|
-
|
28
|
-
try:
|
29
|
-
change_directory_and_path(module_path)
|
33
|
+
with ChangeDirectoryAndPath(module_path):
|
30
34
|
result = original_tool_function(*args, **kwargs)
|
31
|
-
finally:
|
32
|
-
restore_directory_and_path(module_path, old_path)
|
33
35
|
print(f"{tool.name}调用完毕,结果为:", result)
|
34
36
|
return result
|
35
37
|
|
@@ -39,7 +41,6 @@ def wrapped_tool(tool, module_path):
|
|
39
41
|
def import_tools(tool_id):
|
40
42
|
"""Import tools from a specified tool_id."""
|
41
43
|
tool_base_path = "../../tool"
|
42
|
-
old_path = os.getcwd()
|
43
44
|
module_path = os.path.join(tool_base_path, tool_id)
|
44
45
|
module_path = os.path.normpath(os.path.abspath(module_path))
|
45
46
|
|
@@ -51,23 +52,22 @@ def import_tools(tool_id):
|
|
51
52
|
original_modules = sys.modules.copy()
|
52
53
|
|
53
54
|
try:
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
55
|
+
with ChangeDirectoryAndPath(module_path):
|
56
|
+
module = importlib.import_module("tool")
|
57
|
+
export_tools = getattr(module, "export_tools")
|
58
|
+
valid_tools = []
|
59
|
+
for tool in export_tools:
|
60
|
+
assert isinstance(tool, langchain_core.tools.StructuredTool) or isinstance(
|
61
|
+
tool, types.FunctionType
|
62
|
+
), f"Tool is not a StructuredTool or function: {tool}"
|
63
|
+
if isinstance(tool, types.FunctionType) and not isinstance(
|
64
|
+
tool, langchain_core.tools.StructuredTool
|
65
|
+
):
|
66
|
+
valid_tools.append(_tool(tool))
|
67
|
+
export_tools = valid_tools
|
67
68
|
|
68
69
|
except Exception as e:
|
69
70
|
print(f"Error loading tool {tool_id}: {e}")
|
70
|
-
restore_directory_and_path(module_path, old_path)
|
71
71
|
return []
|
72
72
|
|
73
73
|
# Unload modules and restore sys.modules state
|
@@ -76,9 +76,7 @@ def import_tools(tool_id):
|
|
76
76
|
if key not in original_modules:
|
77
77
|
del sys.modules[key]
|
78
78
|
|
79
|
-
restore_directory_and_path(module_path, old_path)
|
80
|
-
|
81
79
|
for tool in export_tools:
|
82
80
|
tool.func = wrapped_tool(tool, module_path)
|
83
81
|
|
84
|
-
return export_tools
|
82
|
+
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
|
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
|