pycoze 0.1.89__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 (32) hide show
  1. {pycoze-0.1.89 → pycoze-0.1.93}/PKG-INFO +2 -2
  2. {pycoze-0.1.89 → pycoze-0.1.93}/README.md +1 -1
  3. pycoze-0.1.93/pycoze/ai/__init__.py +1 -0
  4. {pycoze-0.1.89 → pycoze-0.1.93}/pycoze/ai/vram_reserve.py +3 -11
  5. {pycoze-0.1.89 → pycoze-0.1.93}/pycoze/bot/agent/agent_types/openai_func_call_agent.py +48 -46
  6. {pycoze-0.1.89 → pycoze-0.1.93}/pycoze/bot/bot.py +3 -2
  7. {pycoze-0.1.89 → pycoze-0.1.93}/pycoze.egg-info/PKG-INFO +2 -2
  8. {pycoze-0.1.89 → pycoze-0.1.93}/setup.py +1 -1
  9. pycoze-0.1.89/pycoze/ai/__init__.py +0 -1
  10. {pycoze-0.1.89 → pycoze-0.1.93}/LICENSE +0 -0
  11. {pycoze-0.1.89 → pycoze-0.1.93}/pycoze/__init__.py +0 -0
  12. {pycoze-0.1.89 → pycoze-0.1.93}/pycoze/access/__init__.py +0 -0
  13. {pycoze-0.1.89 → pycoze-0.1.93}/pycoze/access/tool_for_bot.py +0 -0
  14. {pycoze-0.1.89 → pycoze-0.1.93}/pycoze/bot/__init__.py +0 -0
  15. {pycoze-0.1.89 → pycoze-0.1.93}/pycoze/bot/agent/__init__.py +0 -0
  16. {pycoze-0.1.89 → pycoze-0.1.93}/pycoze/bot/agent/agent.py +0 -0
  17. {pycoze-0.1.89 → pycoze-0.1.93}/pycoze/bot/agent/agent_types/__init__.py +0 -0
  18. {pycoze-0.1.89 → pycoze-0.1.93}/pycoze/bot/agent/assistant.py +0 -0
  19. {pycoze-0.1.89 → pycoze-0.1.93}/pycoze/bot/agent/chat.py +0 -0
  20. {pycoze-0.1.89 → pycoze-0.1.93}/pycoze/module.py +0 -0
  21. {pycoze-0.1.89 → pycoze-0.1.93}/pycoze/ui/__init__.py +0 -0
  22. {pycoze-0.1.89 → pycoze-0.1.93}/pycoze/ui/base.py +0 -0
  23. {pycoze-0.1.89 → pycoze-0.1.93}/pycoze/ui/color.py +0 -0
  24. {pycoze-0.1.89 → pycoze-0.1.93}/pycoze/ui/typ.py +0 -0
  25. {pycoze-0.1.89 → pycoze-0.1.93}/pycoze/ui/ui_def.py +0 -0
  26. {pycoze-0.1.89 → pycoze-0.1.93}/pycoze/utils/__init__.py +0 -0
  27. {pycoze-0.1.89 → pycoze-0.1.93}/pycoze/utils/arg.py +0 -0
  28. {pycoze-0.1.89 → pycoze-0.1.93}/pycoze/utils/text_or_file.py +0 -0
  29. {pycoze-0.1.89 → pycoze-0.1.93}/pycoze.egg-info/SOURCES.txt +0 -0
  30. {pycoze-0.1.89 → pycoze-0.1.93}/pycoze.egg-info/dependency_links.txt +0 -0
  31. {pycoze-0.1.89 → pycoze-0.1.93}/pycoze.egg-info/top_level.txt +0 -0
  32. {pycoze-0.1.89 → 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.89
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文件夹 -->
@@ -0,0 +1 @@
1
+ from .vram_reserve import reserve_vram, reserve_vram_retry, unreserve_vram
@@ -88,33 +88,25 @@ def reserve_vram_retry(gb, retry=None, uid=None):
88
88
  retry = sys.maxsize
89
89
  for i in range(retry):
90
90
  time.sleep(1)
91
- if i % 10 == 0 or i < 10:
91
+ if i % 10 == 0 or i < 10 and i != 0:
92
92
  print(f"重试第{i}次")
93
93
  if reserve_vram(gb, uid):
94
94
  return True
95
95
  return False
96
96
 
97
97
 
98
- def release_vram(uid=None):
98
+ def unreserve_vram(uid=None):
99
99
  if uid is None:
100
100
  uid = f"pid:{os.getpid()}"
101
101
  with sqlite3.connect(DATABASE_PATH) as conn:
102
102
  cursor = conn.cursor()
103
103
  cursor.execute(f"DELETE FROM {TABLE_NAME} WHERE uid = ?", (uid,))
104
104
  conn.commit()
105
- # 计算释放后的剩余VRAM大小
106
- cursor.execute(f"SELECT SUM(reserved_gb) FROM {TABLE_NAME}")
107
- total_reserved = cursor.fetchone()[0]
108
- if total_reserved is None:
109
- total_reserved = 0.0
110
- available_gb = get_vram_resources() - total_reserved
111
- print(f"释放成功,剩余VRAM大小: {available_gb} GB")
112
105
 
113
106
 
114
107
  # 注册退出时的清理函数
115
108
  def cleanup():
116
- release_vram()
117
- print("程序退出,VRAM资源已释放")
109
+ unreserve_vram()
118
110
 
119
111
 
120
112
  def initialize_and_check():
@@ -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.89
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.89",
5
+ version="0.1.93",
6
6
  packages=find_packages(),
7
7
  install_requires=[],
8
8
  author="Yuan Jie Xiong",
@@ -1 +0,0 @@
1
- from .vram_reserve import reserve_vram_retry, release_vram, reserve_vram
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