pycoze 0.1.88__tar.gz → 0.1.90__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. {pycoze-0.1.88 → pycoze-0.1.90}/PKG-INFO +1 -1
  2. pycoze-0.1.90/pycoze/ai/__init__.py +1 -0
  3. {pycoze-0.1.88 → pycoze-0.1.90}/pycoze/ai/vram_reserve.py +9 -43
  4. {pycoze-0.1.88 → pycoze-0.1.90}/pycoze/bot/agent/agent_types/openai_func_call_agent.py +1 -16
  5. {pycoze-0.1.88 → pycoze-0.1.90}/pycoze.egg-info/PKG-INFO +1 -1
  6. {pycoze-0.1.88 → pycoze-0.1.90}/pycoze.egg-info/SOURCES.txt +0 -1
  7. {pycoze-0.1.88 → pycoze-0.1.90}/setup.py +1 -1
  8. pycoze-0.1.88/pycoze/ai/__init__.py +0 -1
  9. pycoze-0.1.88/pycoze/ai/comfyui.py +0 -33
  10. {pycoze-0.1.88 → pycoze-0.1.90}/LICENSE +0 -0
  11. {pycoze-0.1.88 → pycoze-0.1.90}/README.md +0 -0
  12. {pycoze-0.1.88 → pycoze-0.1.90}/pycoze/__init__.py +0 -0
  13. {pycoze-0.1.88 → pycoze-0.1.90}/pycoze/access/__init__.py +0 -0
  14. {pycoze-0.1.88 → pycoze-0.1.90}/pycoze/access/tool_for_bot.py +0 -0
  15. {pycoze-0.1.88 → pycoze-0.1.90}/pycoze/bot/__init__.py +0 -0
  16. {pycoze-0.1.88 → pycoze-0.1.90}/pycoze/bot/agent/__init__.py +0 -0
  17. {pycoze-0.1.88 → pycoze-0.1.90}/pycoze/bot/agent/agent.py +0 -0
  18. {pycoze-0.1.88 → pycoze-0.1.90}/pycoze/bot/agent/agent_types/__init__.py +0 -0
  19. {pycoze-0.1.88 → pycoze-0.1.90}/pycoze/bot/agent/assistant.py +0 -0
  20. {pycoze-0.1.88 → pycoze-0.1.90}/pycoze/bot/agent/chat.py +0 -0
  21. {pycoze-0.1.88 → pycoze-0.1.90}/pycoze/bot/bot.py +0 -0
  22. {pycoze-0.1.88 → pycoze-0.1.90}/pycoze/module.py +0 -0
  23. {pycoze-0.1.88 → pycoze-0.1.90}/pycoze/ui/__init__.py +0 -0
  24. {pycoze-0.1.88 → pycoze-0.1.90}/pycoze/ui/base.py +0 -0
  25. {pycoze-0.1.88 → pycoze-0.1.90}/pycoze/ui/color.py +0 -0
  26. {pycoze-0.1.88 → pycoze-0.1.90}/pycoze/ui/typ.py +0 -0
  27. {pycoze-0.1.88 → pycoze-0.1.90}/pycoze/ui/ui_def.py +0 -0
  28. {pycoze-0.1.88 → pycoze-0.1.90}/pycoze/utils/__init__.py +0 -0
  29. {pycoze-0.1.88 → pycoze-0.1.90}/pycoze/utils/arg.py +0 -0
  30. {pycoze-0.1.88 → pycoze-0.1.90}/pycoze/utils/text_or_file.py +0 -0
  31. {pycoze-0.1.88 → pycoze-0.1.90}/pycoze.egg-info/dependency_links.txt +0 -0
  32. {pycoze-0.1.88 → pycoze-0.1.90}/pycoze.egg-info/top_level.txt +0 -0
  33. {pycoze-0.1.88 → pycoze-0.1.90}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pycoze
3
- Version: 0.1.88
3
+ Version: 0.1.90
4
4
  Summary: Package for pycoze only!
5
5
  Author: Yuan Jie Xiong
6
6
  Author-email: aiqqqqqqq@qq.com
@@ -0,0 +1 @@
1
+ from .vram_reserve import reserve_vram, reserve_vram_retry, unreserve_vram
@@ -42,44 +42,18 @@ def get_vram_resources():
42
42
  try:
43
43
  # 使用nvidia-smi命令获取VRAM信息
44
44
  result = subprocess.run(
45
- ["nvidia-smi", "--query-gpu=memory.free", "--format=csv,noheader,nounits"],
45
+ ["nvidia-smi", "--query-gpu=memory.total", "--format=csv,noheader,nounits"],
46
46
  stdout=subprocess.PIPE,
47
47
  text=True,
48
48
  )
49
- free_memory = result.stdout.strip().split("\n")
50
- total_free_memory = 0
51
- for mem in free_memory:
49
+ total_memory_list = result.stdout.strip().split("\n")
50
+ total_memory = 0
51
+ for mem in total_memory_list:
52
52
  try:
53
- total_free_memory += float(mem)
53
+ total_memory += float(mem)
54
54
  except:
55
55
  pass
