pycoze 0.1.131__py3-none-any.whl → 0.1.133__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,7 +11,7 @@ bot_index = 0
11
11
 
12
12
  def import_bot(bot_id):
13
13
  global bot_index
14
- tool_base_path = "../"
14
+ tool_base_path = "../../"
15
15
  module_path = os.path.join(tool_base_path, bot_id)
16
16
  module_path = os.path.normpath(os.path.abspath(module_path))
17
17
 
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, SystemMessage
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)))
@@ -1,4 +1,4 @@
1
1
  from .openai_func_call_agent import create_openai_func_call_agent_executor
2
+ from .const import HumanToolString
2
3
 
3
-
4
- __all__ = [create_openai_func_call_agent_executor]
4
+ __all__ = [create_openai_func_call_agent_executor, HumanToolString]
@@ -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
+ )
pycoze/bot/bot.py CHANGED
@@ -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.bot_for_bot import import_bot
8
- from pycoze.access.tool_for_bot import import_tools
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):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pycoze
3
- Version: 0.1.131
3
+ Version: 0.1.133
4
4
  Summary: Package for pycoze only!
5
5
  Author: Yuan Jie Xiong
6
6
  Author-email: aiqqqqqqq@qq.com
@@ -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=2F-l2O6S94jL8Jpn83y_rUxs-22uxSQgrSd0-9wdmts,2029
4
+ pycoze/access/bot.py,sha256=eZuXTsZXfHqH7YVkKX4HnjWOx8XgEQbKMHuxZ8aeME8,2032
5
5
  pycoze/access/lib.py,sha256=sp3PqvsyE3OjSqgnykyaz_JARwelMGq44NQUU1x7IV4,2045
6
- pycoze/access/tool_for_bot.py,sha256=mAx3dPbZpU_FWlK6uxoWqHbduuNM_EQU8kBmzEKkccE,1339
6
+ pycoze/access/tool.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=u56BqzZ5fbpG3ZgciusMQMXZ3g1YZRmJxZ7vEsC1rAw,3354
10
+ pycoze/bot/bot.py,sha256=3vf1ayGbqSY7Sik3MhTRBY4UUZniFx1Julfo-tzQnuc,3370
11
11
  pycoze/bot/agent/__init__.py,sha256=YR9vpkEQn1e4937r_xFPJXUCPBEJ0SFzEQDBe2x3-YA,157
12
- pycoze/bot/agent/agent.py,sha256=XMTO6s8OJpaOnymT8ZUuJxXx2ICZ3r7Ck0pHJqPPFIs,3346
13
- pycoze/bot/agent/assistant.py,sha256=XI4w-rFfbk3qYE0tWcWoya8dz-3cA-QZ0Sanhl3DbKE,1112
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=XNvKWq9REE5Wzjm0OZi3CKIQF2UZ9PZkeUuxgFJbrfc,128
16
- pycoze/bot/agent/agent_types/openai_func_call_agent.py,sha256=klMFym4FVDClpYZPh3AYXkihBVyRkpdWBpZ56IHohZo,6736
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.131.dist-info/LICENSE,sha256=QStd_Qsd0-kAam_-sOesCIp_uKrGWeoKwt9M49NVkNU,1090
26
- pycoze-0.1.131.dist-info/METADATA,sha256=qaSLZk_SndWeQlXhI9GoN5_jV2sgS4HQcPFk6-QYhOA,726
27
- pycoze-0.1.131.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
28
- pycoze-0.1.131.dist-info/top_level.txt,sha256=76dPeDhKvOCleL3ZC5gl1-y4vdS1tT_U1hxWVAn7sFo,7
29
- pycoze-0.1.131.dist-info/RECORD,,
26
+ pycoze-0.1.133.dist-info/LICENSE,sha256=QStd_Qsd0-kAam_-sOesCIp_uKrGWeoKwt9M49NVkNU,1090
27
+ pycoze-0.1.133.dist-info/METADATA,sha256=CEki2ZAX-36fcKt-NgR4CBZtkJgOfS2KlKnocLepJn0,726
28
+ pycoze-0.1.133.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
29
+ pycoze-0.1.133.dist-info/top_level.txt,sha256=76dPeDhKvOCleL3ZC5gl1-y4vdS1tT_U1hxWVAn7sFo,7
30
+ pycoze-0.1.133.dist-info/RECORD,,
File without changes