pycoze 0.1.300__tar.gz → 0.1.302__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 (49) hide show
  1. {pycoze-0.1.300 → pycoze-0.1.302}/PKG-INFO +1 -1
  2. {pycoze-0.1.300 → pycoze-0.1.302}/pycoze/bot/agent_chat.py +8 -8
  3. {pycoze-0.1.300 → pycoze-0.1.302}/pycoze/reference/bot.py +5 -7
  4. {pycoze-0.1.300 → pycoze-0.1.302}/pycoze/reference/lib.py +4 -5
  5. pycoze-0.1.302/pycoze/reference/tool.py +35 -0
  6. pycoze-0.1.302/pycoze/reference/workflow.py +45 -0
  7. {pycoze-0.1.300 → pycoze-0.1.302}/pycoze.egg-info/PKG-INFO +1 -1
  8. {pycoze-0.1.300 → pycoze-0.1.302}/setup.py +1 -1
  9. pycoze-0.1.300/pycoze/reference/tool.py +0 -49
  10. pycoze-0.1.300/pycoze/reference/workflow.py +0 -59
  11. {pycoze-0.1.300 → pycoze-0.1.302}/LICENSE +0 -0
  12. {pycoze-0.1.300 → pycoze-0.1.302}/README.md +0 -0
  13. {pycoze-0.1.300 → pycoze-0.1.302}/pycoze/__init__.py +0 -0
  14. {pycoze-0.1.300 → pycoze-0.1.302}/pycoze/ai/__init__.py +0 -0
  15. {pycoze-0.1.300 → pycoze-0.1.302}/pycoze/ai/llm/__init__.py +0 -0
  16. {pycoze-0.1.300 → pycoze-0.1.302}/pycoze/ai/llm/chat.py +0 -0
  17. {pycoze-0.1.300 → pycoze-0.1.302}/pycoze/ai/llm/text_to_image_prompt.py +0 -0
  18. {pycoze-0.1.300 → pycoze-0.1.302}/pycoze/ai/llm/think.py +0 -0
  19. {pycoze-0.1.300 → pycoze-0.1.302}/pycoze/ai/vram_reserve.py +0 -0
  20. {pycoze-0.1.300 → pycoze-0.1.302}/pycoze/api/__init__.py +0 -0
  21. {pycoze-0.1.300 → pycoze-0.1.302}/pycoze/api/lib/__init__.py +0 -0
  22. {pycoze-0.1.300 → pycoze-0.1.302}/pycoze/api/lib/tab.py +0 -0
  23. {pycoze-0.1.300 → pycoze-0.1.302}/pycoze/api/lib/view.py +0 -0
  24. {pycoze-0.1.300 → pycoze-0.1.302}/pycoze/api/lib/web.py +0 -0
  25. {pycoze-0.1.300 → pycoze-0.1.302}/pycoze/api/lib/window.py +0 -0
  26. {pycoze-0.1.300 → pycoze-0.1.302}/pycoze/bot/__init__.py +0 -0
  27. {pycoze-0.1.300 → pycoze-0.1.302}/pycoze/bot/agent/__init__.py +0 -0
  28. {pycoze-0.1.300 → pycoze-0.1.302}/pycoze/bot/agent/agent.py +0 -0
  29. {pycoze-0.1.300 → pycoze-0.1.302}/pycoze/bot/agent/agent_types/__init__.py +0 -0
  30. {pycoze-0.1.300 → pycoze-0.1.302}/pycoze/bot/agent/agent_types/const.py +0 -0
  31. {pycoze-0.1.300 → pycoze-0.1.302}/pycoze/bot/agent/agent_types/openai_func_call_agent.py +0 -0
  32. {pycoze-0.1.300 → pycoze-0.1.302}/pycoze/bot/agent/assistant.py +0 -0
  33. {pycoze-0.1.300 → pycoze-0.1.302}/pycoze/bot/agent/chat.py +0 -0
  34. {pycoze-0.1.300 → pycoze-0.1.302}/pycoze/bot/bot.py +0 -0
  35. {pycoze-0.1.300 → pycoze-0.1.302}/pycoze/reference/__init__.py +0 -0
  36. {pycoze-0.1.300 → pycoze-0.1.302}/pycoze/ui/__init__.py +0 -0
  37. {pycoze-0.1.300 → pycoze-0.1.302}/pycoze/ui/base.py +0 -0
  38. {pycoze-0.1.300 → pycoze-0.1.302}/pycoze/ui/color.py +0 -0
  39. {pycoze-0.1.300 → pycoze-0.1.302}/pycoze/ui/typ.py +0 -0
  40. {pycoze-0.1.300 → pycoze-0.1.302}/pycoze/ui/ui_def.py +0 -0
  41. {pycoze-0.1.300 → pycoze-0.1.302}/pycoze/utils/__init__.py +0 -0
  42. {pycoze-0.1.300 → pycoze-0.1.302}/pycoze/utils/arg.py +0 -0
  43. {pycoze-0.1.300 → pycoze-0.1.302}/pycoze/utils/env.py +0 -0
  44. {pycoze-0.1.300 → pycoze-0.1.302}/pycoze/utils/socket.py +0 -0
  45. {pycoze-0.1.300 → pycoze-0.1.302}/pycoze/utils/text_or_file.py +0 -0
  46. {pycoze-0.1.300 → pycoze-0.1.302}/pycoze.egg-info/SOURCES.txt +0 -0
  47. {pycoze-0.1.300 → pycoze-0.1.302}/pycoze.egg-info/dependency_links.txt +0 -0
  48. {pycoze-0.1.300 → pycoze-0.1.302}/pycoze.egg-info/top_level.txt +0 -0
  49. {pycoze-0.1.300 → pycoze-0.1.302}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: pycoze
