pycoze 0.1.88__py3-none-any.whl → 0.1.90__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pycoze/ai/__init__.py +1 -1
- pycoze/ai/vram_reserve.py +9 -43
- pycoze/bot/agent/agent_types/openai_func_call_agent.py +1 -16
- {pycoze-0.1.88.dist-info → pycoze-0.1.90.dist-info}/METADATA +1 -1
- {pycoze-0.1.88.dist-info → pycoze-0.1.90.dist-info}/RECORD +8 -9
- pycoze/ai/comfyui.py +0 -33
- {pycoze-0.1.88.dist-info → pycoze-0.1.90.dist-info}/LICENSE +0 -0
- {pycoze-0.1.88.dist-info → pycoze-0.1.90.dist-info}/WHEEL +0 -0
- {pycoze-0.1.88.dist-info → pycoze-0.1.90.dist-info}/top_level.txt +0 -0
pycoze/ai/__init__.py
CHANGED
@@ -1 +1 @@
|
|
1
|
-
from .vram_reserve import
|
1
|
+
from .vram_reserve import reserve_vram, reserve_vram_retry, unreserve_vram
|
pycoze/ai/vram_reserve.py
CHANGED
@@ -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.
|
45
|
+
["nvidia-smi", "--query-gpu=memory.total", "--format=csv,noheader,nounits"],
|
46
46
|
stdout=subprocess.PIPE,
|
47
47
|
text=True,
|
48
48
|
)
|
49
|
-
|
50
|
-
|
51
|
-
for mem in
|
49
|
+
total_memory_list = result.stdout.strip().split("\n")
|
50
|
+
total_memory = 0
|
51
|
+
for mem in total_memory_list:
|
52
52
|
try:
|
53
|
-
|
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
|
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
|
-
|
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("
|
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:
|
@@ -2,9 +2,8 @@ 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=
|
6
|
-
pycoze/ai/
|
7
|
-
pycoze/ai/vram_reserve.py,sha256=s55Cy-Q5mTq-k5oIPbAFwCfrjatjN0QTjQxW7WBTPZI,5738
|
5
|
+
pycoze/ai/__init__.py,sha256=odM2lgYSnApxw4AzLV_5AyaxL5_MLfydOSB1VmLGFyA,75
|
6
|
+
pycoze/ai/vram_reserve.py,sha256=QbqaA8qv87cnEpOVDMygi0BNMxuhLYwj1UKfR_D5BD4,4340
|
8
7
|
pycoze/bot/__init__.py,sha256=6HHMxDQVOyZM9dtSjQm9tjGnhj4h7CixD0JOvEwTi48,41
|
9
8
|
pycoze/bot/bot.py,sha256=w_ddp3IeWryUgIad-_V-SsDzGwYqZXekw5NXbYyXrkk,3041
|
10
9
|
pycoze/bot/agent/__init__.py,sha256=YR9vpkEQn1e4937r_xFPJXUCPBEJ0SFzEQDBe2x3-YA,157
|
@@ -12,7 +11,7 @@ pycoze/bot/agent/agent.py,sha256=XMTO6s8OJpaOnymT8ZUuJxXx2ICZ3r7Ck0pHJqPPFIs,334
|
|
12
11
|
pycoze/bot/agent/assistant.py,sha256=XI4w-rFfbk3qYE0tWcWoya8dz-3cA-QZ0Sanhl3DbKE,1112
|
13
12
|
pycoze/bot/agent/chat.py,sha256=kc0qgcrBSXdiMy49JwThZTV-0PAvzAhiUvbI5ILiSnU,571
|
14
13
|
pycoze/bot/agent/agent_types/__init__.py,sha256=XNvKWq9REE5Wzjm0OZi3CKIQF2UZ9PZkeUuxgFJbrfc,128
|
15
|
-
pycoze/bot/agent/agent_types/openai_func_call_agent.py,sha256=
|
14
|
+
pycoze/bot/agent/agent_types/openai_func_call_agent.py,sha256=nqyHEZVSqxFlfjraeWJ1up4IGZFZSaZB2rlzhVheKbw,6877
|
16
15
|
pycoze/ui/__init__.py,sha256=7xAfL2lfG7-jllPJEZUJO89xUE9sNzvo1y0WmBswjBI,458
|
17
16
|
pycoze/ui/base.py,sha256=SCXVDK7PpMaBv6ovvabHcfRq_d2AWM0BRyxpNhuJN5A,1285
|
18
17
|
pycoze/ui/color.py,sha256=cT9Ib8uNzkOKxyW0IwVj46o4LwdB1xgNCj1_Rou9d_4,854
|
@@ -21,8 +20,8 @@ pycoze/ui/ui_def.py,sha256=UhhU_yB3GV9ISbvTWT48hsHPHI250BhMILh6bu5Uioo,4206
|
|
21
20
|
pycoze/utils/__init__.py,sha256=TNJhFfY7JYdLlzuP9GvgxfNXUtbgH_NUUJSqHXCxJn4,78
|
22
21
|
pycoze/utils/arg.py,sha256=kA3KBQzXc2WlH5XbF8kfikfpqljiKaW7oY_GE4Qyffc,753
|
23
22
|
pycoze/utils/text_or_file.py,sha256=gpxZVWt2DW6YiEg_MnMuwg36VNf3TX383QD_1oZNB0Y,551
|
24
|
-
pycoze-0.1.
|
25
|
-
pycoze-0.1.
|
26
|
-
pycoze-0.1.
|
27
|
-
pycoze-0.1.
|
28
|
-
pycoze-0.1.
|
23
|
+
pycoze-0.1.90.dist-info/LICENSE,sha256=QStd_Qsd0-kAam_-sOesCIp_uKrGWeoKwt9M49NVkNU,1090
|
24
|
+
pycoze-0.1.90.dist-info/METADATA,sha256=zoj2vDA5bs0HUR12_2UExkLzufmpRv_srUQ2UUu_c2s,719
|
25
|
+
pycoze-0.1.90.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
|
26
|
+
pycoze-0.1.90.dist-info/top_level.txt,sha256=76dPeDhKvOCleL3ZC5gl1-y4vdS1tT_U1hxWVAn7sFo,7
|
27
|
+
pycoze-0.1.90.dist-info/RECORD,,
|
pycoze/ai/comfyui.py
DELETED
@@ -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
|