pycoze 0.1.285__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/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.285
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
-
@@ -19,12 +19,12 @@ pycoze/bot/agent/assistant.py,sha256=5LIgPIVVzx6uIOWT5S_XDDyPPjPHRBBNpIU3GiOkVHc
19
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
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.285.dist-info/LICENSE,sha256=QStd_Qsd0-kAam_-sOesCIp_uKrGWeoKwt9M49NVkNU,1090
39
- pycoze-0.1.285.dist-info/METADATA,sha256=Qb3Dk-FsO1-K9xMul-gH7ds6KoH56qCjAH2RpUJPNqY,755
40
- pycoze-0.1.285.dist-info/WHEEL,sha256=ewwEueio1C2XeHTvT17n8dZUJgOvyCWCt0WVNLClP9o,92
41
- pycoze-0.1.285.dist-info/top_level.txt,sha256=76dPeDhKvOCleL3ZC5gl1-y4vdS1tT_U1hxWVAn7sFo,7
42
- pycoze-0.1.285.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