pycoze 0.1.130__py3-none-any.whl → 0.1.132__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- pycoze/access/bot_for_bot.py +1 -0
- pycoze/access/lib.py +1 -1
- pycoze/bot/agent/agent.py +6 -6
- pycoze/bot/agent/agent_types/__init__.py +2 -2
- pycoze/bot/agent/agent_types/const.py +1 -0
- pycoze/bot/agent/agent_types/openai_func_call_agent.py +2 -5
- pycoze/bot/agent/assistant.py +35 -35
- pycoze/bot/bot.py +3 -3
- {pycoze-0.1.130.dist-info → pycoze-0.1.132.dist-info}/METADATA +1 -1
- {pycoze-0.1.130.dist-info → pycoze-0.1.132.dist-info}/RECORD +13 -12
- {pycoze-0.1.130.dist-info → pycoze-0.1.132.dist-info}/LICENSE +0 -0
- {pycoze-0.1.130.dist-info → pycoze-0.1.132.dist-info}/WHEEL +0 -0
- {pycoze-0.1.130.dist-info → pycoze-0.1.132.dist-info}/top_level.txt +0 -0
pycoze/access/bot_for_bot.py
CHANGED
@@ -45,6 +45,7 @@ def {random_name}(command:str) -> str:
|
|
45
45
|
with tempfile.NamedTemporaryFile(delete=True, mode='w+t') as temp_file:
|
46
46
|
sys.stdout = temp_file # 将输出重定向到临时文件,防止影响AI结果
|
47
47
|
result = bot.get_chat_response("botSetting.json", command)
|
48
|
+
sys.stdout = sys.__stdout__ # 恢复标准输出
|
48
49
|
return result
|
49
50
|
"""
|
50
51
|
exec(function_code)
|
pycoze/access/lib.py
CHANGED
pycoze/bot/agent/agent.py
CHANGED
@@ -10,9 +10,10 @@ from langchain_core.messages import (
|
|
10
10
|
SystemMessage,
|
11
11
|
)
|
12
12
|
from langchain_core.agents import AgentFinish
|
13
|
+
from .agent_types.const import HumanToolString
|
13
14
|
|
14
15
|
|
15
|
-
async def run_agent(agent, inputs: list):
|
16
|
+
async def run_agent(agent, inputs: list, tool_compatibility_mode:bool):
|
16
17
|
exist_ids = set()
|
17
18
|
content_list = []
|
18
19
|
async for event in agent.astream_events(inputs, version="v2"):
|
@@ -27,10 +28,9 @@ async def run_agent(agent, inputs: list):
|
|
27
28
|
):
|
28
29
|
input_list = event["data"]["input"]
|
29
30
|
for msg in input_list:
|
30
|
-
if isinstance(msg, HumanMessage) or isinstance(
|
31
|
-
msg
|
32
|
-
|
33
|
-
content_list = []
|
31
|
+
if isinstance(msg, HumanMessage) or isinstance(msg, SystemMessage):
|
32
|
+
if not tool_compatibility_mode or not msg.content.startswith(HumanToolString):
|
33
|
+
content_list = [] # 防止内容重复
|
34
34
|
if isinstance(msg, AIMessage) and not isinstance(
|
35
35
|
msg, AIMessageChunk
|
36
36
|
):
|
@@ -87,4 +87,4 @@ if __name__ == "__main__":
|
|
87
87
|
)
|
88
88
|
|
89
89
|
inputs = [HumanMessage(content="计算根号7+根号88")]
|
90
|
-
print(asyncio.run(run_agent(agent, inputs)))
|
90
|
+
print(asyncio.run(run_agent(agent, inputs, True)))
|
@@ -0,0 +1 @@
|
|
1
|
+
HumanToolString = 'The tool call is done, the result is as follows:\n'
|
@@ -11,7 +11,7 @@ from langgraph.prebuilt import ToolExecutor, ToolInvocation
|
|
11
11
|
import re
|
12
12
|
import json
|
13
13
|
import random
|
14
|
-
|
14
|
+
from .const import HumanToolString
|
15
15
|
|
16
16
|
def get_all_markdown_json(content):
|
17
17
|
# Find all markdown json blocks
|
@@ -160,10 +160,7 @@ def create_openai_func_call_agent_executor(
|
|
160
160
|
# HumanMessage
|
161
161
|
tool_msgs_str = repr(tool_messages)
|
162
162
|
tool_messages = [
|
163
|
-
HumanMessage(
|
164
|
-
content="The tool call is done, the result is as follows:\n"
|
165
|
-
+ tool_msgs_str
|
166
|
-
)
|
163
|
+
HumanMessage(content=HumanToolString + tool_msgs_str)
|
167
164
|
]
|
168
165
|
return tool_messages
|
169
166
|
|
pycoze/bot/agent/assistant.py
CHANGED
@@ -1,35 +1,35 @@
|
|
1
|
-
from typing import Sequence
|
2
|
-
from langchain.tools import BaseTool
|
3
|
-
from langchain_core.language_models.base import LanguageModelLike
|
4
|
-
from langchain_core.runnables import RunnableBinding
|
5
|
-
from .agent_types import create_openai_func_call_agent_executor
|
6
|
-
|
7
|
-
|
8
|
-
class Runnable(RunnableBinding):
|
9
|
-
agent_execution_mode: str
|
10
|
-
tools: Sequence[BaseTool]
|
11
|
-
llm: LanguageModelLike
|
12
|
-
assistant_message: str
|
13
|
-
|
14
|
-
def __init__(
|
15
|
-
self,
|
16
|
-
*,
|
17
|
-
agent_execution_mode: str,
|
18
|
-
tools: Sequence[BaseTool],
|
19
|
-
llm: LanguageModelLike,
|
20
|
-
assistant_message: str,
|
21
|
-
tool_compatibility_mode: bool
|
22
|
-
) -> None:
|
23
|
-
|
24
|
-
agent_executor = create_openai_func_call_agent_executor(
|
25
|
-
tools, llm, assistant_message, tool_compatibility_mode
|
26
|
-
)
|
27
|
-
agent_executor = agent_executor.with_config({"recursion_limit": 50})
|
28
|
-
super().__init__(
|
29
|
-
tools=tools,
|
30
|
-
llm=llm,
|
31
|
-
agent_execution_mode=agent_execution_mode,
|
32
|
-
assistant_message=assistant_message,
|
33
|
-
bound=agent_executor,
|
34
|
-
return_intermediate_steps=True,
|
35
|
-
)
|
1
|
+
from typing import Sequence
|
2
|
+
from langchain.tools import BaseTool
|
3
|
+
from langchain_core.language_models.base import LanguageModelLike
|
4
|
+
from langchain_core.runnables import RunnableBinding
|
5
|
+
from .agent_types import create_openai_func_call_agent_executor
|
6
|
+
|
7
|
+
|
8
|
+
class Runnable(RunnableBinding):
|
9
|
+
agent_execution_mode: str
|
10
|
+
tools: Sequence[BaseTool]
|
11
|
+
llm: LanguageModelLike
|
12
|
+
assistant_message: str
|
13
|
+
|
14
|
+
def __init__(
|
15
|
+
self,
|
16
|
+
*,
|
17
|
+
agent_execution_mode: str,
|
18
|
+
tools: Sequence[BaseTool],
|
19
|
+
llm: LanguageModelLike,
|
20
|
+
assistant_message: str,
|
21
|
+
tool_compatibility_mode: bool
|
22
|
+
) -> None:
|
23
|
+
|
24
|
+
agent_executor = create_openai_func_call_agent_executor(
|
25
|
+
tools, llm, assistant_message, tool_compatibility_mode
|
26
|
+
)
|
27
|
+
agent_executor = agent_executor.with_config({"recursion_limit": 50})
|
28
|
+
super().__init__(
|
29
|
+
tools=tools,
|
30
|
+
llm=llm,
|
31
|
+
agent_execution_mode=agent_execution_mode,
|
32
|
+
assistant_message=assistant_message,
|
33
|
+
bound=agent_executor,
|
34
|
+
return_intermediate_steps=True,
|
35
|
+
)
|
pycoze/bot/bot.py
CHANGED
@@ -53,8 +53,8 @@ def agent_chat(bot_setting_file, history):
|
|
53
53
|
)
|
54
54
|
prompt = role_setting["prompt"]
|
55
55
|
if (
|
56
|
-
cfg["model"].startswith("deepseek")
|
57
|
-
or cfg["toolCompatibilityMode"]
|
56
|
+
(cfg["model"].startswith("deepseek")
|
57
|
+
or cfg["toolCompatibilityMode"])
|
58
58
|
and len(abilities) > 0
|
59
59
|
):
|
60
60
|
prompt += """
|
@@ -76,7 +76,7 @@ def agent_chat(bot_setting_file, history):
|
|
76
76
|
assistant_message=prompt,
|
77
77
|
tool_compatibility_mode=cfg["toolCompatibilityMode"],
|
78
78
|
)
|
79
|
-
return asyncio.run(run_agent(agent, history))
|
79
|
+
return asyncio.run(run_agent(agent, history, cfg["toolCompatibilityMode"]))
|
80
80
|
|
81
81
|
|
82
82
|
def chat(bot_setting_file: str):
|
@@ -1,19 +1,20 @@
|
|
1
1
|
pycoze/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
2
|
pycoze/module.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
3
3
|
pycoze/access/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
4
|
-
pycoze/access/bot_for_bot.py,sha256=
|
5
|
-
pycoze/access/lib.py,sha256=
|
4
|
+
pycoze/access/bot_for_bot.py,sha256=2F-l2O6S94jL8Jpn83y_rUxs-22uxSQgrSd0-9wdmts,2029
|
5
|
+
pycoze/access/lib.py,sha256=sp3PqvsyE3OjSqgnykyaz_JARwelMGq44NQUU1x7IV4,2045
|
6
6
|
pycoze/access/tool_for_bot.py,sha256=mAx3dPbZpU_FWlK6uxoWqHbduuNM_EQU8kBmzEKkccE,1339
|
7
7
|
pycoze/ai/__init__.py,sha256=odM2lgYSnApxw4AzLV_5AyaxL5_MLfydOSB1VmLGFyA,75
|
8
8
|
pycoze/ai/vram_reserve.py,sha256=QbqaA8qv87cnEpOVDMygi0BNMxuhLYwj1UKfR_D5BD4,4340
|
9
9
|
pycoze/bot/__init__.py,sha256=6HHMxDQVOyZM9dtSjQm9tjGnhj4h7CixD0JOvEwTi48,41
|
10
|
-
pycoze/bot/bot.py,sha256=
|
10
|
+
pycoze/bot/bot.py,sha256=VHBSIq1t11QIL6lVEWxhg89Dq9v04JiZNMHzsGbBmgc,3386
|
11
11
|
pycoze/bot/agent/__init__.py,sha256=YR9vpkEQn1e4937r_xFPJXUCPBEJ0SFzEQDBe2x3-YA,157
|
12
|
-
pycoze/bot/agent/agent.py,sha256=
|
13
|
-
pycoze/bot/agent/assistant.py,sha256=
|
12
|
+
pycoze/bot/agent/agent.py,sha256=Aue8nWeW_I7e1jo4o7cUjFFjrsV9NtVUiTX3EQYHmbA,3507
|
13
|
+
pycoze/bot/agent/assistant.py,sha256=3iLxnRvf_ia0cP-FHK5Fv4ylltlnzPq1KscRCFYqjkc,1147
|
14
14
|
pycoze/bot/agent/chat.py,sha256=kc0qgcrBSXdiMy49JwThZTV-0PAvzAhiUvbI5ILiSnU,571
|
15
|
-
pycoze/bot/agent/agent_types/__init__.py,sha256=
|
16
|
-
pycoze/bot/agent/agent_types/
|
15
|
+
pycoze/bot/agent/agent_types/__init__.py,sha256=zmU2Kmrv5mCdfg-QlPn2H6pWxbGeq8s7YTqLhpzJC6k,179
|
16
|
+
pycoze/bot/agent/agent_types/const.py,sha256=BfUKPrhAHREoMLHuFNG2bCIEkC1-f7K0LEqNg4RwiRE,70
|
17
|
+
pycoze/bot/agent/agent_types/openai_func_call_agent.py,sha256=SnEm5MODHn2uMsaMNqgzULM_91vqLHC0TU6ovwCOqLU,6675
|
17
18
|
pycoze/ui/__init__.py,sha256=7xAfL2lfG7-jllPJEZUJO89xUE9sNzvo1y0WmBswjBI,458
|
18
19
|
pycoze/ui/base.py,sha256=SCXVDK7PpMaBv6ovvabHcfRq_d2AWM0BRyxpNhuJN5A,1285
|
19
20
|
pycoze/ui/color.py,sha256=cT9Ib8uNzkOKxyW0IwVj46o4LwdB1xgNCj1_Rou9d_4,854
|
@@ -22,8 +23,8 @@ pycoze/ui/ui_def.py,sha256=UhhU_yB3GV9ISbvTWT48hsHPHI250BhMILh6bu5Uioo,4206
|
|
22
23
|
pycoze/utils/__init__.py,sha256=TNJhFfY7JYdLlzuP9GvgxfNXUtbgH_NUUJSqHXCxJn4,78
|
23
24
|
pycoze/utils/arg.py,sha256=kA3KBQzXc2WlH5XbF8kfikfpqljiKaW7oY_GE4Qyffc,753
|
24
25
|
pycoze/utils/text_or_file.py,sha256=gpxZVWt2DW6YiEg_MnMuwg36VNf3TX383QD_1oZNB0Y,551
|
25
|
-
pycoze-0.1.
|
26
|
-
pycoze-0.1.
|
27
|
-
pycoze-0.1.
|
28
|
-
pycoze-0.1.
|
29
|
-
pycoze-0.1.
|
26
|
+
pycoze-0.1.132.dist-info/LICENSE,sha256=QStd_Qsd0-kAam_-sOesCIp_uKrGWeoKwt9M49NVkNU,1090
|
27
|
+
pycoze-0.1.132.dist-info/METADATA,sha256=lDMJbKNm4FOf53-HAhXXtbBDoG32DUpI22ZYyKKi_dQ,726
|
28
|
+
pycoze-0.1.132.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
|
29
|
+
pycoze-0.1.132.dist-info/top_level.txt,sha256=76dPeDhKvOCleL3ZC5gl1-y4vdS1tT_U1hxWVAn7sFo,7
|
30
|
+
pycoze-0.1.132.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|