pycoze 0.1.39__tar.gz → 0.1.41__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 (33) hide show
  1. {pycoze-0.1.39 → pycoze-0.1.41}/PKG-INFO +1 -1
  2. pycoze-0.1.41/pycoze/access/tool_for_bot.py +75 -0
  3. {pycoze-0.1.39 → pycoze-0.1.41}/pycoze/bot/bot.py +1 -1
  4. pycoze-0.1.41/pycoze/module.py +0 -0
  5. {pycoze-0.1.39 → pycoze-0.1.41}/pycoze.egg-info/PKG-INFO +1 -1
  6. {pycoze-0.1.39 → pycoze-0.1.41}/pycoze.egg-info/SOURCES.txt +2 -0
  7. {pycoze-0.1.39 → pycoze-0.1.41}/setup.py +1 -1
  8. {pycoze-0.1.39 → pycoze-0.1.41}/LICENSE +0 -0
  9. {pycoze-0.1.39 → pycoze-0.1.41}/README.md +0 -0
  10. {pycoze-0.1.39 → pycoze-0.1.41}/pycoze/__init__.py +0 -0
  11. /pycoze-0.1.39/pycoze/module.py → /pycoze-0.1.41/pycoze/access/__init__.py +0 -0
  12. {pycoze-0.1.39 → pycoze-0.1.41}/pycoze/bot/__init__.py +0 -0
  13. {pycoze-0.1.39 → pycoze-0.1.41}/pycoze/bot/agent/__init__.py +0 -0
  14. {pycoze-0.1.39 → pycoze-0.1.41}/pycoze/bot/agent/agent.py +0 -0
  15. {pycoze-0.1.39 → pycoze-0.1.41}/pycoze/bot/agent/agent_types/__init__.py +0 -0
  16. {pycoze-0.1.39 → pycoze-0.1.41}/pycoze/bot/agent/agent_types/openai_func_call_agent.py +0 -0
  17. {pycoze-0.1.39 → pycoze-0.1.41}/pycoze/bot/agent/agent_types/react_agent.py +0 -0
  18. {pycoze-0.1.39 → pycoze-0.1.41}/pycoze/bot/agent/agent_types/react_prompt.py +0 -0
  19. {pycoze-0.1.39 → pycoze-0.1.41}/pycoze/bot/agent/assistant.py +0 -0
  20. {pycoze-0.1.39 → pycoze-0.1.41}/pycoze/bot/agent/chat.py +0 -0
  21. {pycoze-0.1.39 → pycoze-0.1.41}/pycoze/gpu/__init__.py +0 -0
  22. {pycoze-0.1.39 → pycoze-0.1.41}/pycoze/gpu/gpu_reserve.py +0 -0
  23. {pycoze-0.1.39 → pycoze-0.1.41}/pycoze/ui/__init__.py +0 -0
  24. {pycoze-0.1.39 → pycoze-0.1.41}/pycoze/ui/base.py +0 -0
  25. {pycoze-0.1.39 → pycoze-0.1.41}/pycoze/ui/color.py +0 -0
  26. {pycoze-0.1.39 → pycoze-0.1.41}/pycoze/ui/typ.py +0 -0
  27. {pycoze-0.1.39 → pycoze-0.1.41}/pycoze/ui/ui_def.py +0 -0
  28. {pycoze-0.1.39 → pycoze-0.1.41}/pycoze/utils/__init__.py +0 -0
  29. {pycoze-0.1.39 → pycoze-0.1.41}/pycoze/utils/arg.py +0 -0
  30. {pycoze-0.1.39 → pycoze-0.1.41}/pycoze/utils/text_or_file.py +0 -0
  31. {pycoze-0.1.39 → pycoze-0.1.41}/pycoze.egg-info/dependency_links.txt +0 -0
  32. {pycoze-0.1.39 → pycoze-0.1.41}/pycoze.egg-info/top_level.txt +0 -0
  33. {pycoze-0.1.39 → pycoze-0.1.41}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pycoze
3
- Version: 0.1.39
3
+ Version: 0.1.41
4
4
  Summary: Package for pycoze only!
5
5
  Author: Yuan Jie Xiong
6
6
  Author-email: aiqqqqqqq@qq.com
@@ -0,0 +1,75 @@
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
@@ -4,7 +4,7 @@ from .agent import run_agent, Runnable, INPUT_MESSAGE, output
4
4
  import asyncio
5
5
  from langchain_core.messages import HumanMessage
6
6
  from pycoze import utils
7
- from pycoze.access.
7
+ from pycoze.access.tool_for_bot import import_tools
8
8
 
9
9
  params = utils.arg.read_params()
10
10
  llm_file = params["appPath"] + "/JsonStorage/llm.json"
File without changes
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pycoze
3
- Version: 0.1.39
3
+ Version: 0.1.41
4
4
  Summary: Package for pycoze only!
5
5
  Author: Yuan Jie Xiong
6
6
  Author-email: aiqqqqqqq@qq.com
@@ -7,6 +7,8 @@ pycoze.egg-info/PKG-INFO
7
7
  pycoze.egg-info/SOURCES.txt
8
8
  pycoze.egg-info/dependency_links.txt
9
9
  pycoze.egg-info/top_level.txt
10
+ pycoze/access/__init__.py
11
+ pycoze/access/tool_for_bot.py
10
12
  pycoze/bot/__init__.py
11
13
  pycoze/bot/bot.py
12
14
  pycoze/bot/agent/__init__.py
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name="pycoze",
5
- version="0.1.39",
5
+ version="0.1.41",
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