pycoze 0.1.90__tar.gz → 0.1.93__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. {pycoze-0.1.90 → pycoze-0.1.93}/PKG-INFO +2 -2
  2. {pycoze-0.1.90 → pycoze-0.1.93}/README.md +1 -1
  3. {pycoze-0.1.90 → pycoze-0.1.93}/pycoze/bot/agent/agent_types/openai_func_call_agent.py +48 -46
  4. {pycoze-0.1.90 → pycoze-0.1.93}/pycoze/bot/bot.py +3 -2
  5. {pycoze-0.1.90 → pycoze-0.1.93}/pycoze.egg-info/PKG-INFO +2 -2
  6. {pycoze-0.1.90 → pycoze-0.1.93}/setup.py +1 -1
  7. {pycoze-0.1.90 → pycoze-0.1.93}/LICENSE +0 -0
  8. {pycoze-0.1.90 → pycoze-0.1.93}/pycoze/__init__.py +0 -0
  9. {pycoze-0.1.90 → pycoze-0.1.93}/pycoze/access/__init__.py +0 -0
  10. {pycoze-0.1.90 → pycoze-0.1.93}/pycoze/access/tool_for_bot.py +0 -0
  11. {pycoze-0.1.90 → pycoze-0.1.93}/pycoze/ai/__init__.py +0 -0
  12. {pycoze-0.1.90 → pycoze-0.1.93}/pycoze/ai/vram_reserve.py +0 -0
  13. {pycoze-0.1.90 → pycoze-0.1.93}/pycoze/bot/__init__.py +0 -0
  14. {pycoze-0.1.90 → pycoze-0.1.93}/pycoze/bot/agent/__init__.py +0 -0
  15. {pycoze-0.1.90 → pycoze-0.1.93}/pycoze/bot/agent/agent.py +0 -0
  16. {pycoze-0.1.90 → pycoze-0.1.93}/pycoze/bot/agent/agent_types/__init__.py +0 -0
  17. {pycoze-0.1.90 → pycoze-0.1.93}/pycoze/bot/agent/assistant.py +0 -0
  18. {pycoze-0.1.90 → pycoze-0.1.93}/pycoze/bot/agent/chat.py +0 -0
  19. {pycoze-0.1.90 → pycoze-0.1.93}/pycoze/module.py +0 -0
  20. {pycoze-0.1.90 → pycoze-0.1.93}/pycoze/ui/__init__.py +0 -0
  21. {pycoze-0.1.90 → pycoze-0.1.93}/pycoze/ui/base.py +0 -0
  22. {pycoze-0.1.90 → pycoze-0.1.93}/pycoze/ui/color.py +0 -0
  23. {pycoze-0.1.90 → pycoze-0.1.93}/pycoze/ui/typ.py +0 -0
  24. {pycoze-0.1.90 → pycoze-0.1.93}/pycoze/ui/ui_def.py +0 -0
  25. {pycoze-0.1.90 → pycoze-0.1.93}/pycoze/utils/__init__.py +0 -0
  26. {pycoze-0.1.90 → pycoze-0.1.93}/pycoze/utils/arg.py +0 -0
  27. {pycoze-0.1.90 → pycoze-0.1.93}/pycoze/utils/text_or_file.py +0 -0
  28. {pycoze-0.1.90 → pycoze-0.1.93}/pycoze.egg-info/SOURCES.txt +0 -0
  29. {pycoze-0.1.90 → pycoze-0.1.93}/pycoze.egg-info/dependency_links.txt +0 -0
  30. {pycoze-0.1.90 → pycoze-0.1.93}/pycoze.egg-info/top_level.txt +0 -0
  31. {pycoze-0.1.90 → pycoze-0.1.93}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pycoze
3
- Version: 0.1.90
3
+ Version: 0.1.93
4
4
  Summary: Package for pycoze only!
5
5
  Author: Yuan Jie Xiong
6
6
  Author-email: aiqqqqqqq@qq.com
@@ -18,7 +18,7 @@ Package for pycoze only!
18
18
 
19
19
 
20
20
  <!-- For author only -->
21
- <!-- pip install twine -->
21
+ <!-- pip install twine wheel -->
22
22
 
23
23
  <!-- 递增setup.py的版本 -->
24
24
  <!-- 删除build和dist和pycoze.egg-info文件夹 -->
@@ -5,7 +5,7 @@ Package for pycoze only!
5
5
 
6
6
 
7
7
  <!-- For author only -->
8
- <!-- pip install twine -->
8
+ <!-- pip install twine wheel -->
9
9
 
10
10
  <!-- 递增setup.py的版本 -->
11
11
  <!-- 删除build和dist和pycoze.egg-info文件夹 -->
@@ -30,40 +30,11 @@ def get_all_markdown_json(content):
30
30
  return json_list
31
31
 
32
32
 
33
- def create_openai_func_call_agent_executor(
34
- tools: list[BaseTool],
35
- llm: LanguageModelLike,
36
- system_message: str,
37
- tool_compatibility_mode: str,
38
- **kwargs
39
- ):
40
-
41
- async def _get_messages(messages):
42
- msgs = []
43
- for m in messages:
44
- if isinstance(m, ToolMessage):
45
- _dict = m.dict()
46
- _dict["content"] = str(_dict["content"])
47
- m_c = ToolMessage(**_dict)
48
- msgs.append(m_c)
49
- else:
50
- msgs.append(m)
51
-
52
- return [SystemMessage(content=system_message)] + msgs
53
-
54
- if tools:
55
- llm_with_tools = llm.bind(tools=[convert_to_openai_tool(t) for t in tools])
33
+ def get_tools(last_message):
34
+ if "tool_calls" in last_message.additional_kwargs:
35
+ return last_message.additional_kwargs["tool_calls"]
56
36
  else:
