pycoze 0.1.9__tar.gz → 0.1.13__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 (30) hide show
  1. {pycoze-0.1.9 → pycoze-0.1.13}/PKG-INFO +3 -3
  2. {pycoze-0.1.9 → pycoze-0.1.13}/README.md +14 -14
  3. {pycoze-0.1.9 → pycoze-0.1.13}/pycoze/bot/base.py +81 -79
  4. {pycoze-0.1.9 → pycoze-0.1.13}/pycoze/bot/bot.py +54 -50
  5. pycoze-0.1.13/pycoze/utils/__init__.py +1 -0
  6. {pycoze-0.1.9 → pycoze-0.1.13}/pycoze/utils/arg.py +25 -15
  7. {pycoze-0.1.9 → pycoze-0.1.13}/pycoze.egg-info/PKG-INFO +3 -3
  8. {pycoze-0.1.9 → pycoze-0.1.13}/setup.py +2 -2
  9. pycoze-0.1.9/pycoze/utils/__init__.py +0 -1
  10. {pycoze-0.1.9 → pycoze-0.1.13}/LICENSE +0 -0
  11. {pycoze-0.1.9 → pycoze-0.1.13}/pycoze/__init__.py +0 -0
  12. {pycoze-0.1.9 → pycoze-0.1.13}/pycoze/bot/__init__.py +0 -0
  13. {pycoze-0.1.9 → pycoze-0.1.13}/pycoze/bot/agent/__init__.py +0 -0
  14. {pycoze-0.1.9 → pycoze-0.1.13}/pycoze/bot/agent/agent.py +0 -0
  15. {pycoze-0.1.9 → pycoze-0.1.13}/pycoze/bot/agent/agent_types/__init__.py +0 -0
  16. {pycoze-0.1.9 → pycoze-0.1.13}/pycoze/bot/agent/agent_types/openai_func_call_agent.py +0 -0
  17. {pycoze-0.1.9 → pycoze-0.1.13}/pycoze/bot/agent/agent_types/react_agent.py +0 -0
  18. {pycoze-0.1.9 → pycoze-0.1.13}/pycoze/bot/agent/agent_types/react_prompt.py +0 -0
  19. {pycoze-0.1.9 → pycoze-0.1.13}/pycoze/bot/agent/assistant.py +0 -0
  20. {pycoze-0.1.9 → pycoze-0.1.13}/pycoze/bot/agent/chat.py +0 -0
  21. {pycoze-0.1.9 → pycoze-0.1.13}/pycoze/module.py +0 -0
  22. {pycoze-0.1.9 → pycoze-0.1.13}/pycoze/ui/__init__.py +0 -0
  23. {pycoze-0.1.9 → pycoze-0.1.13}/pycoze/ui/base.py +0 -0
  24. {pycoze-0.1.9 → pycoze-0.1.13}/pycoze/ui/color.py +0 -0
  25. {pycoze-0.1.9 → pycoze-0.1.13}/pycoze/ui/typ.py +0 -0
  26. {pycoze-0.1.9 → pycoze-0.1.13}/pycoze/ui/ui_def.py +0 -0
  27. {pycoze-0.1.9 → pycoze-0.1.13}/pycoze.egg-info/SOURCES.txt +0 -0
  28. {pycoze-0.1.9 → pycoze-0.1.13}/pycoze.egg-info/dependency_links.txt +0 -0
  29. {pycoze-0.1.9 → pycoze-0.1.13}/pycoze.egg-info/top_level.txt +0 -0
  30. {pycoze-0.1.9 → pycoze-0.1.13}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pycoze
3
- Version: 0.1.9
3
+ Version: 0.1.13
4
4
  Summary: Package for pycoze only!
5
5
  Author: Yuan Jie Xiong
6
6
  Author-email: aiqqqqqqq@qq.com
@@ -20,8 +20,8 @@ Package for pycoze only!
20
20
  <!-- For author only -->
21
21
  <!-- pip install twine -->
22
22
 
23
- <!-- 递增版本 -->
24
- <!-- 修改src\renderer\layout\init\const.ts中的库版本要求 -->
23
+ <!-- 递增setup.py的版本 -->
25
24
  <!-- 删除build和dist和pycoze.egg-info文件夹 -->
26
25
  <!-- python setup.py sdist bdist_wheel -->