56
-
57
- # 获取正在使用VRAM的进程信息
58
- process_result = subprocess.run(
59
- [
60
- "nvidia-smi",
61
- "--query-compute-apps=pid,process_name,used_memory",
62
- "--format=csv,noheader,nounits",
63
- ],
64
- stdout=subprocess.PIPE,
65
- text=True,
66
- )
67
- process_info = process_result.stdout.strip().split("\n")
68
-
69
- # 过滤掉进程名中包含"python"的进程
70
- python_memory_usage = 0.0
71
- for process in process_info:
72
- pid, process_name, used_memory = process.split(", ")
73
- if "python" in process_name.lower():
74
- try:
75
- python_memory_usage += float(used_memory)
76
- except:
77
- pass
78
- print("total_free_vram_memory: ", total_free_memory)
79
- print("python_vram_memory_usage: ", python_memory_usage)
80
- # 计算排除python进程后的总空闲内存
81
- total_free_memory -= python_memory_usage
82
- return round(total_free_memory / 1024, 2)
56
+ return round(total_memory / 1024, 2)
83
57
  except Exception as e:
84
58
  print(f"Error getting VRAM resources: {e}")
85
59
  return 0.0
@@ -114,33 +88,25 @@ def reserve_vram_retry(gb, retry=None, uid=None):
114
88
  retry = sys.maxsize
115
89
  for i in range(retry):
116
90
  time.sleep(1)
117
- if i % 10 == 0 or i < 10:
91
+ if i % 10 == 0 or i < 10 and i != 0:
118
92
  print(f"重试第{i}次")
119
93
  if reserve_vram(gb, uid):
120
94
  return True
121
95
  return False
122
96
 
123
97
 
124
- def release_vram(uid=None):
98
+ def unreserve_vram(uid=None):
125
99
  if uid is None:
126
100
  uid = f"pid:{os.getpid()}"
127
101
  with sqlite3.connect(DATABASE_PATH) as conn:
128
102
  cursor = conn.cursor()
129
103
  cursor.execute(f"DELETE FROM {TABLE_NAME} WHERE uid = ?", (uid,))
130
104
  conn.commit()
131
- # 计算释放后的剩余VRAM大小
132
- cursor.execute(f"SELECT SUM(reserved_gb) FROM {TABLE_NAME}")
133
- total_reserved = cursor.fetchone()[0]
134
- if total_reserved is None:
135
- total_reserved = 0.0
136
- available_gb = get_vram_resources() - total_reserved
137
- print(f"释放成功,剩余VRAM大小: {available_gb} GB")
138
105
 
139
106
 
140
107
  # 注册退出时的清理函数
141
108
  def cleanup():
142
- release_vram()
143
- print("程序退出,VRAM资源已释放")
109
+ unreserve_vram()
144
110
 
145
111
 
146
112
  def initialize_and_check():
@@ -64,23 +64,8 @@ def create_openai_func_call_agent_executor(
64
64
  last_message = messages[-1]
65
65
  if last_message.content.strip().endswith("```"):
66
66
  last_message.content = last_message.content + "\n\n" # 避免影响阅读
67
- # if not last_message.tool_calls:
68
- # if (
69
- # "接下来我将" in last_message.content
70
- # or "接下来,我将" in last_message.content
71
- # ):
72
- # print("deepseek的bug: “接下来我将” 模式,使用a_delay_function骗过llm")
73
- # last_message.additional_kwargs["tool_calls"] = (
74
- # last_message.tool_calls
75
- # ) = [
76
- # {
77
- # "function": {"name": "a_delay_function", "arguments": "{}"},
78
- # "id": random.randint(0, 1000000),
79
- # }
80
- # ]
81
- # return "continue"
82
67
  if '"name"' in last_message.content and '"parameters":' in last_message.content:
83
- print("deepseek的bug: name 和 paremeters 模式")
68
+ print("name 和 paremeters 模式")
84
69
  all_json = get_all_markdown_json(last_message.content)
85
70
  tool_calls = []
86
71
  for tool_call in all_json:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pycoze
3
- Version: 0.1.88
3
+ Version: 0.1.90
4
4
  Summary: Package for pycoze only!
5
5
  Author: Yuan Jie Xiong
6
6
  Author-email: aiqqqqqqq@qq.com
@@ -10,7 +10,6 @@ pycoze.egg-info/top_level.txt
10
10
  pycoze/access/__init__.py
11
11
  pycoze/access/tool_for_bot.py
12
12
  pycoze/ai/__init__.py
13
- pycoze/ai/comfyui.py
14
13
  pycoze/ai/vram_reserve.py
15
14
  pycoze/bot/__init__.py
16
15
  pycoze/bot/bot.py
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name="pycoze",
5
- version="0.1.88",
5
+ version="0.1.90",
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
@@ -1,33 +0,0 @@
1
- from .vram_reserve import reserve_vram_retry, release_vram
2
-
3
-
4
- class ComfyUI:
5
- def __init__(self, file_path):
6
- self.file_path = file_path
7
-
8
- def load(self):
9
- reserve_vram_retry(20) # 20GB VRAM
10
- with open(self.file_path, "r") as file:
11
- return file.read()
12
-
13
- def __exit__(self, exc_type, exc_value, traceback):
14
- clear_memory()
15
- return None
16
-
17
- def unload(self):
18
- clear_memory()
19
- return None
20
-
21
-
22
- def clear_memory():
23
- import requests
24
- import json
25
-
26
- release_vram()
27
-
28
- url = "http://127.0.0.1:8188/free"
29
- data = {"unload_models": True, "free_memory": False}
30
- response = requests.post(
31
- url, data=json.dumps(data), headers={"Content-Type": "application/json"}
32
- )
33
- return response.status_code, response.text
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
File without changes