57
- llm_with_tools = llm
58
- agent = _get_messages | llm_with_tools
59
- tool_executor = ToolExecutor(tools)
60
-
61
- # Define the function that determines whether to continue or not
62
- def should_continue(messages):
63
- # If there is no FuncCall, then we finish
64
- last_message = messages[-1]
65
- if last_message.content.strip().endswith("```"):
66
- last_message.content = last_message.content + "\n\n" # 避免影响阅读
37
+ tool_calls = None
67
38
  if '"name"' in last_message.content and '"parameters":' in last_message.content:
68
39
  print("name 和 paremeters 模式")
69
40
  all_json = get_all_markdown_json(last_message.content)
@@ -79,9 +50,6 @@ def create_openai_func_call_agent_executor(
79
50
  "id": random.randint(0, 1000000),
80
51
  }
81
52
  )
82
- last_message.tool_calls = tool_calls
83
- last_message.additional_kwargs["tool_calls"] = tool_calls
84
- return "continue"
85
53
  if "<|tool▁sep|>" in last_message.content:
86
54
  print("deepseek的bug: <|tool▁sep|> 模式")
87
55
  name = (
@@ -100,15 +68,49 @@ def create_openai_func_call_agent_executor(
100
68
  }
101
69
  )
102
70
 
103
- last_message.additional_kwargs["tool_calls"] = tool_calls
104
- last_message.tool_calls = tool_calls
105
- return "continue"
71
+ return tool_calls
72
+
73
+
74
+ def create_openai_func_call_agent_executor(
75
+ tools: list[BaseTool],
76
+ llm: LanguageModelLike,
77
+ system_message: str,
78
+ tool_compatibility_mode: str,
79
+ **kwargs
80
+ ):
81
+
82
+ async def _get_messages(messages):
83
+ msgs = []
84
+ for m in messages:
85
+ if isinstance(m, ToolMessage):
86
+ _dict = m.dict()
87
+ _dict["content"] = str(_dict["content"])
88
+ m_c = ToolMessage(**_dict)
89
+ msgs.append(m_c)
90
+ else:
91
+ msgs.append(m)
92
+
93
+ return [SystemMessage(content=system_message)] + msgs
94
+
95
+ if tools:
96
+ llm_with_tools = llm.bind(tools=[convert_to_openai_tool(t) for t in tools])
97
+ else:
98
+ llm_with_tools = llm
99
+ agent = _get_messages | llm_with_tools
100
+ tool_executor = ToolExecutor(tools)
101
+
102
+ # Define the function that determines whether to continue or not
103
+ def should_continue(messages):
104
+ # If there is no FuncCall, then we finish
105
+ last_message = messages[-1]
106
+ if last_message.content.strip().endswith("```"):
107
+ last_message.content = last_message.content + "\n\n" # 避免影响阅读
108
+ tools = get_tools(last_message)
109
+ if last_message.tool_calls or tools:
110
+ return 'continue'
111
+ return 'end'
106
112
 
107
- if not last_message.tool_calls:
108
- return "end"
109
- # Otherwise if there is, we continue
110
- else:
111
- return "continue"
113
+
112
114
 
113
115
  # Define the function to execute tools
114
116
  async def call_tool(messages):
@@ -116,7 +118,7 @@ def create_openai_func_call_agent_executor(
116
118
  # Based on the continue condition
117
119
  # we know the last message involves a FuncCall
118
120
  last_message = messages[-1]
119
- for tool_call in last_message.additional_kwargs["tool_calls"]:
121
+ for tool_call in get_tools(last_message):
120
122
  function = tool_call["function"]
121
123
  function_name = function["name"]
122
124
  if function_name == "a_delay_function":
@@ -141,7 +143,7 @@ def create_openai_func_call_agent_executor(
141
143
  # We use the response to create a ToolMessage
142
144
  tool_messages = []
143
145
  for tool_call, response in zip(
144
- last_message.additional_kwargs["tool_calls"], responses
146
+ get_tools(last_message), responses
145
147
  ):
146
148
  if not isinstance(response, (str, int, float, bool, list, tuple)):
147
149
  response = repr(
@@ -53,8 +53,9 @@ def agent_chat(bot_setting_file, history):
53
53
  and len(tools) > 0
54
54
  ):
55
55
  prompt += """
56
- 如果不确定结果,请务必使用工具查询。
57
- 如果需要调用工具,请使用以正确markdown中的json代码格式进行结尾(务必保证json格式正确,不要出现反斜杠未转义等问题):
56
+ 作为一个AI,你如果不确定结果,请务必使用工具查询。
57
+ 你可以通过下面的方式使用工具,并耐心等待工具返回结果。
58
+ 如果你需要调用工具,请使用以正确markdown中的json代码格式进行结尾(务必保证json格式正确,不要出现反斜杠未转义等问题):
58
59
  ```json
59
60
  {"name": 函数名, "parameters": 参数词典}
60
61
  ```
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pycoze
3
- Version: 0.1.90
3
+ Version: 0.1.93
4
4
  Summary: Package for pycoze only!
5
5
  Author: Yuan Jie Xiong
6
6
  Author-email: aiqqqqqqq@qq.com
@@ -18,7 +18,7 @@ Package for pycoze only!
18
18
 
19
19
 
20
20
  <!-- For author only -->
21
- <!-- pip install twine -->
21
+ <!-- pip install twine wheel -->
22
22
 
23
23
  <!-- 递增setup.py的版本 -->
24
24
  <!-- 删除build和dist和pycoze.egg-info文件夹 -->
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name="pycoze",
5
- version="0.1.90",
5
+ version="0.1.93",
6
6
  packages=find_packages(),
7
7
  install_requires=[],
8
8
  author="Yuan Jie Xiong",
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