pycoze 0.1.131__tar.gz → 0.1.133__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {pycoze-0.1.131 → pycoze-0.1.133}/PKG-INFO +1 -1
- pycoze-0.1.131/pycoze/access/bot_for_bot.py → pycoze-0.1.133/pycoze/access/bot.py +1 -1
- {pycoze-0.1.131 → pycoze-0.1.133}/pycoze/bot/agent/agent.py +6 -6
- pycoze-0.1.133/pycoze/bot/agent/agent_types/__init__.py +4 -0
- pycoze-0.1.133/pycoze/bot/agent/agent_types/const.py +1 -0
- {pycoze-0.1.131 → pycoze-0.1.133}/pycoze/bot/agent/agent_types/openai_func_call_agent.py +2 -5
- {pycoze-0.1.131 → pycoze-0.1.133}/pycoze/bot/agent/assistant.py +35 -35
- {pycoze-0.1.131 → pycoze-0.1.133}/pycoze/bot/bot.py +5 -5
- {pycoze-0.1.131 → pycoze-0.1.133}/pycoze.egg-info/PKG-INFO +1 -1
- {pycoze-0.1.131 → pycoze-0.1.133}/pycoze.egg-info/SOURCES.txt +3 -2
- {pycoze-0.1.131 → pycoze-0.1.133}/setup.py +1 -1
- pycoze-0.1.131/pycoze/bot/agent/agent_types/__init__.py +0 -4
- {pycoze-0.1.131 → pycoze-0.1.133}/LICENSE +0 -0
- {pycoze-0.1.131 → pycoze-0.1.133}/README.md +0 -0
- {pycoze-0.1.131 → pycoze-0.1.133}/pycoze/__init__.py +0 -0
- {pycoze-0.1.131 → pycoze-0.1.133}/pycoze/access/__init__.py +0 -0
- {pycoze-0.1.131 → pycoze-0.1.133}/pycoze/access/lib.py +0 -0
- /pycoze-0.1.131/pycoze/access/tool_for_bot.py → /pycoze-0.1.133/pycoze/access/tool.py +0 -0
- {pycoze-0.1.131 → pycoze-0.1.133}/pycoze/ai/__init__.py +0 -0
- {pycoze-0.1.131 → pycoze-0.1.133}/pycoze/ai/vram_reserve.py +0 -0
- {pycoze-0.1.131 → pycoze-0.1.133}/pycoze/bot/__init__.py +0 -0
- {pycoze-0.1.131 → pycoze-0.1.133}/pycoze/bot/agent/__init__.py +0 -0
- {pycoze-0.1.131 → pycoze-0.1.133}/pycoze/bot/agent/chat.py +0 -0
- {pycoze-0.1.131 → pycoze-0.1.133}/pycoze/module.py +0 -0
- {pycoze-0.1.131 → pycoze-0.1.133}/pycoze/ui/__init__.py +0 -0
- {pycoze-0.1.131 → pycoze-0.1.133}/pycoze/ui/base.py +0 -0
- {pycoze-0.1.131 → pycoze-0.1.133}/pycoze/ui/color.py +0 -0
- {pycoze-0.1.131 → pycoze-0.1.133}/pycoze/ui/typ.py +0 -0
- {pycoze-0.1.131 → pycoze-0.1.133}/pycoze/ui/ui_def.py +0 -0
- {pycoze-0.1.131 → pycoze-0.1.133}/pycoze/utils/__init__.py +0 -0
- {pycoze-0.1.131 → pycoze-0.1.133}/pycoze/utils/arg.py +0 -0
- {pycoze-0.1.131 → pycoze-0.1.133}/pycoze/utils/text_or_file.py +0 -0
- {pycoze-0.1.131 → pycoze-0.1.133}/pycoze.egg-info/dependency_links.txt +0 -0
- {pycoze-0.1.131 → pycoze-0.1.133}/pycoze.egg-info/top_level.txt +0 -0
- {pycoze-0.1.131 → pycoze-0.1.133}/setup.cfg +0 -0
@@ -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
|
+
)
|
@@ -4,8 +4,8 @@ from .agent import run_agent, Runnable, INPUT_MESSAGE, output
|
|
4
4
|
import asyncio
|
5
5
|
from langchain_core.messages import HumanMessage
|
6
6
|
from pycoze import utils
|
7
|
-
from pycoze.access.
|
8
|
-
from pycoze.access.
|
7
|
+
from pycoze.access.bot import import_bot
|
8
|
+
from pycoze.access.tool import import_tools
|
9
9
|
from langchain_core.utils.function_calling import convert_to_openai_tool
|
10
10
|
|
11
11
|
params = utils.arg.read_params_file()
|
@@ -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):
|
@@ -8,9 +8,9 @@ pycoze.egg-info/SOURCES.txt
|
|
8
8
|
pycoze.egg-info/dependency_links.txt
|
9
9
|
pycoze.egg-info/top_level.txt
|
10
10
|
pycoze/access/__init__.py
|
11
|
-
pycoze/access/
|
11
|
+
pycoze/access/bot.py
|
12
12
|
pycoze/access/lib.py
|
13
|
-
pycoze/access/
|
13
|
+
pycoze/access/tool.py
|
14
14
|
pycoze/ai/__init__.py
|
15
15
|
pycoze/ai/vram_reserve.py
|
16
16
|
pycoze/bot/__init__.py
|
@@ -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
|
File without changes
|