pycoze 0.1.89__py3-none-any.whl → 0.1.93__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
pycoze/ai/__init__.py CHANGED
@@ -1 +1 @@
1
- from .vram_reserve import reserve_vram_retry, release_vram, reserve_vram
1
+ from .vram_reserve import reserve_vram, reserve_vram_retry, unreserve_vram
pycoze/ai/vram_reserve.py CHANGED
@@ -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(
pycoze/bot/bot.py CHANGED
@@ -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,16 +2,16 @@ 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
4
  pycoze/access/tool_for_bot.py,sha256=Nv6XlxcqaLaMVQNDkpcthlqaSxyfHoOfWiTScQXO22Y,2656
5
- pycoze/ai/__init__.py,sha256=Smivpb8qbRnzWkzKRe2IxsmKP5Dh8EvngDFdkD_DVLo,73
6
- pycoze/ai/vram_reserve.py,sha256=zjRFxTJDfWlyd3xSJTkB4sdfsahsOijyCY_MEIotMbw,4731
5
+ pycoze/ai/__init__.py,sha256=odM2lgYSnApxw4AzLV_5AyaxL5_MLfydOSB1VmLGFyA,75
6
+ pycoze/ai/vram_reserve.py,sha256=QbqaA8qv87cnEpOVDMygi0BNMxuhLYwj1UKfR_D5BD4,4340
7
7
  pycoze/bot/__init__.py,sha256=6HHMxDQVOyZM9dtSjQm9tjGnhj4h7CixD0JOvEwTi48,41
8
- pycoze/bot/bot.py,sha256=w_ddp3IeWryUgIad-_V-SsDzGwYqZXekw5NXbYyXrkk,3041
8
+ pycoze/bot/bot.py,sha256=HV2N6Cfuvv5eCCh8bG8Lv6DpDJZ1FrSVrVk8H-zcyCE,3146
9
9
  pycoze/bot/agent/__init__.py,sha256=YR9vpkEQn1e4937r_xFPJXUCPBEJ0SFzEQDBe2x3-YA,157
10
10
  pycoze/bot/agent/agent.py,sha256=XMTO6s8OJpaOnymT8ZUuJxXx2ICZ3r7Ck0pHJqPPFIs,3346
11
11
  pycoze/bot/agent/assistant.py,sha256=XI4w-rFfbk3qYE0tWcWoya8dz-3cA-QZ0Sanhl3DbKE,1112
12
12
  pycoze/bot/agent/chat.py,sha256=kc0qgcrBSXdiMy49JwThZTV-0PAvzAhiUvbI5ILiSnU,571
13
13
  pycoze/bot/agent/agent_types/__init__.py,sha256=XNvKWq9REE5Wzjm0OZi3CKIQF2UZ9PZkeUuxgFJbrfc,128
14
- pycoze/bot/agent/agent_types/openai_func_call_agent.py,sha256=nqyHEZVSqxFlfjraeWJ1up4IGZFZSaZB2rlzhVheKbw,6877
14
+ pycoze/bot/agent/agent_types/openai_func_call_agent.py,sha256=klMFym4FVDClpYZPh3AYXkihBVyRkpdWBpZ56IHohZo,6736
15
15
  pycoze/ui/__init__.py,sha256=7xAfL2lfG7-jllPJEZUJO89xUE9sNzvo1y0WmBswjBI,458
16
16
  pycoze/ui/base.py,sha256=SCXVDK7PpMaBv6ovvabHcfRq_d2AWM0BRyxpNhuJN5A,1285
17
17
  pycoze/ui/color.py,sha256=cT9Ib8uNzkOKxyW0IwVj46o4LwdB1xgNCj1_Rou9d_4,854
@@ -20,8 +20,8 @@ pycoze/ui/ui_def.py,sha256=UhhU_yB3GV9ISbvTWT48hsHPHI250BhMILh6bu5Uioo,4206
20
20
  pycoze/utils/__init__.py,sha256=TNJhFfY7JYdLlzuP9GvgxfNXUtbgH_NUUJSqHXCxJn4,78
21
21
  pycoze/utils/arg.py,sha256=kA3KBQzXc2WlH5XbF8kfikfpqljiKaW7oY_GE4Qyffc,753
22
22
  pycoze/utils/text_or_file.py,sha256=gpxZVWt2DW6YiEg_MnMuwg36VNf3TX383QD_1oZNB0Y,551
23
- pycoze-0.1.89.dist-info/LICENSE,sha256=QStd_Qsd0-kAam_-sOesCIp_uKrGWeoKwt9M49NVkNU,1090
24
- pycoze-0.1.89.dist-info/METADATA,sha256=vpuL_fkJtMzFx7So1MwT3eftwVbeRMQdYnNQJ96Ecbk,719
25
- pycoze-0.1.89.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
26
- pycoze-0.1.89.dist-info/top_level.txt,sha256=76dPeDhKvOCleL3ZC5gl1-y4vdS1tT_U1hxWVAn7sFo,7
27
- pycoze-0.1.89.dist-info/RECORD,,
23
+ pycoze-0.1.93.dist-info/LICENSE,sha256=QStd_Qsd0-kAam_-sOesCIp_uKrGWeoKwt9M49NVkNU,1090
24
+ pycoze-0.1.93.dist-info/METADATA,sha256=logRR2lLxN2coU_EflW59R7Ra3Nu_HkILqKr7OCwVvU,725
25
+ pycoze-0.1.93.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
26
+ pycoze-0.1.93.dist-info/top_level.txt,sha256=76dPeDhKvOCleL3ZC5gl1-y4vdS1tT_U1hxWVAn7sFo,7
27
+ pycoze-0.1.93.dist-info/RECORD,,