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.
Files changed (35) hide show
  1. {pycoze-0.1.130 → pycoze-0.1.132}/PKG-INFO +1 -1
  2. {pycoze-0.1.130 → pycoze-0.1.132}/pycoze/access/bot_for_bot.py +1 -0
  3. {pycoze-0.1.130 → pycoze-0.1.132}/pycoze/access/lib.py +1 -1
  4. {pycoze-0.1.130 → pycoze-0.1.132}/pycoze/bot/agent/agent.py +6 -6
  5. pycoze-0.1.132/pycoze/bot/agent/agent_types/__init__.py +4 -0
  6. pycoze-0.1.132/pycoze/bot/agent/agent_types/const.py +1 -0
  7. {pycoze-0.1.130 → pycoze-0.1.132}/pycoze/bot/agent/agent_types/openai_func_call_agent.py +2 -5
  8. {pycoze-0.1.130 → pycoze-0.1.132}/pycoze/bot/agent/assistant.py +35 -35
  9. {pycoze-0.1.130 → pycoze-0.1.132}/pycoze/bot/bot.py +3 -3
  10. {pycoze-0.1.130 → pycoze-0.1.132}/pycoze.egg-info/PKG-INFO +1 -1
  11. {pycoze-0.1.130 → pycoze-0.1.132}/pycoze.egg-info/SOURCES.txt +1 -0
  12. {pycoze-0.1.130 → pycoze-0.1.132}/setup.py +1 -1
  13. pycoze-0.1.130/pycoze/bot/agent/agent_types/__init__.py +0 -4
  14. {pycoze-0.1.130 → pycoze-0.1.132}/LICENSE +0 -0
  15. {pycoze-0.1.130 → pycoze-0.1.132}/README.md +0 -0
  16. {pycoze-0.1.130 → pycoze-0.1.132}/pycoze/__init__.py +0 -0
  17. {pycoze-0.1.130 → pycoze-0.1.132}/pycoze/access/__init__.py +0 -0
  18. {pycoze-0.1.130 → pycoze-0.1.132}/pycoze/access/tool_for_bot.py +0 -0
  19. {pycoze-0.1.130 → pycoze-0.1.132}/pycoze/ai/__init__.py +0 -0
  20. {pycoze-0.1.130 → pycoze-0.1.132}/pycoze/ai/vram_reserve.py +0 -0
  21. {pycoze-0.1.130 → pycoze-0.1.132}/pycoze/bot/__init__.py +0 -0
  22. {pycoze-0.1.130 → pycoze-0.1.132}/pycoze/bot/agent/__init__.py +0 -0
  23. {pycoze-0.1.130 → pycoze-0.1.132}/pycoze/bot/agent/chat.py +0 -0
  24. {pycoze-0.1.130 → pycoze-0.1.132}/pycoze/module.py +0 -0
  25. {pycoze-0.1.130 → pycoze-0.1.132}/pycoze/ui/__init__.py +0 -0
  26. {pycoze-0.1.130 → pycoze-0.1.132}/pycoze/ui/base.py +0 -0
  27. {pycoze-0.1.130 → pycoze-0.1.132}/pycoze/ui/color.py +0 -0
  28. {pycoze-0.1.130 → pycoze-0.1.132}/pycoze/ui/typ.py +0 -0
  29. {pycoze-0.1.130 → pycoze-0.1.132}/pycoze/ui/ui_def.py +0 -0
  30. {pycoze-0.1.130 → pycoze-0.1.132}/pycoze/utils/__init__.py +0 -0
  31. {pycoze-0.1.130 → pycoze-0.1.132}/pycoze/utils/arg.py +0 -0
  32. {pycoze-0.1.130 → pycoze-0.1.132}/pycoze/utils/text_or_file.py +0 -0
  33. {pycoze-0.1.130 → pycoze-0.1.132}/pycoze.egg-info/dependency_links.txt +0 -0
  34. {pycoze-0.1.130 → pycoze-0.1.132}/pycoze.egg-info/top_level.txt +0 -0
  35. {pycoze-0.1.130 → pycoze-0.1.132}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pycoze
3
- Version: 0.1.130
3
+ Version: 0.1.132
4
4
  Summary: Package for pycoze only!
5
5
  Author: Yuan Jie Xiong
6
6
  Author-email: aiqqqqqqq@qq.com
@@ -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)
@@ -54,7 +54,7 @@ def wrapped_func(item, module_path):
54
54
  try:
55
55
  print(f"调用了 {item.name}")
56
56
  except:
57
- pass
57
+ print(f"called unknown")
58
58
  with ChangeDirectoryAndPath(module_path):
59
59
  result = original_tool_function(*args, **kwargs)
60
60
  try:
@@ -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)))
@@ -0,0 +1,4 @@
1
+ from .openai_func_call_agent import create_openai_func_call_agent_executor
2
+ from .const import HumanToolString
3
+
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
+ )
@@ -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.130
3
+ Version: 0.1.132
4
4
  Summary: Package for pycoze only!
5
5
  Author: Yuan Jie Xiong
6
6
  Author-email: aiqqqqqqq@qq.com
@@ -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
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name="pycoze",
5
- version="0.1.130",
5
+ version="0.1.132",
6
6
  packages=find_packages(),
7
7
  install_requires=[],
8
8
  author="Yuan Jie Xiong",
@@ -1,4 +0,0 @@
1
- from .openai_func_call_agent import create_openai_func_call_agent_executor
2
-
3
-
4
- __all__ = [create_openai_func_call_agent_executor]
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