pycoze 0.1.99__tar.gz → 0.1.101__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. {pycoze-0.1.99 → pycoze-0.1.101}/PKG-INFO +1 -1
  2. pycoze-0.1.101/pycoze/access/bot_for_bot.py +46 -0
  3. {pycoze-0.1.99 → pycoze-0.1.101}/pycoze/access/lib.py +4 -2
  4. {pycoze-0.1.99 → pycoze-0.1.101}/pycoze/access/tool_for_bot.py +2 -2
  5. {pycoze-0.1.99 → pycoze-0.1.101}/pycoze/bot/bot.py +13 -8
  6. {pycoze-0.1.99 → pycoze-0.1.101}/pycoze.egg-info/PKG-INFO +1 -1
  7. {pycoze-0.1.99 → pycoze-0.1.101}/setup.py +1 -1
  8. pycoze-0.1.99/pycoze/access/bot_for_bot.py +0 -40
  9. {pycoze-0.1.99 → pycoze-0.1.101}/LICENSE +0 -0
  10. {pycoze-0.1.99 → pycoze-0.1.101}/README.md +0 -0
  11. {pycoze-0.1.99 → pycoze-0.1.101}/pycoze/__init__.py +0 -0
  12. {pycoze-0.1.99 → pycoze-0.1.101}/pycoze/access/__init__.py +0 -0
  13. {pycoze-0.1.99 → pycoze-0.1.101}/pycoze/ai/__init__.py +0 -0
  14. {pycoze-0.1.99 → pycoze-0.1.101}/pycoze/ai/vram_reserve.py +0 -0
  15. {pycoze-0.1.99 → pycoze-0.1.101}/pycoze/bot/__init__.py +0 -0
  16. {pycoze-0.1.99 → pycoze-0.1.101}/pycoze/bot/agent/__init__.py +0 -0
  17. {pycoze-0.1.99 → pycoze-0.1.101}/pycoze/bot/agent/agent.py +0 -0
  18. {pycoze-0.1.99 → pycoze-0.1.101}/pycoze/bot/agent/agent_types/__init__.py +0 -0
  19. {pycoze-0.1.99 → pycoze-0.1.101}/pycoze/bot/agent/agent_types/openai_func_call_agent.py +0 -0
  20. {pycoze-0.1.99 → pycoze-0.1.101}/pycoze/bot/agent/assistant.py +0 -0
  21. {pycoze-0.1.99 → pycoze-0.1.101}/pycoze/bot/agent/chat.py +0 -0
  22. {pycoze-0.1.99 → pycoze-0.1.101}/pycoze/module.py +0 -0
  23. {pycoze-0.1.99 → pycoze-0.1.101}/pycoze/ui/__init__.py +0 -0
  24. {pycoze-0.1.99 → pycoze-0.1.101}/pycoze/ui/base.py +0 -0
  25. {pycoze-0.1.99 → pycoze-0.1.101}/pycoze/ui/color.py +0 -0
  26. {pycoze-0.1.99 → pycoze-0.1.101}/pycoze/ui/typ.py +0 -0
  27. {pycoze-0.1.99 → pycoze-0.1.101}/pycoze/ui/ui_def.py +0 -0
  28. {pycoze-0.1.99 → pycoze-0.1.101}/pycoze/utils/__init__.py +0 -0
  29. {pycoze-0.1.99 → pycoze-0.1.101}/pycoze/utils/arg.py +0 -0
  30. {pycoze-0.1.99 → pycoze-0.1.101}/pycoze/utils/text_or_file.py +0 -0
  31. {pycoze-0.1.99 → pycoze-0.1.101}/pycoze.egg-info/SOURCES.txt +0 -0
  32. {pycoze-0.1.99 → pycoze-0.1.101}/pycoze.egg-info/dependency_links.txt +0 -0
  33. {pycoze-0.1.99 → pycoze-0.1.101}/pycoze.egg-info/top_level.txt +0 -0
  34. {pycoze-0.1.99 → pycoze-0.1.101}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pycoze
3
- Version: 0.1.99
3
+ Version: 0.1.101
4
4
  Summary: Package for pycoze only!
5
5
  Author: Yuan Jie Xiong
6
6
  Author-email: aiqqqqqqq@qq.com
@@ -0,0 +1,46 @@
1
+ import sys
2
+ import os
3
+ import importlib
4
+ from langchain.agents import tool as to_agent_tool
5
+ import types
6
+ import langchain_core
7
+ from .lib import ChangeDirectoryAndPath, ModuleManager, wrapped_func
8
+
9
+
10
+ def import_bot(bot_id):
11
+ tool_base_path = "../"
12
+ module_path = os.path.join(tool_base_path, bot_id)
13
+ module_path = os.path.normpath(os.path.abspath(module_path))
14
+
15
+ if not os.path.exists(module_path):
16
+ print(f"Bot {bot_id} not found")
17
+ return None
18
+
19
+ try:
20
+ with ModuleManager(module_path) as manager:
21
+ bot_setting = module_path + "/botSetting.json"
22
+ with open(bot_setting, "r", encoding="utf-8") as f:
23
+ bot_setting = json.load(f)
24
+ module = importlib.import_module("bot_function")
25
+ chat_func = getattr(module, "chat")
26
+ random_name = "bot_" + bot_id[-6:]
27
+ # 定义函数的内容
28
+ function_code = f"""
29
+ def {random_name}(command:str) -> str:
30
+ \"\"\"
31
+ 本函数可以让你与虚拟人角色({bot_setting["name"]})进行交互。
32
+ 该函数接收一个指令字符串,并返回虚拟人执行该指令后的结果。
33
+
34
+ Args:
35
+ command: 需要执行的指令字符串。
36
+
37
+ Returns:
38
+ str: 虚拟人执行指令后的结果。
39
+ \"\"\"
40
+ return chat_func(command)
41
+ """
42
+
43
+ return wrapped_func(to_agent_tool(eval(random_name)))
44
+ except Exception as e:
45
+ print(f"Error loading bot {bot_id}: {e}")
46
+ return tool
@@ -47,7 +47,7 @@ class ModuleManager:
47
47
  del sys.modules[key]
