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.
- pycoze/bot/agent/agent_types/openai_func_call_agent.py +5 -9
- pycoze/bot/agent/chat.py +2 -2
- pycoze/reference/bot.py +61 -64
- pycoze/reference/tool.py +5 -3
- pycoze/reference/workflow.py +59 -56
- {pycoze-0.1.284.dist-info → pycoze-0.1.286.dist-info}/METADATA +9 -7
- {pycoze-0.1.284.dist-info → pycoze-0.1.286.dist-info}/RECORD +10 -10
- {pycoze-0.1.284.dist-info → pycoze-0.1.286.dist-info}/WHEEL +1 -1
- {pycoze-0.1.284.dist-info → pycoze-0.1.286.dist-info}/LICENSE +0 -0
- {pycoze-0.1.284.dist-info → pycoze-0.1.286.dist-info}/top_level.txt +0 -0
@@ -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
|
111
|
-
return
|
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
|
2
|
-
import
|
3
|
-
import
|
4
|
-
|
5
|
-
import
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
tool
|
59
|
-
|
60
|
-
|
61
|
-
|
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
|
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(
|
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):
|
pycoze/reference/workflow.py
CHANGED
@@ -1,56 +1,59 @@
|
|
1
|
-
import
|
2
|
-
import
|
3
|
-
import
|
4
|
-
|
5
|
-
import
|
6
|
-
import
|
7
|
-
from
|
8
|
-
|
9
|
-
|
10
|
-
|
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,
|
32
|
-
)
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
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
|
+
Metadata-Version: 2.2
|
2
2
|
Name: pycoze
|
3
|
-
Version: 0.1.
|
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=
|
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=
|
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=
|
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=
|
27
|
-
pycoze/reference/workflow.py,sha256=
|
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.
|
39
|
-
pycoze-0.1.
|
40
|
-
pycoze-0.1.
|
41
|
-
pycoze-0.1.
|
42
|
-
pycoze-0.1.
|
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,,
|
File without changes
|
File without changes
|