pycoze 0.1.234__py3-none-any.whl → 0.1.237__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.py +2 -3
- pycoze/bot/agent/agent_types/openai_func_call_agent.py +1 -7
- pycoze/bot/agent/assistant.py +1 -2
- pycoze/bot/agent_chat.py +7 -24
- pycoze/bot/bot.py +0 -1
- {pycoze-0.1.234.dist-info → pycoze-0.1.237.dist-info}/METADATA +1 -1
- {pycoze-0.1.234.dist-info → pycoze-0.1.237.dist-info}/RECORD +10 -10
- {pycoze-0.1.234.dist-info → pycoze-0.1.237.dist-info}/LICENSE +0 -0
- {pycoze-0.1.234.dist-info → pycoze-0.1.237.dist-info}/WHEEL +0 -0
- {pycoze-0.1.234.dist-info → pycoze-0.1.237.dist-info}/top_level.txt +0 -0
pycoze/bot/agent/agent.py
CHANGED
@@ -13,7 +13,7 @@ from langchain_core.agents import AgentFinish
|
|
13
13
|
from .agent_types.const import HumanToolString
|
14
14
|
|
15
15
|
|
16
|
-
async def run_agent(agent, inputs: list
|
16
|
+
async def run_agent(agent, inputs: list):
|
17
17
|
exist_ids = set()
|
18
18
|
content_list = []
|
19
19
|
async for event in agent.astream_events(inputs, version="v2"):
|
@@ -29,7 +29,7 @@ async def run_agent(agent, inputs: list, tool_compatibility_mode: bool):
|
|
29
29
|
input_list = event["data"]["input"]
|
30
30
|
for msg in input_list:
|
31
31
|
if isinstance(msg, HumanMessage) or isinstance(msg, SystemMessage):
|
32
|
-
if not
|
32
|
+
if not msg.content.startswith(HumanToolString):
|
33
33
|
content_list = [] # 防止内容重复
|
34
34
|
if isinstance(msg, AIMessage) and not isinstance(
|
35
35
|
msg, AIMessageChunk
|
@@ -84,7 +84,6 @@ if __name__ == "__main__":
|
|
84
84
|
tools=[python_tool],
|
85
85
|
llm=chat,
|
86
86
|
assistant_message="请以女友的口吻回答,输出不小于100字,可以随便说点其他的",
|
87
|
-
tool_compatibility_mode=False,
|
88
87
|
)
|
89
88
|
|
90
89
|
inputs = [HumanMessage(content="计算根号7+根号88")]
|
@@ -75,7 +75,6 @@ def create_openai_func_call_agent_executor(
|
|
75
75
|
tools: list[BaseTool],
|
76
76
|
llm: LanguageModelLike,
|
77
77
|
system_message: str,
|
78
|
-
tool_compatibility_mode: str,
|
79
78
|
**kwargs
|
80
79
|
):
|
81
80
|
|
@@ -156,12 +155,7 @@ def create_openai_func_call_agent_executor(
|
|
156
155
|
additional_kwargs={"name": tool_call["function"]["name"]},
|
157
156
|
)
|
158
157
|
tool_messages.append(message)
|
159
|
-
|
160
|
-
# HumanMessage
|
161
|
-
tool_msgs_str = repr(tool_messages)
|
162
|
-
tool_messages = [
|
163
|
-
HumanMessage(content=HumanToolString + tool_msgs_str)
|
164
|
-
]
|
158
|
+
|
165
159
|
return tool_messages
|
166
160
|
|
167
161
|
workflow = MessageGraph()
|
pycoze/bot/agent/assistant.py
CHANGED
@@ -18,11 +18,10 @@ class Runnable(RunnableBinding):
|
|
18
18
|
tools: Sequence[BaseTool],
|
19
19
|
llm: LanguageModelLike,
|
20
20
|
assistant_message: str,
|
21
|
-
tool_compatibility_mode: bool
|
22
21
|
) -> None:
|
23
22
|
|
24
23
|
agent_executor = create_openai_func_call_agent_executor(
|
25
|
-
tools, llm, assistant_message
|
24
|
+
tools, llm, assistant_message
|
26
25
|
)
|
27
26
|
agent_executor = agent_executor.with_config({"recursion_limit": 50})
|
28
27
|
super().__init__(
|
pycoze/bot/agent_chat.py
CHANGED
@@ -10,8 +10,6 @@ from langchain_core.utils.function_calling import convert_to_openai_tool
|
|
10
10
|
import os
|
11
11
|
|
12
12
|
cfg = utils.read_json_file("llm.json")
|
13
|
-
if cfg["model"].startswith("qwen-") or cfg["model"].startswith("deepseek"):
|
14
|
-
cfg["toolCompatibilityMode"] = False
|
15
13
|
|
16
14
|
|
17
15
|
def load_role_setting(bot_setting_file: str):
|
@@ -45,10 +43,10 @@ async def check_interrupt_file(interval, interrupt_file,agent_task):
|
|
45
43
|
agent_task.cancel()
|
46
44
|
break
|
47
45
|
|
48
|
-
async def run_with_interrupt_check(agent, history,
|
46
|
+
async def run_with_interrupt_check(agent, history, interrupt_file, check_interval=1):
|
49
47
|
clear_chat_data()
|
50
48
|
try:
|
51
|
-
agent_task = asyncio.create_task(run_agent(agent, history
|
49
|
+
agent_task = asyncio.create_task(run_agent(agent, history))
|
52
50
|
check_task = asyncio.create_task(check_interrupt_file(check_interval, interrupt_file, agent_task))
|
53
51
|
result = await agent_task
|
54
52
|
return result
|
@@ -59,6 +57,8 @@ async def run_with_interrupt_check(agent, history, tool_compatibility_mode, inte
|
|
59
57
|
print(traceback.format_exc())
|
60
58
|
return None # 返回 None 或者处理异常后的结果
|
61
59
|
finally:
|
60
|
+
if not agent_task.done():
|
61
|
+
agent_task.cancel()
|
62
62
|
# 确保即使发生异常也会取消检查任务
|
63
63
|
if not check_task.done():
|
64
64
|
check_task.cancel()
|
@@ -86,35 +86,18 @@ async def agent_chat(bot_setting_file, history):
|
|
86
86
|
], # 停用deepseek的工具调用标记,不然会虚构工具调用过程和结果
|
87
87
|
)
|
88
88
|
prompt = role_setting["prompt"]
|
89
|
-
|
90
|
-
(cfg["model"].startswith("deepseek")
|
91
|
-
or cfg["toolCompatibilityMode"])
|
92
|
-
and len(abilities) > 0
|
93
|
-
):
|
94
|
-
prompt += """
|
95
|
-
作为一个AI,你如果不确定结果,请务必使用工具查询。
|
96
|
-
你可以通过下面的方式使用工具,并耐心等待工具返回结果。
|
97
|
-
如果你需要调用工具,请使用以正确markdown中的json代码格式进行结尾(务必保证json格式正确,不要出现反斜杠未转义等问题):
|
98
|
-
```json
|
99
|
-
{"name": 函数名, "parameters": 参数词典}
|
100
|
-
```
|
101
|
-
"""
|
102
|
-
if cfg["model"].startswith("yi-"):
|
103
|
-
prompt += "\nAvailable functions:\n"
|
104
|
-
for t in abilities:
|
105
|
-
prompt += f"\n```json\n{json.dumps(convert_to_openai_tool(t))}\n```"
|
89
|
+
|
106
90
|
agent = Runnable(
|
107
91
|
agent_execution_mode="FuncCall",
|
108
92
|
tools=abilities,
|
109
93
|
llm=chat,
|
110
94
|
assistant_message=prompt,
|
111
|
-
tool_compatibility_mode=cfg["toolCompatibilityMode"],
|
112
95
|
)
|
113
96
|
params = utils.read_params_file()
|
114
97
|
if "interruptFile" in params:
|
115
98
|
interrupt_file_path = params["interruptFile"]
|
116
|
-
result = await run_with_interrupt_check(agent, history,
|
99
|
+
result = await run_with_interrupt_check(agent, history,interrupt_file_path)
|
117
100
|
else:
|
118
|
-
result = await run_agent(agent, history
|
101
|
+
result = await run_agent(agent, history)
|
119
102
|
return result
|
120
103
|
|
pycoze/bot/bot.py
CHANGED
@@ -9,15 +9,15 @@ pycoze/automation/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU
|
|
9
9
|
pycoze/automation/browser/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
10
10
|
pycoze/automation/browser/edge_driver_manager.py,sha256=gpgseunph5owZH6EskSYthuhey2SU3UP204gY0yIcuI,3022
|
11
11
|
pycoze/bot/__init__.py,sha256=6HHMxDQVOyZM9dtSjQm9tjGnhj4h7CixD0JOvEwTi48,41
|
12
|
-
pycoze/bot/agent_chat.py,sha256=
|
13
|
-
pycoze/bot/bot.py,sha256=
|
12
|
+
pycoze/bot/agent_chat.py,sha256=BREcg2L1LVZ4mZybTfFtxIL3OMHaxoQcPsBVumq2a1s,3556
|
13
|
+
pycoze/bot/bot.py,sha256=_qmUTZ09FmRLifHrW5stDZWGVK6yuMEMBC3fmeYJnqk,844
|
14
14
|
pycoze/bot/agent/__init__.py,sha256=3wE8_FFQS8j2BY-g9Cr-onV0POEvDRZaw_NCzpqrNus,265
|
15
|
-
pycoze/bot/agent/agent.py,sha256=
|
16
|
-
pycoze/bot/agent/assistant.py,sha256=
|
15
|
+
pycoze/bot/agent/agent.py,sha256=iZzvem9_NyFyfu1uvnCxS89SNo2O4Qx1n3CxMIrIy0A,3447
|
16
|
+
pycoze/bot/agent/assistant.py,sha256=s1y_gR_9UK_jzjX6YztXK5JNhnV-_YvUA6vv1lToS-k,1083
|
17
17
|
pycoze/bot/agent/chat.py,sha256=mubOCAHvA6VtyE6N40elI6KrP6A69uB_G6ihE3G_Vi4,860
|
18
18
|
pycoze/bot/agent/agent_types/__init__.py,sha256=zmU2Kmrv5mCdfg-QlPn2H6pWxbGeq8s7YTqLhpzJC6k,179
|
19
19
|
pycoze/bot/agent/agent_types/const.py,sha256=BfUKPrhAHREoMLHuFNG2bCIEkC1-f7K0LEqNg4RwiRE,70
|
20
|
-
pycoze/bot/agent/agent_types/openai_func_call_agent.py,sha256=
|
20
|
+
pycoze/bot/agent/agent_types/openai_func_call_agent.py,sha256=uXQGGmC9qFBsmdE-u-nXfXuqGq618hQ91GYW4mntmpU,6417
|
21
21
|
pycoze/reference/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
22
22
|
pycoze/reference/bot.py,sha256=BDflTV3zYoZqWnJpD5lMM_1vU_5b20M3XiFt1p-RHWM,2427
|
23
23
|
pycoze/reference/lib.py,sha256=0xQJTLTHedGzQBsjuTFNBVqYc4-8Yl65gGCrAhWyOX8,2155
|
@@ -32,8 +32,8 @@ pycoze/utils/__init__.py,sha256=Gi5EnrWZGMD2JRejgV4c_VLCXyvA2wwBFI_niDF5MUE,110
|
|
32
32
|
pycoze/utils/arg.py,sha256=GtfGbMTMdaK75Fwh6MpUe1pCA5X6Ep4LFG7a72YrzjI,525
|
33
33
|
pycoze/utils/env.py,sha256=W04lhvTHhAAC6EldP6kk2xrctqtu8K6kl1vDLZDNeh8,561
|
34
34
|
pycoze/utils/text_or_file.py,sha256=gpxZVWt2DW6YiEg_MnMuwg36VNf3TX383QD_1oZNB0Y,551
|
35
|
-
pycoze-0.1.
|
36
|
-
pycoze-0.1.
|
37
|
-
pycoze-0.1.
|
38
|
-
pycoze-0.1.
|
39
|
-
pycoze-0.1.
|
35
|
+
pycoze-0.1.237.dist-info/LICENSE,sha256=QStd_Qsd0-kAam_-sOesCIp_uKrGWeoKwt9M49NVkNU,1090
|
36
|
+
pycoze-0.1.237.dist-info/METADATA,sha256=idM3nyKaTT363E4aiUb4PcVvUXGKuf1_S57x79XMZlA,699
|
37
|
+
pycoze-0.1.237.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
38
|
+
pycoze-0.1.237.dist-info/top_level.txt,sha256=76dPeDhKvOCleL3ZC5gl1-y4vdS1tT_U1hxWVAn7sFo,7
|
39
|
+
pycoze-0.1.237.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|