pycoze 0.1.284__py3-none-any.whl → 0.1.286__py3-none-any.whl

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.
@@ -1,6 +1,5 @@
1
1
  # reference:https://github.com/maxtheman/opengpts/blob/d3425b1ba80aec48953a327ecd9a61b80efb0e69/backend/app/agent_types/openai_agent.py
2
2
  import json
3
-
4
3
  from langchain.tools import BaseTool
5
4
  from langchain_core.utils.function_calling import convert_to_openai_tool
6
5
  from langchain_core.language_models.base import LanguageModelLike
@@ -13,6 +12,7 @@ import json
13
12
  import random
14
13
  from .const import HumanToolString
15
14
 
15
+
16
16
  def get_all_markdown_json(content):
17
17
  # Find all markdown json blocks
18
18
  markdown_json_blocks = re.findall(r"```json(.*?)```", content, re.DOTALL)
@@ -107,8 +107,8 @@ def create_openai_func_call_agent_executor(
107
107
  last_message.content = last_message.content + "\n\n" # 避免影响阅读
108
108
  tools = get_tools(last_message)
109
109
  if last_message.tool_calls or tools:
110
- return 'continue'
111
- return 'end'
110
+ return "continue"
111
+ return "end"
112
112
 
113
113
  # Define the function to execute tools
114
114
  async def call_tool(messages):
@@ -140,9 +140,7 @@ def create_openai_func_call_agent_executor(
140
140
  responses = await tool_executor.abatch(actions, **kwargs)
141
141
  # We use the response to create a ToolMessage
142
142
  tool_messages = []
143
- for tool_call, response in zip(
144
- get_tools(last_message), responses
145
- ):
143
+ for tool_call, response in zip(get_tools(last_message), responses):
146
144
  if not isinstance(response, (str, int, float, bool, list, tuple)):
147
145
  response = repr(
148
146
  response
@@ -157,9 +155,7 @@ def create_openai_func_call_agent_executor(
157
155
  if tool_compatibility_mode:
158
156
  # HumanMessage
159
157
  tool_msgs_str = repr(tool_messages)
160
- tool_messages = [
161
- HumanMessage(content=HumanToolString + tool_msgs_str)
162
- ]
158
+ tool_messages = [HumanMessage(content=HumanToolString + tool_msgs_str)]
163
159
  return tool_messages
164
160
 
165
161
  workflow = MessageGraph()
pycoze/bot/agent/chat.py CHANGED
@@ -1,5 +1,4 @@
1
1
  import json
2
- from langchain_core.messages import AIMessage
3
2
 
4
3
 
5
4
  INPUT_MESSAGE = "INPUT_MESSAGE=>"
@@ -9,7 +8,7 @@ _INFOMATION_MESSAGE = "INFOMATION_MESSAGE=>"
9
8
  _LOG = "LOG=>"
10
9
 
11
10
 
12
- CHAT_DATA = {"output":"", "info": ""}
11
+ CHAT_DATA = {"output": "", "info": ""}
13
12
 
14
13
 
15
14
  def log(content, *args, end="\n", **kwargs):
@@ -27,6 +26,7 @@ def output(role, content):
27
26
  CHAT_DATA["output"] = content
28
27
  print(_OUTPUT_MESSAGE + json.dumps({"role": role, "content": content}))
29
28
 
29
+
30
30
  def info(role, content):
31
31
  CHAT_DATA["info"] += content
32
32
  print(_INFOMATION_MESSAGE + json.dumps({"role": role, "content": content}))
pycoze/reference/bot.py CHANGED
@@ -1,64 +1,61 @@
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
- import json
9
- from pycoze import utils
10
-
11
- bot_index = 0
12
-
13
- params = utils.params
14
-
15
- def ref_bot(bot_id, as_agent_tool=False, workspace_path=None):
16
- global bot_index
17
- if workspace_path is None:
18
- workspace_path = params["workspacePath"]
19
- tool_base_path = os.path.join(workspace_path, "User/Local/bot")
20
- module_path = os.path.join(tool_base_path, bot_id)
21
- module_path = os.path.normpath(os.path.abspath(module_path))
22
-
23
- if not os.path.exists(module_path):
24
- print(f"Bot {bot_id} not found in:"+ module_path)
25
- return None
26
-
27
- try:
28
- with ModuleManager(module_path) as manager:
29
- info = module_path + "/info.json"
30
- with open(info, "r", encoding="utf-8") as f:
31
- info = json.load(f)
32
- name = info["name"]
33
- random_name = "bot_" + str(bot_index)
34
- bot_index += 1
35
- function_code = f"""
36
- def {random_name}(command:str) -> str:
37
- \"\"\"接收任意指令字符串,并返回AI角色({name}专家)深入思考和执行指令后的字符串结果。
38
- AI角色({name}专家)擅长使用各种工具,并会给出专业且更为准确的结果。
39
-
40
- Args:
41
- command (str): AI角色({name}专家)需要执行的指令字符串。
42
-
43
- Returns:
44
- str: AI角色({name}专家)执行指令后的结果。
45
- \"\"\"
46
- from pycoze import bot
47
- from pycoze import utils
48
- import tempfile
49
-
50
- with tempfile.NamedTemporaryFile(delete=True, mode='w+t') as temp_file:
51
- sys.stdout = temp_file # 将输出重定向到临时文件,防止影响AI结果
52
- result = bot.get_chat_response("botSetting.json", command)
53
- sys.stdout = sys.__stdout__ # 恢复标准输出
54
- return result
55
- """
56
- exec(function_code)
57
- tool = to_agent_tool(eval(random_name))
58
- tool.func = wrapped_func(tool, module_path)
59
- if tool.description is None:
60
- tool.description = "This tool is used to " + tool.name + "."
61
- return tool if as_agent_tool else tool.func
62
- except Exception as e:
63
- print(f"Error loading bot {bot_id}: {e}")
64
- return None
1
+ import os
2
+ from langchain.agents import tool as to_agent_tool
3
+ from .lib import ModuleManager, wrapped_func
4
+ import json
5
+ from pycoze import utils
6
+
7
+ bot_index = 0
8
+
9
+ params = utils.params
10
+
11
+
12
+ def ref_bot(bot_id, as_agent_tool=False, workspace_path=None):
13
+ global bot_index
14
+ if workspace_path is None:
15
+ workspace_path = params["workspacePath"]
16
+ tool_base_path = os.path.join(workspace_path, "User/Local/bot")
17
+ module_path = os.path.join(tool_base_path, bot_id)
18
+ module_path = os.path.normpath(os.path.abspath(module_path))
19
+
20
+ if not os.path.exists(module_path):
21
+ print(f"Bot {bot_id} not found in:" + module_path)
22
+ return None
23
+
24
+ try:
25
+ with ModuleManager(module_path) as manager:
26
+ info = module_path + "/info.json"
27
+ with open(info, "r", encoding="utf-8") as f:
28
+ info = json.load(f)
29
+ name = info["name"]
30
+ random_name = "bot_" + str(bot_index)
31
+ bot_index += 1
32
+ function_code = f"""
33
+ def {random_name}(command:str) -> str:
34
+ \"\"\"接收任意指令字符串,并返回AI角色({name}专家)深入思考和执行指令后的字符串结果。
35
+ AI角色({name}专家)擅长使用各种工具,并会给出专业且更为准确的结果。
36
+
37
+ Args:
38
+ command (str): AI角色({name}专家)需要执行的指令字符串。
39
+
40
+ Returns:
41
+ str: AI角色({name}专家)执行指令后的结果。
42
+ \"\"\"
43
+ from pycoze import bot
44
+ from pycoze import utils
45
+ import tempfile
46
+
47
+ with tempfile.NamedTemporaryFile(delete=True, mode='w+t') as temp_file:
48
+ sys.stdout = temp_file # 将输出重定向到临时文件,防止影响AI结果
49
+ result = bot.get_chat_response("botSetting.json", command)
50
+ sys.stdout = sys.__stdout__ # 恢复标准输出
51
+ return result
52
+ """
53
+ 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
59
+ except Exception as e:
60
+ print(f"Error loading bot {bot_id}: {e}")
61
+ return None
pycoze/reference/tool.py CHANGED
@@ -1,15 +1,15 @@
1
- import sys
2
1
  import os
3
2
  import importlib
4
3
  from langchain.agents import tool as to_agent_tool
5
4
  import types
6
5
  import langchain_core
7
- from .lib import ChangeDirectoryAndPath, ModuleManager, wrapped_func
6
+ from .lib import ModuleManager, wrapped_func
8
7
  from pycoze import utils
9
8
 
10
9
 
11
10
  params = utils.params
12
11
 
12
+
13
13
  def ref_tools(tool_id, as_agent_tool=False, workspace_path=None):
14
14
  if workspace_path is None:
15
15
  workspace_path = params["workspacePath"]
@@ -27,7 +27,9 @@ def ref_tools(tool_id, as_agent_tool=False, workspace_path=None):
27
27
  export_tools = getattr(module, "export_tools")
28
28
  valid_tools = []
29
29
  for tool in export_tools:
30
- assert isinstance(tool, langchain_core.tools.StructuredTool) or isinstance(
30
+ assert isinstance(
31
+ tool, langchain_core.tools.StructuredTool
32
+ ) or isinstance(
31
33
  tool, types.FunctionType
32
34
  ), f"Tool is not a StructuredTool or function: {tool}"
33
35
  if not isinstance(tool, langchain_core.tools.StructuredTool):
@@ -1,56 +1,59 @@
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 ModuleManager, wrapped_func
8
- from pycoze import utils
9
-
10
-
11
- params = utils.params
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(tool, langchain_core.tools.StructuredTool) or isinstance(
31
- tool, types.FunctionType
32
- ), f"Tool is not a StructuredTool or function: {tool}"
33
- if not isinstance(tool, langchain_core.tools.StructuredTool):
34
- tool = to_agent_tool(tool)
35
- valid_tools.append(tool)
36
- export_tools = valid_tools
37
-
38
- except Exception as e:
39
- print(f"Error loading workflow {workflow_id}: {e}")
40
- return []
41
-
42
- for tool in export_tools:
43
- tool.func = wrapped_func(tool, module_path)
44
- if tool.description is None:
45
- tool.description = "This tool is used to " + tool.name + "."
46
-
47
- return export_tools if as_agent_tool else [tool.func for tool in export_tools]
48
-
49
-
50
- def ref_workflow(workflow_id, as_agent_tool=False, workspace_path=None):
51
- tools = _ref_workflows(workflow_id, as_agent_tool=as_agent_tool, workspace_path=workspace_path)
52
- if len(tools) > 0:
53
- return tools[0]
54
- else:
55
- return None
56
-
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
@@ -1,18 +1,22 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: pycoze
3
- Version: 0.1.284
3
+ Version: 0.1.286
4
4
  Summary: Package for pycoze only!
5
- Home-page: UNKNOWN
6
5
  Author: Yuan Jie Xiong
7
6
  Author-email: aiqqqqqqq@qq.com
8
- License: UNKNOWN
9
- Platform: UNKNOWN
10
7
  Classifier: Programming Language :: Python :: 3
11
8
  Classifier: License :: OSI Approved :: MIT License
12
9
  Classifier: Operating System :: OS Independent
13
10
  Requires-Python: >=3.6
14
11
  Description-Content-Type: text/markdown
15
12
  License-File: LICENSE
13
+ Dynamic: author
14
+ Dynamic: author-email
15
+ Dynamic: classifier
16
+ Dynamic: description
17
+ Dynamic: description-content-type
18
+ Dynamic: requires-python
19
+ Dynamic: summary
16
20
 
17
21
  # PYCOZE
18
22
 
@@ -28,5 +32,3 @@ Package for pycoze only!
28
32
  <!-- python setup.py sdist bdist_wheel -->
29
33
  <!-- twine upload dist/* -->
30
34
  <!-- 修改src\renderer\layout\init\const.ts中的库版本要求 -->
31
-
32
-
@@ -16,15 +16,15 @@ pycoze/bot/bot.py,sha256=_qmUTZ09FmRLifHrW5stDZWGVK6yuMEMBC3fmeYJnqk,844
16
16
  pycoze/bot/agent/__init__.py,sha256=3wE8_FFQS8j2BY-g9Cr-onV0POEvDRZaw_NCzpqrNus,265
17
17
  pycoze/bot/agent/agent.py,sha256=qkLIRgSMNT1VD_UD0e6kYUuOTOqylQiYSCay6HZ12LA,3653
18
18
  pycoze/bot/agent/assistant.py,sha256=5LIgPIVVzx6uIOWT5S_XDDyPPjPHRBBNpIU3GiOkVHc,1186
19
- pycoze/bot/agent/chat.py,sha256=mubOCAHvA6VtyE6N40elI6KrP6A69uB_G6ihE3G_Vi4,860
19
+ pycoze/bot/agent/chat.py,sha256=9wZ24CPdSbSnPCWmCQJle05U5VlDGgZhZ9z1mezLst0,816
20
20
  pycoze/bot/agent/agent_types/__init__.py,sha256=zmU2Kmrv5mCdfg-QlPn2H6pWxbGeq8s7YTqLhpzJC6k,179
21
21
  pycoze/bot/agent/agent_types/const.py,sha256=BfUKPrhAHREoMLHuFNG2bCIEkC1-f7K0LEqNg4RwiRE,70
22
- pycoze/bot/agent/agent_types/openai_func_call_agent.py,sha256=6aKnUQDINyUaCW24oa9Qjkm5w3ctZ6lxAgcE4m9YHwE,6701
22
+ pycoze/bot/agent/agent_types/openai_func_call_agent.py,sha256=3qOyrddujtJ50W9SbH5bapbVTwjgE_LC2TnYJWUH9yc,6649
23
23
  pycoze/reference/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
24
- pycoze/reference/bot.py,sha256=EQUngYFn5K7DdQWsPHKOXOsrMAz-3nMjiZEPc3yHfvo,2415
24
+ pycoze/reference/bot.py,sha256=d5uB0OH1MF3LXGoBAF6vX6y50IV3sOrNi_5hXAHAmGU,2255
25
25
  pycoze/reference/lib.py,sha256=0xQJTLTHedGzQBsjuTFNBVqYc4-8Yl65gGCrAhWyOX8,2155
26
- pycoze/reference/tool.py,sha256=CYUS95M_XGnUcl4uWayjzKOM9jGpylS7vWJ66JfNTjI,1710
27
- pycoze/reference/workflow.py,sha256=LiubvvhGa6KoVIP8W8D8zTZaL595M4Dorsa_kxZ8UgQ,2028
26
+ pycoze/reference/tool.py,sha256=_dggSWn-oC_reB8TuNOPl48Xr-pgwJHF7XmzlIw6lsQ,1714
27
+ pycoze/reference/workflow.py,sha256=22y8yyJgBMcGShBbqKpUGFl2CM9dh646LsM8r-1UKcs,2013
28
28
  pycoze/ui/__init__.py,sha256=uaXet23wUk64TcZjpBX8qOx4aUhwA_ucrmcxy7Q4Qr4,929
29
29
  pycoze/ui/base.py,sha256=bz9mHZwIXA8LErEHTIonH347u6LP7rxV2EADMMjNZos,1081
30
30
  pycoze/ui/color.py,sha256=cT9Ib8uNzkOKxyW0IwVj46o4LwdB1xgNCj1_Rou9d_4,854
@@ -35,8 +35,8 @@ pycoze/utils/arg.py,sha256=jop1tBfe5hYkHW1NSpCeaZBEznkgguBscj_7M2dWfrs,503
35
35
  pycoze/utils/env.py,sha256=5pWlXfM1F5ZU9hhv1rHlDEanjEW5wf0nbyez9bNRqqA,559
36
36
  pycoze/utils/socket.py,sha256=bZbFFRH4mfThzRqt55BAAGQ6eICx_ja4x8UGGrUdAm8,2428
37
37
  pycoze/utils/text_or_file.py,sha256=gpxZVWt2DW6YiEg_MnMuwg36VNf3TX383QD_1oZNB0Y,551
38
- pycoze-0.1.284.dist-info/LICENSE,sha256=QStd_Qsd0-kAam_-sOesCIp_uKrGWeoKwt9M49NVkNU,1090
39
- pycoze-0.1.284.dist-info/METADATA,sha256=7NRzJB0uGt2arHh5jYvBXhcspsqvN7RQmLtr7BUsaa4,755
40
- pycoze-0.1.284.dist-info/WHEEL,sha256=ewwEueio1C2XeHTvT17n8dZUJgOvyCWCt0WVNLClP9o,92
41
- pycoze-0.1.284.dist-info/top_level.txt,sha256=76dPeDhKvOCleL3ZC5gl1-y4vdS1tT_U1hxWVAn7sFo,7
42
- pycoze-0.1.284.dist-info/RECORD,,
38
+ pycoze-0.1.286.dist-info/LICENSE,sha256=QStd_Qsd0-kAam_-sOesCIp_uKrGWeoKwt9M49NVkNU,1090
39
+ pycoze-0.1.286.dist-info/METADATA,sha256=CE7H9CpBdsQrmZo7FaGjGSQNBcOAO0rkp7BsVQ3ZCYU,854
40
+ pycoze-0.1.286.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
41
+ pycoze-0.1.286.dist-info/top_level.txt,sha256=76dPeDhKvOCleL3ZC5gl1-y4vdS1tT_U1hxWVAn7sFo,7
42
+ pycoze-0.1.286.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.37.0)
2
+ Generator: setuptools (75.8.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5