pycoze 0.1.94__tar.gz → 0.1.95__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {pycoze-0.1.94 → pycoze-0.1.95}/PKG-INFO +1 -1
- pycoze-0.1.95/pycoze/access/lib.py +46 -0
- {pycoze-0.1.94 → pycoze-0.1.95}/pycoze/access/tool_for_bot.py +7 -33
- {pycoze-0.1.94 → pycoze-0.1.95}/pycoze.egg-info/PKG-INFO +1 -1
- {pycoze-0.1.94 → pycoze-0.1.95}/pycoze.egg-info/SOURCES.txt +1 -0
- {pycoze-0.1.94 → pycoze-0.1.95}/setup.py +1 -1
- {pycoze-0.1.94 → pycoze-0.1.95}/LICENSE +0 -0
- {pycoze-0.1.94 → pycoze-0.1.95}/README.md +0 -0
- {pycoze-0.1.94 → pycoze-0.1.95}/pycoze/__init__.py +0 -0
- {pycoze-0.1.94 → pycoze-0.1.95}/pycoze/access/__init__.py +0 -0
- {pycoze-0.1.94 → pycoze-0.1.95}/pycoze/ai/__init__.py +0 -0
- {pycoze-0.1.94 → pycoze-0.1.95}/pycoze/ai/vram_reserve.py +0 -0
- {pycoze-0.1.94 → pycoze-0.1.95}/pycoze/bot/__init__.py +0 -0
- {pycoze-0.1.94 → pycoze-0.1.95}/pycoze/bot/agent/__init__.py +0 -0
- {pycoze-0.1.94 → pycoze-0.1.95}/pycoze/bot/agent/agent.py +0 -0
- {pycoze-0.1.94 → pycoze-0.1.95}/pycoze/bot/agent/agent_types/__init__.py +0 -0
- {pycoze-0.1.94 → pycoze-0.1.95}/pycoze/bot/agent/agent_types/openai_func_call_agent.py +0 -0
- {pycoze-0.1.94 → pycoze-0.1.95}/pycoze/bot/agent/assistant.py +0 -0
- {pycoze-0.1.94 → pycoze-0.1.95}/pycoze/bot/agent/chat.py +0 -0
- {pycoze-0.1.94 → pycoze-0.1.95}/pycoze/bot/bot.py +0 -0
- {pycoze-0.1.94 → pycoze-0.1.95}/pycoze/module.py +0 -0
- {pycoze-0.1.94 → pycoze-0.1.95}/pycoze/ui/__init__.py +0 -0
- {pycoze-0.1.94 → pycoze-0.1.95}/pycoze/ui/base.py +0 -0
- {pycoze-0.1.94 → pycoze-0.1.95}/pycoze/ui/color.py +0 -0
- {pycoze-0.1.94 → pycoze-0.1.95}/pycoze/ui/typ.py +0 -0
- {pycoze-0.1.94 → pycoze-0.1.95}/pycoze/ui/ui_def.py +0 -0
- {pycoze-0.1.94 → pycoze-0.1.95}/pycoze/utils/__init__.py +0 -0
- {pycoze-0.1.94 → pycoze-0.1.95}/pycoze/utils/arg.py +0 -0
- {pycoze-0.1.94 → pycoze-0.1.95}/pycoze/utils/text_or_file.py +0 -0
- {pycoze-0.1.94 → pycoze-0.1.95}/pycoze.egg-info/dependency_links.txt +0 -0
- {pycoze-0.1.94 → pycoze-0.1.95}/pycoze.egg-info/top_level.txt +0 -0
- {pycoze-0.1.94 → pycoze-0.1.95}/setup.cfg +0 -0
@@ -0,0 +1,46 @@
|
|
1
|
+
import os
|
2
|
+
import sys
|
3
|
+
|
4
|
+
|
5
|
+
class ChangeDirectoryAndPath:
|
6
|
+
"""Context manager to change the current working directory and sys.path."""
|
7
|
+
|
8
|
+
def __init__(self, module_path):
|
9
|
+
self.module_path = module_path
|
10
|
+
self.old_path = None
|
11
|
+
|
12
|
+
def __enter__(self):
|
13
|
+
self.old_path = os.getcwd()
|
14
|
+
sys.path.insert(0, self.module_path)
|
15
|
+
os.chdir(self.module_path)
|
16
|
+
return self
|
17
|
+
|
18
|
+
def __exit__(self, exc_type, exc_value, traceback):
|
19
|
+
sys.path.remove(self.module_path)
|
20
|
+
os.chdir(self.old_path)
|
21
|
+
|
22
|
+
|
23
|
+
class ModuleManager:
|
24
|
+
"""Context manager for handling module imports and sys.modules state."""
|
25
|
+
|
26
|
+
def __init__(self, module_path):
|
27
|
+
self.module_path = module_path
|
28
|
+
self.original_modules = sys.modules.copy()
|
29
|
+
|
30
|
+
def __enter__(self):
|
31
|
+
"""Enter the runtime context related to this object."""
|
32
|
+
self.change_dir = ChangeDirectoryAndPath(self.module_path)
|
33
|
+
self.change_dir.__enter__()
|
34
|
+
return self
|
35
|
+
|
36
|
+
def __exit__(self, exc_type, exc_value, traceback):
|
37
|
+
"""Exit the runtime context related to this object."""
|
38
|
+
self.change_dir.__exit__(exc_type, exc_value, traceback)
|
39
|
+
self.cleanup_modules()
|
40
|
+
|
41
|
+
def cleanup_modules(self):
|
42
|
+
"""Restore the original sys.modules state."""
|
43
|
+
importlib.invalidate_caches()
|
44
|
+
for key in list(sys.modules.keys()):
|
45
|
+
if key not in self.original_modules:
|
46
|
+
del sys.modules[key]
|
@@ -1,28 +1,12 @@
|
|
1
1
|
import sys
|
2
2
|
import os
|
3
3
|
import importlib
|
4
|
-
from langchain.agents import tool as
|
4
|
+
from langchain.agents import tool as to_agent_tool
|
5
5
|
import types
|
6
6
|
import langchain_core
|
7
|
+
from .lib import ChangeDirectoryAndPath, ModuleManager
|
7
8
|
|
8
9
|
|
9
|
-
class ChangeDirectoryAndPath:
|
10
|
-
"""Context manager to change the current working directory and sys.path."""
|
11
|
-
|
12
|
-
def __init__(self, module_path):
|
13
|
-
self.module_path = module_path
|
14
|
-
self.old_path = None
|
15
|
-
|
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)
|
25
|
-
|
26
10
|
|
27
11
|
def wrapped_tool(tool, module_path):
|
28
12
|
"""Wrap the tool function to include additional logging and path management."""
|
@@ -48,11 +32,8 @@ def import_tools(tool_id):
|
|
48
32
|
print(f"Tool {tool_id} not found")
|
49
33
|
return []
|
50
34
|
|
51
|
-
# Save the current sys.modules state
|
52
|
-
original_modules = sys.modules.copy()
|
53
|
-
|
54
35
|
try:
|
55
|
-
with
|
36
|
+
with ModuleManager(module_path) as manager:
|
56
37
|
module = importlib.import_module("tool")
|
57
38
|
export_tools = getattr(module, "export_tools")
|
58
39
|
valid_tools = []
|
@@ -60,23 +41,16 @@ def import_tools(tool_id):
|
|
60
41
|
assert isinstance(tool, langchain_core.tools.StructuredTool) or isinstance(
|
61
42
|
tool, types.FunctionType
|
62
43
|
), f"Tool is not a StructuredTool or function: {tool}"
|
63
|
-
if
|
64
|
-
tool
|
65
|
-
)
|
66
|
-
valid_tools.append(_tool(tool))
|
44
|
+
if not isiisinstance(tool, langchain_core.tools.StructuredTool):
|
45
|
+
tool = to_agent_tool(tool)
|
46
|
+
valid_tools.append(to_agent_tool(tool))
|
67
47
|
export_tools = valid_tools
|
68
48
|
|
69
49
|
except Exception as e:
|
70
50
|
print(f"Error loading tool {tool_id}: {e}")
|
71
51
|
return []
|
72
52
|
|
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
53
|
for tool in export_tools:
|
80
54
|
tool.func = wrapped_tool(tool, module_path)
|
81
55
|
|
82
|
-
return export_tools
|
56
|
+
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
|