27
26
  <!-- twine upload dist/* -->
27
+ <!-- 修改src\renderer\layout\init\const.ts中的库版本要求 -->
@@ -1,14 +1,14 @@
1
- # PYCOZE
2
-
3
- Package for pycoze only!
4
-
5
-
6
-
7
- <!-- For author only -->
8
- <!-- pip install twine -->
9
-
10
- <!-- 递增版本 -->
11
- <!-- 修改src\renderer\layout\init\const.ts中的库版本要求 -->
12
- <!-- 删除build和dist和pycoze.egg-info文件夹 -->
13
- <!-- python setup.py sdist bdist_wheel -->
14
- <!-- twine upload dist/* -->
1
+ # PYCOZE
2
+
3
+ Package for pycoze only!
4
+
5
+
6
+
7
+ <!-- For author only -->
8
+ <!-- pip install twine -->
9
+
10
+ <!-- 递增setup.py的版本 -->
11
+ <!-- 删除build和dist和pycoze.egg-info文件夹 -->
12
+ <!-- python setup.py sdist bdist_wheel -->
13
+ <!-- twine upload dist/* -->
14
+ <!-- 修改src\renderer\layout\init\const.ts中的库版本要求 -->
@@ -1,79 +1,81 @@
1
- import sys
2
- import os
3
- import argparse
4
- import importlib
5
- from langchain.agents import tool as _tool
6
- import types
7
- import langchain_core
8
-
9
- def wrapped_tool(tool, module_path):
10
- old_tool_fun = tool.func
11
- def _wrapped_tool(*args, **kwargs):
12
- print(f"调用了{tool.name}")
13
- old_path = os.getcwd()
14
- try:
15
- sys.path.insert(0, module_path) # 插入到第一个位置
16
- os.chdir(module_path)
17
- result = old_tool_fun(*args, **kwargs)
18
- finally:
19
- sys.path.remove(module_path)
20
- os.chdir(old_path)
21
- print(f"{tool.name}调用完毕,结果为:", result)
22
- return result
23
- return _wrapped_tool
24
-
25
-
26
- def import_tools(tool_id):
27
- tool_path = "../../tool"
28
- old_path = os.getcwd()
29
- module_path = os.path.join(tool_path, tool_id)
30
- module_path = os.path.normpath(os.path.abspath(module_path))
31
-
32
- if not os.path.exists(module_path):
33
- return []
34
-
35
- # 保存当前的 sys.modules 状态
36
- original_modules = sys.modules.copy()
37
-
38
- try:
39
- sys.path.insert(0, module_path) # 插入到第一个位置
40
- os.chdir(module_path)
41
- module = importlib.import_module("tool")
42
- export_tools = getattr(module, "export_tools")
43
- temp_list = []
44
- for tool in export_tools:
45
- assert isinstance(tool, langchain_core.tools.StructuredTool) or isinstance(tool, types.FunctionType), f"Tool is not a StructuredTool or function: {tool}"
46
- if isinstance(tool, types.FunctionType) and not isinstance(tool, langchain_core.tools.StructuredTool):
47
- temp_list.append(_tool(tool))
48
- export_tools = temp_list
49
-
50
- except Exception as e:
51
- sys.path.remove(module_path)
52
- os.chdir(old_path)
53
- return []
54
-
55
- # 卸载模块并恢复 sys.modules 状态
56
- importlib.invalidate_caches()
57
- for key in list(sys.modules.keys()):
58
- if key not in original_modules:
59
- del sys.modules[key]
60
-
61
- sys.path.remove(module_path)
62
- os.chdir(old_path)
63
-
64
- for tool in export_tools:
65
- tool.func = wrapped_tool(tool, module_path)
66
-
67
- return export_tools
68
-
69
-
70
- def read_arg(param: str, is_path=False):
71
- parser = argparse.ArgumentParser()
72
- parser.add_argument(param, nargs='?', help=f'Parameter {param}')
73
- args = parser.parse_args()
74
- value = getattr(args, param.lstrip('-'))
75
- # 如果是路径并且有引号,去掉引号
76
- if is_path and value and value.startswith('"') and value.endswith('"'):
77
- value = value[1:-1]
78
-
79
- return value
1
+ import sys
2
+ import os
3
+ import argparse
4
+ import importlib
5
+ from langchain.agents import tool as _tool
6
+ import types
7
+ import langchain_core
8
+
9
+ def wrapped_tool(tool, module_path):
10
+ old_tool_fun = tool.func
11
+ def _wrapped_tool(*args, **kwargs):
12
+ print(f"调用了{tool.name}")
13
+ old_path = os.getcwd()
14
+ try:
15
+ sys.path.insert(0, module_path) # 插入到第一个位置
16
+ os.chdir(module_path)
17
+ result = old_tool_fun(*args, **kwargs)
18
+ finally:
19
+ sys.path.remove(module_path)
20
+ os.chdir(old_path)
21
+ print(f"{tool.name}调用完毕,结果为:", result)
22
+ return result
23
+ return _wrapped_tool
24
+
25
+
26
+ def import_tools(tool_id):
27
+ tool_path = "../../tool"
28
+ old_path = os.getcwd()
29
+ module_path = os.path.join(tool_path, tool_id)
30
+ module_path = os.path.normpath(os.path.abspath(module_path))
31
+
32
+ if not os.path.exists(module_path):
33
+ print(f"Tool {tool_id} not found")
34
+ return []
35
+
36
+ # 保存当前的 sys.modules 状态
37
+ original_modules = sys.modules.copy()
38
+
39
+ try:
40
+ sys.path.insert(0, module_path) # 插入到第一个位置
41
+ os.chdir(module_path)
42
+ module = importlib.import_module("tool")
43
+ export_tools = getattr(module, "export_tools")
44
+ temp_list = []
45
+ for tool in export_tools:
46
+ assert isinstance(tool, langchain_core.tools.StructuredTool) or isinstance(tool, types.FunctionType), f"Tool is not a StructuredTool or function: {tool}"
47
+ if isinstance(tool, types.FunctionType) and not isinstance(tool, langchain_core.tools.StructuredTool):
48
+ temp_list.append(_tool(tool))
49
+ export_tools = temp_list
50
+
51
+ except Exception as e:
52
+ print(f"Error loading tool {tool_id}: {e}")
53
+ sys.path.remove(module_path)
54
+ os.chdir(old_path)
55
+ return []
56
+
57
+ # 卸载模块并恢复 sys.modules 状态
58
+ importlib.invalidate_caches()
59
+ for key in list(sys.modules.keys()):
60
+ if key not in original_modules:
61
+ del sys.modules[key]
62
+
63
+ sys.path.remove(module_path)
64
+ os.chdir(old_path)
65
+
66
+ for tool in export_tools:
67
+ tool.func = wrapped_tool(tool, module_path)
68
+
69
+ return export_tools
70
+
71
+
72
+ def read_arg(param: str, is_path=False):
73
+ parser = argparse.ArgumentParser()
74
+ parser.add_argument(param, nargs='?', help=f'Parameter {param}')
75
+ args = parser.parse_args()
76
+ value = getattr(args, param.lstrip('-'))
77
+ # 如果是路径并且有引号,去掉引号
78
+ if is_path and value and value.startswith('"') and value.endswith('"'):
79
+ value = value[1:-1]
80
+
81
+ return value
@@ -1,50 +1,54 @@
1
- import json
2
- from langchain_openai import ChatOpenAI
3
- from .base import import_tools
4
- from .agent import run_agent, Runnable, INPUT_MESSAGE, output
5
- import asyncio
6
- from langchain_core.messages import HumanMessage
7
-
8
-
9
- def load_role_setting(bot_setting_file:str):
10
- with open(bot_setting_file, "r", encoding="utf-8") as f:
11
- return json.load(f)
12
-
13
- def load_tools(bot_setting_file:str):
14
- with open(bot_setting_file, "r", encoding="utf-8") as f:
15
- role_setting = json.load(f)
16
-
17
- tools = []
18
- for tool_id in role_setting["tools"]:
19
- tools.extend(import_tools(tool_id))
20
- return tools
21
-
22
-
23
-
24
-
25
- def chat(bot_setting_file:str, llm_file:str):
26
- history = []
27
-
28
- while True:
29
- message = input()
30
- role_setting = load_role_setting(bot_setting_file)
31
- tools = load_tools(bot_setting_file)
32
- if not message.startswith(INPUT_MESSAGE):
33
- raise ValueError("Invalid message")
34
- message = json.loads(message[len(INPUT_MESSAGE):])["content"]
35
- print("user:", message)
36
-
37
- with open(llm_file, "r", encoding="utf-8") as f:
38
- cfg = json.load(f)
39
- chat = ChatOpenAI(api_key=cfg["apiKey"], base_url=cfg['baseURL'], model=cfg["model"], temperature=role_setting["temperature"])
40
-
41
-
42
- agent = Runnable(agent_execution_mode='FuncCall', # 'FuncCall' or 'ReAct',大模型支持FuncCall的话就用FuncCall
43
- tools=tools,
44
- llm=chat,
45
- assistant_message=role_setting["prompt"],)
46
-
47
- history += [HumanMessage(content=message)]
48
- result = asyncio.run(run_agent(agent, history))
49
- output("assistant", result, history)
50
-
1
+ import json
2
+ from langchain_openai import ChatOpenAI
3
+ from .base import import_tools
4
+ from .agent import run_agent, Runnable, INPUT_MESSAGE, output
5
+ import asyncio
6
+ from langchain_core.messages import HumanMessage
7
+ from pycoze import utils
8
+
9
+
10
+ params = utils.arg.read_params()
11
+ llm_file = params["appPath"] + "/JsonStorage/llm.json"
12
+
13
+ def load_role_setting(bot_setting_file:str):
14
+ with open(bot_setting_file, "r", encoding="utf-8") as f:
15
+ return json.load(f)
16
+
17
+ def load_tools(bot_setting_file:str):
18
+ with open(bot_setting_file, "r", encoding="utf-8") as f:
19
+ role_setting = json.load(f)
20
+
21
+ tools = []
22
+ for tool_id in role_setting["tools"]:
23
+ tools.extend(import_tools(tool_id))
24
+ return tools
25
+
26
+
27
+
28
+
29
+ def chat(bot_setting_file:str):
30
+ history = []
31
+
32
+ while True:
33
+ message = input()
34
+ role_setting = load_role_setting(bot_setting_file)
35
+ tools = load_tools(bot_setting_file)
36
+ if not message.startswith(INPUT_MESSAGE):
37
+ raise ValueError("Invalid message")
38
+ message = json.loads(message[len(INPUT_MESSAGE):])["content"]
39
+ print("user:", message)
40
+
41
+ with open(llm_file, "r", encoding="utf-8") as f:
42
+ cfg = json.load(f)
43
+ chat = ChatOpenAI(api_key=cfg["apiKey"], base_url=cfg['baseURL'], model=cfg["model"], temperature=role_setting["temperature"])
44
+
45
+
46
+ agent = Runnable(agent_execution_mode='FuncCall', # 'FuncCall' or 'ReAct',大模型支持FuncCall的话就用FuncCall
47
+ tools=tools,
48
+ llm=chat,
49
+ assistant_message=role_setting["prompt"],)
50
+
51
+ history += [HumanMessage(content=message)]
52
+ result = asyncio.run(run_agent(agent, history))
53
+ output("assistant", result, history)
54
+
@@ -0,0 +1 @@
1
+ from .arg import read_arg, read_params
@@ -1,15 +1,25 @@
1
- import argparse
2
- import sys
3
-
4
-
5
- def read_arg(param, is_path=False):
6
- args = sys.argv[1:]
7
- parser = argparse.ArgumentParser()
8
- parser.add_argument(param, nargs='?', help=f'Parameter {param}')
9
- args = parser.parse_known_args(args)[0]
10
- value = getattr(args, param.lstrip('-'))
11
- # 如果是路径并且有引号,去掉引号
12
- if is_path and value and value.startswith('"') and value.endswith('"'):
13
- value = value[1:-1]
14
-
15
- return value
1
+ import argparse
2
+ import sys
3
+ import json
4
+
5
+ def read_arg(param, is_path=False):
6
+ args = sys.argv[1:]
7
+ parser = argparse.ArgumentParser()
8
+ parser.add_argument(param, nargs='?', help=f'Parameter {param}')
9
+ args = parser.parse_known_args(args)[0]
10
+ value = getattr(args, param.lstrip('-'))
11
+ # 如果是路径并且有引号,去掉引号
12
+ if is_path and value and value.startswith('"') and value.endswith('"'):
13
+ value = value[1:-1]
14
+
15
+ return value
16
+
17
+ def read_params():
18
+ params_file = read_arg('params_file', True)
19
+ params = None
20
+ try:
21
+ with open(params_file, 'r', encoding='utf-8') as f:
22
+ params = json.load(f)
23
+ except Exception as e:
24
+ print(e)
25
+ return params
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pycoze
3
- Version: 0.1.9
3
+ Version: 0.1.13
4
4
  Summary: Package for pycoze only!
5
5
  Author: Yuan Jie Xiong
6
6
  Author-email: aiqqqqqqq@qq.com
@@ -20,8 +20,8 @@ Package for pycoze only!
20
20
  <!-- For author only -->
21
21
  <!-- pip install twine -->
22
22
 
23
- <!-- 递增版本 -->
24
- <!-- 修改src\renderer\layout\init\const.ts中的库版本要求 -->
23
+ <!-- 递增setup.py的版本 -->
25
24
  <!-- 删除build和dist和pycoze.egg-info文件夹 -->
26
25
  <!-- python setup.py sdist bdist_wheel -->
27
26
  <!-- twine upload dist/* -->
27
+ <!-- 修改src\renderer\layout\init\const.ts中的库版本要求 -->
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name="pycoze",
5
- version="0.1.9",
5
+ version="0.1.13",
6
6
  packages=find_packages(),
7
7
  install_requires=[],
8
8
  author="Yuan Jie Xiong",
@@ -16,4 +16,4 @@ setup(
16
16
  "Operating System :: OS Independent",
17
17
  ],
18
18
  python_requires='>=3.6',
19
- )
19
+ )
@@ -1 +0,0 @@
1
- from .arg import read_arg
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