3
- Version: 0.1.300
3
+ Version: 0.1.302
4
4
  Summary: Package for pycoze only!
5
5
  Author: Yuan Jie Xiong
6
6
  Author-email: aiqqqqqqq@qq.com
@@ -11,23 +11,23 @@ import os
11
11
 
12
12
  cfg = utils.read_json_file("llm.json")
13
13
 
14
- def load_role_setting(bot_setting_file: str):
14
+ def load_bot_setting(bot_setting_file: str):
15
15
  with open(bot_setting_file, "r", encoding="utf-8") as f:
16
16
  return json.load(f)
17
17
 
18
18
 
19
19
  def load_abilities(bot_setting_file: str):
20
20
  with open(bot_setting_file, "r", encoding="utf-8") as f:
21
- role_setting = json.load(f)
21
+ bot_setting = json.load(f)
22
22
 
23
23
  abilities = []
24
- for bot_id in role_setting["bots"]:
24
+ for bot_id in bot_setting["bots"]:
25
25
  bot = ref_bot(bot_id, as_agent_tool=True)
26
26
  if bot:
27
27
  abilities.append(bot)
28
- for tool_id in role_setting["tools"]:
28
+ for tool_id in bot_setting["tools"]:
29
29
  abilities.extend(ref_tools(tool_id, as_agent_tool=True))
30
- for workflow_id in role_setting["workflows"]:
30
+ for workflow_id in bot_setting["workflows"]:
31
31
  workflow = ref_workflow(workflow_id, as_agent_tool=True)
32
32
  if workflow:
33
33
  abilities.append(workflow)
