pycoze 0.1.130__tar.gz → 0.1.132__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {pycoze-0.1.130 → pycoze-0.1.132}/PKG-INFO +1 -1
- {pycoze-0.1.130 → pycoze-0.1.132}/pycoze/access/bot_for_bot.py +1 -0
- {pycoze-0.1.130 → pycoze-0.1.132}/pycoze/access/lib.py +1 -1
- {pycoze-0.1.130 → pycoze-0.1.132}/pycoze/bot/agent/agent.py +6 -6
- pycoze-0.1.132/pycoze/bot/agent/agent_types/__init__.py +4 -0
- pycoze-0.1.132/pycoze/bot/agent/agent_types/const.py +1 -0
- {pycoze-0.1.130 → pycoze-0.1.132}/pycoze/bot/agent/agent_types/openai_func_call_agent.py +2 -5
- {pycoze-0.1.130 → pycoze-0.1.132}/pycoze/bot/agent/assistant.py +35 -35
- {pycoze-0.1.130 → pycoze-0.1.132}/pycoze/bot/bot.py +3 -3
- {pycoze-0.1.130 → pycoze-0.1.132}/pycoze.egg-info/PKG-INFO +1 -1
- {pycoze-0.1.130 → pycoze-0.1.132}/pycoze.egg-info/SOURCES.txt +1 -0
- {pycoze-0.1.130 → pycoze-0.1.132}/setup.py +1 -1
- pycoze-0.1.130/pycoze/bot/agent/agent_types/__init__.py +0 -4
- {pycoze-0.1.130 → pycoze-0.1.132}/LICENSE +0 -0
- {pycoze-0.1.130 → pycoze-0.1.132}/README.md +0 -0
- {pycoze-0.1.130 → pycoze-0.1.132}/pycoze/__init__.py +0 -0
- {pycoze-0.1.130 → pycoze-0.1.132}/pycoze/access/__init__.py +0 -0
- {pycoze-0.1.130 → pycoze-0.1.132}/pycoze/access/tool_for_bot.py +0 -0
- {pycoze-0.1.130 → pycoze-0.1.132}/pycoze/ai/__init__.py +0 -0
- {pycoze-0.1.130 → pycoze-0.1.132}/pycoze/ai/vram_reserve.py +0 -0
- {pycoze-0.1.130 → pycoze-0.1.132}/pycoze/bot/__init__.py +0 -0
- {pycoze-0.1.130 → pycoze-0.1.132}/pycoze/bot/agent/__init__.py +0 -0
- {pycoze-0.1.130 → pycoze-0.1.132}/pycoze/bot/agent/chat.py +0 -0
- {pycoze-0.1.130 → pycoze-0.1.132}/pycoze/module.py +0 -0
- {pycoze-0.1.130 → pycoze-0.1.132}/pycoze/ui/__init__.py +0 -0
- {pycoze-0.1.130 → pycoze-0.1.132}/pycoze/ui/base.py +0 -0
- {pycoze-0.1.130 → pycoze-0.1.132}/pycoze/ui/color.py +0 -0
- {pycoze-0.1.130 → pycoze-0.1.132}/pycoze/ui/typ.py +0 -0
- {pycoze-0.1.130 → pycoze-0.1.132}/pycoze/ui/ui_def.py +0 -0
- {pycoze-0.1.130 → pycoze-0.1.132}/pycoze/utils/__init__.py +0 -0
- {pycoze-0.1.130 → pycoze-0.1.132}/pycoze/utils/arg.py +0 -0
- {pycoze-0.1.130 → pycoze-0.1.132}/pycoze/utils/text_or_file.py +0 -0
- {pycoze-0.1.130 → pycoze-0.1.132}/pycoze.egg-info/dependency_links.txt +0 -0
- {pycoze-0.1.130 → pycoze-0.1.132}/pycoze.egg-info/top_level.txt +0 -0
- {pycoze-0.1.130 → pycoze-0.1.132}/setup.cfg +0 -0
@@ -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)
|
@@ -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
|
|
@@ -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
|
+
)
|
@@ -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):
|
@@ -20,6 +20,7 @@ pycoze/bot/agent/agent.py
|
|
20
20
|
pycoze/bot/agent/assistant.py
|
21
21
|
pycoze/bot/agent/chat.py
|
22
22
|
pycoze/bot/agent/agent_types/__init__.py
|
23
|
+
pycoze/bot/agent/agent_types/const.py
|
23
24
|
pycoze/bot/agent/agent_types/openai_func_call_agent.py
|
24
25
|
pycoze/ui/__init__.py
|
25
26
|
pycoze/ui/base.py
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|