48
48
 
49
49
 
50
- def wrapped_fun(item, module_path):
50
+ def wrapped_func(item, module_path):
51
51
  original_tool_function = item.func
52
52
 
53
53
  def _wrapped(*args, **kwargs):
@@ -57,4 +57,6 @@ def wrapped_fun(item, module_path):
57
57
  print(f"{item.name} 调用完毕,结果为:", result)
58
58
  return result
59
59
 
60
- return _wrapped
60
+ return _wrapped
61
+
62
+
@@ -4,7 +4,7 @@ import importlib
4
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, wrapped_fun
7
+ from .lib import ChangeDirectoryAndPath, ModuleManager, wrapped_func
8
8
 
9
9
 
10
10
  def import_tools(tool_id):
@@ -35,6 +35,6 @@ def import_tools(tool_id):
35
35
  return []
36
36
 
37
37
  for tool in export_tools:
38
- tool.func = wrapped_fun(tool, module_path)
38
+ tool.func = wrapped_func(tool, module_path)
39
39
 
40
40
  return export_tools
@@ -4,6 +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.bot_for_bot import import_bot
7
8
  from pycoze.access.tool_for_bot import import_tools
8
9
  from langchain_core.utils.function_calling import convert_to_openai_tool
9
10
 
@@ -18,19 +19,23 @@ def load_role_setting(bot_setting_file: str):
18
19
  return json.load(f)
19
20
 
20
21
 
21
- def load_tools(bot_setting_file: str):
22
+ def load_abilities(bot_setting_file: str):
22
23
  with open(bot_setting_file, "r", encoding="utf-8") as f:
23
24
  role_setting = json.load(f)
24
25
 
25
- tools = []
26
+ abilities = []
27
+ for bot_id in role_setting["bots"]:
28
+ bot = import_bot(bot_id)
29
+ if bot:
30
+ abilities.append(bot)
26
31
  for tool_id in role_setting["tools"]:
27
- tools.extend(import_tools(tool_id))
28
- return tools
32
+ abilities.extend(import_tools(tool_id))
33
+ return abilities
29
34
 
30
35
 
31
36
  def agent_chat(bot_setting_file, history):
32
37
  role_setting = load_role_setting(bot_setting_file)
33
- tools = load_tools(bot_setting_file)
38
+ abilities = load_abilities(bot_setting_file)
34
39
 
35
40
  chat = ChatOpenAI(
36
41
  api_key=cfg["apiKey"],
@@ -50,7 +55,7 @@ def agent_chat(bot_setting_file, history):
50
55
  if (
51
56
  cfg["model"].startswith("deepseek")
52
57
  or cfg["toolCompatibilityMode"]
53
- and len(tools) > 0
58
+ and len(abilities) > 0
54
59
  ):
55
60
  prompt += """
56
61
  作为一个AI,你如果不确定结果,请务必使用工具查询。
@@ -62,11 +67,11 @@ def agent_chat(bot_setting_file, history):
62
67
  """
63
68
  if cfg["model"].startswith("yi-"):
64
69
  prompt += "\nAvailable functions:\n"
65
- for t in tools:
70
+ for t in abilities:
66
71
  prompt += f"\n```json\n{json.dumps(convert_to_openai_tool(t))}\n```"
67
72
  agent = Runnable(
68
73
  agent_execution_mode="FuncCall",
69
- tools=tools,
74
+ tools=abilities,
70
75
  llm=chat,
71
76
  assistant_message=prompt,
72
77
  tool_compatibility_mode=cfg["toolCompatibilityMode"],
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pycoze
3
- Version: 0.1.99
3
+ Version: 0.1.101
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.99",
5
+ version="0.1.101",
6
6
  packages=find_packages(),
7
7
  install_requires=[],
8
8
  author="Yuan Jie Xiong",
@@ -1,40 +0,0 @@
1
- import sys
2
- import os
3
- import importlib
4
- from langchain.agents import tool as to_agent_tool
5
- import types
6
- import langchain_core
7
- from .lib import ChangeDirectoryAndPath, ModuleManager, wrapped_fun
8
-
9
-
10
- def import_tools(tool_id):
11
- tool_base_path = "../../tool"
12
- module_path = os.path.join(tool_base_path, tool_id)
13
- module_path = os.path.normpath(os.path.abspath(module_path))
14
-
15
- if not os.path.exists(module_path):
16
- print(f"Tool {tool_id} not found")
17
- return []
18
-
19
- try:
20
- with ModuleManager(module_path) as manager:
21
- module = importlib.import_module("tool")
22
- export_tools = getattr(module, "export_tools")
23
- valid_tools = []
24
- for tool in export_tools:
25
- assert isinstance(tool, langchain_core.tools.StructuredTool) or isinstance(
26
- tool, types.FunctionType
27
- ), f"Tool is not a StructuredTool or function: {tool}"
28
- if not isinstance(tool, langchain_core.tools.StructuredTool):
29
- tool = to_agent_tool(tool)
30
- valid_tools.append(tool)
31
- export_tools = valid_tools
32
-
33
- except Exception as e:
34
- print(f"Error loading tool {tool_id}: {e}")
35
- return []
36
-
37
- for tool in export_tools:
38
- tool.func = wrapped_fun(tool, module_path)
39
-
40
- 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