@@ -67,20 +67,20 @@ async def run_with_interrupt_check(agent, history, tool_compatibility_mode, inte
67
67
  pass # 忽略取消错误
68
68
 
69
69
  async def agent_chat(bot_setting_file, history):
70
- role_setting = load_role_setting(bot_setting_file)
70
+ bot_setting = load_bot_setting(bot_setting_file)
71
71
  abilities = load_abilities(bot_setting_file)
72
72
 
73
73
  chat = ChatOpenAI(
74
74
  api_key=cfg["apiKey"],
75
75
  base_url=cfg["baseURL"],
76
76
  model=cfg["model"],
77
- temperature=role_setting["temperature"],
77
+ temperature=bot_setting["temperature"],
78
78
  stop_sequences=[
79
79
  "tool▁calls▁end",
80
80
  "tool▁call▁end",
81
81
  ], # 不然会虚构工具调用过程和结果
82
82
  )
83
- prompt = role_setting["prompt"]
83
+ prompt = bot_setting["prompt"]
84
84
  if cfg["toolCompatibilityMode"] and len(abilities) > 0:
85
85
  prompt += """
86
86
  作为一个AI,你如果不确定结果,请务必使用工具查询。
@@ -1,5 +1,4 @@
1
1
  import os
2
- from langchain.agents import tool as to_agent_tool
3
2
  from .lib import ModuleManager, wrapped_func
4
3
  import json
5
4
  from pycoze import utils
@@ -9,7 +8,7 @@ bot_index = 0
9
8
  params = utils.params
10
9
 
11
10
 
12
- def ref_bot(bot_id, as_agent_tool=False, workspace_path=None):
11
+ def ref_bot(bot_id, workspace_path=None):
13
12
  global bot_index
14
13
  if workspace_path is None:
15
14
  workspace_path = params["workspacePath"]
@@ -51,11 +50,10 @@ def {random_name}(command:str) -> str:
51
50
  return result
52
51
  """
53
52
  exec(function_code)
54
- tool = to_agent_tool(eval(random_name))
55
- tool.func = wrapped_func(tool, module_path)
56
- if tool.description is None:
57
- tool.description = "This tool is used to " + tool.name + "."
58
- return tool if as_agent_tool else tool.func
53
+ tool = eval(random_name)
54
+ tool = wrapped_func(tool, module_path)
55
+
56
+ return tool
59
57
  except Exception as e:
60
58
  print(f"Error loading bot {bot_id}: {e}")
61
59
  return None
@@ -48,20 +48,19 @@ class ModuleManager:
48
48
  del sys.modules[key]
49
49
 
50
50
 
51
- def wrapped_func(item, module_path):
52
- original_tool_function = item.func
51
+ def wrapped_func(func, module_path):
53
52
 
54
53
  def _wrapped(*args, **kwargs):
55
54
  try:
56
- print(f"调用了 {item.name}")
55
+ print(f"调用了 {func.__name__}")
57
56
  except:
58
57
  print(f"called unknown")
59
58
  with ChangeDirectoryAndPath(module_path):
60
- result = original_tool_function(*args, **kwargs)
59
+ result = func(*args, **kwargs)
61
60
  try:
62
61
  if isinstance(result, types.GeneratorType):
63
62
  result = list(result)
64
- print(f"{item.name} 调用完毕,结果为:", result)
63
+ print(f"{func.__name__} 调用完毕,结果为:", result)
65
64
  except:
66
65
  pass
67
66
  return result
@@ -0,0 +1,35 @@
1
+ import os
2
+ import importlib
3
+ from .lib import ModuleManager, wrapped_func
4
+ from pycoze import utils
5
+
6
+
7
+ params = utils.params
8
+
9
+
10
+ def ref_tools(tool_id, workspace_path=None):
11
+ if workspace_path is None:
12
+ workspace_path = params["workspacePath"]
13
+ tool_base_path = os.path.join(workspace_path, "User/Local/tool")
14
+ module_path = os.path.join(tool_base_path, tool_id)
15
+ module_path = os.path.normpath(os.path.abspath(module_path))
16
+
17
+ if not os.path.exists(module_path):
18
+ print(f"Tool {tool_id} not found")
19
+ return []
20
+
21
+ try:
22
+ with ModuleManager(module_path) as manager:
23
+ module = importlib.import_module("tool")
24
+ export_tools = getattr(module, "export_tools")
25
+
26
+ except Exception as e:
27
+ print(f"Error loading tool {tool_id}: {e}")
28
+ return []
29
+
30
+ for tool in export_tools:
31
+ tool = wrapped_func(tool, module_path)
32
+ if tool.__doc__ is None:
33
+ tool.__doc__ = "This tool is used to " + tool.__name__.split("_") + "."
34
+
35
+ return [tool.func for tool in export_tools]
@@ -0,0 +1,45 @@
1
+ import os
2
+ import importlib
3
+ from .lib import ModuleManager, wrapped_func
4
+ from pycoze import utils
5
+
6
+
7
+ params = utils.params
8
+
9
+
10
+ def _ref_workflows(workflow_id, workspace_path=None):
11
+ if workspace_path is None:
12
+ workspace_path = params["workspacePath"]
13
+ tool_base_path = os.path.join(workspace_path, "User/Local/workflow")
14
+ module_path = os.path.join(tool_base_path, workflow_id)
15
+ module_path = os.path.normpath(os.path.abspath(module_path))
16
+
17
+ if not os.path.exists(module_path):
18
+ print(f"Workflow {workflow_id} not found")
19
+ return []
20
+
21
+ try:
22
+ with ModuleManager(module_path) as manager:
23
+ module = importlib.import_module("tool")
24
+ export_tools = getattr(module, "export_tools")
25
+
26
+ except Exception as e:
27
+ print(f"Error loading workflow {workflow_id}: {e}")
28
+ return []
29
+
30
+ for tool in export_tools:
31
+ tool = wrapped_func(tool, module_path)
32
+ if tool.__doc__ is None:
33
+ tool.__doc__ = "This tool is used to " + tool.__name__.split("_") + "."
34
+
35
+ return [tool.func for tool in export_tools]
36
+
37
+
38
+ def ref_workflow(workflow_id, workspace_path=None):
39
+ tools = _ref_workflows(
40
+ workflow_id, workspace_path=workspace_path
41
+ )
42
+ if len(tools) > 0:
43
+ return tools[0]
44
+ else:
45
+ return None
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: pycoze
3
- Version: 0.1.300
3
+ Version: 0.1.302
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.300",
5
+ version="0.1.302",
6
6
  packages=find_packages(),
7
7
  install_requires=[],
8
8
  author="Yuan Jie Xiong",
@@ -1,49 +0,0 @@
1
- import os
2
- import importlib
3
- from langchain.agents import tool as to_agent_tool
4
- import types
5
- import langchain_core
6
- from .lib import ModuleManager, wrapped_func
7
- from pycoze import utils
8
-
9
-
10
- params = utils.params
11
-
12
-
13
- def ref_tools(tool_id, as_agent_tool=False, workspace_path=None):
14
- if workspace_path is None:
15
- workspace_path = params["workspacePath"]
16
- tool_base_path = os.path.join(workspace_path, "User/Local/tool")
17
- module_path = os.path.join(tool_base_path, tool_id)
18
- module_path = os.path.normpath(os.path.abspath(module_path))
19
-
20
- if not os.path.exists(module_path):
21
- print(f"Tool {tool_id} not found")
22
- return []
23
-
24
- try:
25
- with ModuleManager(module_path) as manager:
26
- module = importlib.import_module("tool")
27
- export_tools = getattr(module, "export_tools")
28
- valid_tools = []
29
- for tool in export_tools:
30
- assert isinstance(
31
- tool, langchain_core.tools.StructuredTool
32
- ) or isinstance(
33
- tool, types.FunctionType
34
- ), f"Tool is not a StructuredTool or function: {tool}"
35
- if not isinstance(tool, langchain_core.tools.StructuredTool):
36
- tool = to_agent_tool(tool)
37
- valid_tools.append(tool)
38
- export_tools = valid_tools
39
-
40
- except Exception as e:
41
- print(f"Error loading tool {tool_id}: {e}")
42
- return []
43
-
44
- for tool in export_tools:
45
- tool.func = wrapped_func(tool, module_path)
46
- if tool.description is None:
47
- tool.description = "This tool is used to " + tool.name + "."
48
-
49
- return export_tools if as_agent_tool else [tool.func for tool in export_tools]
@@ -1,59 +0,0 @@
1
- import os
2
- import importlib
3
- from langchain.agents import tool as to_agent_tool
4
- import types
5
- import langchain_core
6
- from .lib import ModuleManager, wrapped_func
7
- from pycoze import utils
8
-
9
-
10
- params = utils.params
11
-
12
-
13
- def _ref_workflows(workflow_id, as_agent_tool=False, workspace_path=None):
14
- if workspace_path is None:
15
- workspace_path = params["workspacePath"]
16
- tool_base_path = os.path.join(workspace_path, "User/Local/workflow")
17
- module_path = os.path.join(tool_base_path, workflow_id)
18
- module_path = os.path.normpath(os.path.abspath(module_path))
19
-
20
- if not os.path.exists(module_path):
21
- print(f"Workflow {workflow_id} not found")
22
- return []
23
-
24
- try:
25
- with ModuleManager(module_path) as manager:
26
- module = importlib.import_module("tool")
27
- export_tools = getattr(module, "export_tools")
28
- valid_tools = []
29
- for tool in export_tools:
30
- assert isinstance(
31
- tool, langchain_core.tools.StructuredTool
32
- ) or isinstance(
33
- tool, types.FunctionType
34
- ), f"Tool is not a StructuredTool or function: {tool}"
35
- if not isinstance(tool, langchain_core.tools.StructuredTool):
36
- tool = to_agent_tool(tool)
37
- valid_tools.append(tool)
38
- export_tools = valid_tools
39
-
40
- except Exception as e:
41
- print(f"Error loading workflow {workflow_id}: {e}")
42
- return []
43
-
44
- for tool in export_tools:
45
- tool.func = wrapped_func(tool, module_path)
46
- if tool.description is None:
47
- tool.description = "This tool is used to " + tool.name + "."
48
-
49
- return export_tools if as_agent_tool else [tool.func for tool in export_tools]
50
-
51
-
52
- def ref_workflow(workflow_id, as_agent_tool=False, workspace_path=None):
53
- tools = _ref_workflows(
54
- workflow_id, as_agent_tool=as_agent_tool, workspace_path=workspace_path
55
- )
56
- if len(tools) > 0:
57
- return tools[0]
58
- else:
59
- return None
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