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.
Files changed (31) hide show
  1. {pycoze-0.1.93 → pycoze-0.1.94}/PKG-INFO +1 -1
  2. {pycoze-0.1.93 → pycoze-0.1.94}/pycoze/access/tool_for_bot.py +29 -31
  3. {pycoze-0.1.93 → pycoze-0.1.94}/pycoze.egg-info/PKG-INFO +1 -1
  4. {pycoze-0.1.93 → pycoze-0.1.94}/setup.py +1 -1
  5. {pycoze-0.1.93 → pycoze-0.1.94}/LICENSE +0 -0
  6. {pycoze-0.1.93 → pycoze-0.1.94}/README.md +0 -0
  7. {pycoze-0.1.93 → pycoze-0.1.94}/pycoze/__init__.py +0 -0
  8. {pycoze-0.1.93 → pycoze-0.1.94}/pycoze/access/__init__.py +0 -0
  9. {pycoze-0.1.93 → pycoze-0.1.94}/pycoze/ai/__init__.py +0 -0
  10. {pycoze-0.1.93 → pycoze-0.1.94}/pycoze/ai/vram_reserve.py +0 -0
  11. {pycoze-0.1.93 → pycoze-0.1.94}/pycoze/bot/__init__.py +0 -0
  12. {pycoze-0.1.93 → pycoze-0.1.94}/pycoze/bot/agent/__init__.py +0 -0
  13. {pycoze-0.1.93 → pycoze-0.1.94}/pycoze/bot/agent/agent.py +0 -0
  14. {pycoze-0.1.93 → pycoze-0.1.94}/pycoze/bot/agent/agent_types/__init__.py +0 -0
  15. {pycoze-0.1.93 → pycoze-0.1.94}/pycoze/bot/agent/agent_types/openai_func_call_agent.py +0 -0
  16. {pycoze-0.1.93 → pycoze-0.1.94}/pycoze/bot/agent/assistant.py +0 -0
  17. {pycoze-0.1.93 → pycoze-0.1.94}/pycoze/bot/agent/chat.py +0 -0
  18. {pycoze-0.1.93 → pycoze-0.1.94}/pycoze/bot/bot.py +0 -0
  19. {pycoze-0.1.93 → pycoze-0.1.94}/pycoze/module.py +0 -0
  20. {pycoze-0.1.93 → pycoze-0.1.94}/pycoze/ui/__init__.py +0 -0
  21. {pycoze-0.1.93 → pycoze-0.1.94}/pycoze/ui/base.py +0 -0
  22. {pycoze-0.1.93 → pycoze-0.1.94}/pycoze/ui/color.py +0 -0
  23. {pycoze-0.1.93 → pycoze-0.1.94}/pycoze/ui/typ.py +0 -0
  24. {pycoze-0.1.93 → pycoze-0.1.94}/pycoze/ui/ui_def.py +0 -0
  25. {pycoze-0.1.93 → pycoze-0.1.94}/pycoze/utils/__init__.py +0 -0
  26. {pycoze-0.1.93 → pycoze-0.1.94}/pycoze/utils/arg.py +0 -0
  27. {pycoze-0.1.93 → pycoze-0.1.94}/pycoze/utils/text_or_file.py +0 -0
  28. {pycoze-0.1.93 → pycoze-0.1.94}/pycoze.egg-info/SOURCES.txt +0 -0
  29. {pycoze-0.1.93 → pycoze-0.1.94}/pycoze.egg-info/dependency_links.txt +0 -0
  30. {pycoze-0.1.93 → pycoze-0.1.94}/pycoze.egg-info/top_level.txt +0 -0
  31. {pycoze-0.1.93 → pycoze-0.1.94}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pycoze
3
- Version: 0.1.93
3
+ Version: 0.1.94
4
4
  Summary: Package for pycoze only!
5
5
  Author: Yuan Jie Xiong
6
6
  Author-email: aiqqqqqqq@qq.com
@@ -6,16 +6,22 @@ import types
6
6
  import langchain_core
7
7
 
8
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)
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 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)
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
- old_path = os.getcwd()
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
- 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
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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pycoze
3
- Version: 0.1.93
3
+ Version: 0.1.94
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.93",
5
+ version="0.1.94",
6
6
  packages=find_packages(),
7
7
  install_requires=[],
8
8
  author="Yuan Jie Xiong",
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