pycoze 0.1.73__tar.gz → 0.1.75__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.73 → pycoze-0.1.75}/PKG-INFO +1 -1
  2. {pycoze-0.1.73/pycoze/gpu → pycoze-0.1.75/pycoze/ai}/__init__.py +1 -1
  3. {pycoze-0.1.73/pycoze/gpu → pycoze-0.1.75/pycoze/ai}/gpu_reserve.py +31 -20
  4. {pycoze-0.1.73 → pycoze-0.1.75}/pycoze/bot/agent/agent_types/openai_func_call_agent.py +11 -6
  5. {pycoze-0.1.73 → pycoze-0.1.75}/pycoze/ui/base.py +1 -6
  6. {pycoze-0.1.73 → pycoze-0.1.75}/pycoze.egg-info/PKG-INFO +1 -1
  7. {pycoze-0.1.73 → pycoze-0.1.75}/pycoze.egg-info/SOURCES.txt +2 -2
  8. {pycoze-0.1.73 → pycoze-0.1.75}/setup.py +1 -1
  9. {pycoze-0.1.73 → pycoze-0.1.75}/LICENSE +0 -0
  10. {pycoze-0.1.73 → pycoze-0.1.75}/README.md +0 -0
  11. {pycoze-0.1.73 → pycoze-0.1.75}/pycoze/__init__.py +0 -0
  12. {pycoze-0.1.73 → pycoze-0.1.75}/pycoze/access/__init__.py +0 -0
  13. {pycoze-0.1.73 → pycoze-0.1.75}/pycoze/access/tool_for_bot.py +0 -0
  14. {pycoze-0.1.73 → pycoze-0.1.75}/pycoze/bot/__init__.py +0 -0
  15. {pycoze-0.1.73 → pycoze-0.1.75}/pycoze/bot/agent/__init__.py +0 -0
  16. {pycoze-0.1.73 → pycoze-0.1.75}/pycoze/bot/agent/agent.py +0 -0
  17. {pycoze-0.1.73 → pycoze-0.1.75}/pycoze/bot/agent/agent_types/__init__.py +0 -0
  18. {pycoze-0.1.73 → pycoze-0.1.75}/pycoze/bot/agent/agent_types/react_agent.py +0 -0
  19. {pycoze-0.1.73 → pycoze-0.1.75}/pycoze/bot/agent/agent_types/react_prompt.py +0 -0
  20. {pycoze-0.1.73 → pycoze-0.1.75}/pycoze/bot/agent/assistant.py +0 -0
  21. {pycoze-0.1.73 → pycoze-0.1.75}/pycoze/bot/agent/chat.py +0 -0
  22. {pycoze-0.1.73 → pycoze-0.1.75}/pycoze/bot/bot.py +0 -0
  23. {pycoze-0.1.73 → pycoze-0.1.75}/pycoze/module.py +0 -0
  24. {pycoze-0.1.73 → pycoze-0.1.75}/pycoze/ui/__init__.py +0 -0
  25. {pycoze-0.1.73 → pycoze-0.1.75}/pycoze/ui/color.py +0 -0
  26. {pycoze-0.1.73 → pycoze-0.1.75}/pycoze/ui/typ.py +0 -0
  27. {pycoze-0.1.73 → pycoze-0.1.75}/pycoze/ui/ui_def.py +0 -0
  28. {pycoze-0.1.73 → pycoze-0.1.75}/pycoze/utils/__init__.py +0 -0
  29. {pycoze-0.1.73 → pycoze-0.1.75}/pycoze/utils/arg.py +0 -0
  30. {pycoze-0.1.73 → pycoze-0.1.75}/pycoze/utils/text_or_file.py +0 -0
  31. {pycoze-0.1.73 → pycoze-0.1.75}/pycoze.egg-info/dependency_links.txt +0 -0
  32. {pycoze-0.1.73 → pycoze-0.1.75}/pycoze.egg-info/top_level.txt +0 -0
  33. {pycoze-0.1.73 → pycoze-0.1.75}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pycoze
3
- Version: 0.1.73
3
+ Version: 0.1.75
4
4
  Summary: Package for pycoze only!
5
5
  Author: Yuan Jie Xiong
6
6
  Author-email: aiqqqqqqq@qq.com
@@ -1 +1 @@
1
- from .gpu_reserve import reserve_gpu_retry, release_gpu, reserve_gpu_retry
1
+ from .gpu_reserve import reserve_gpu_retry, release_gpu, reserve_gpu
@@ -29,7 +29,7 @@ def initialize_db():
29
29
  f"""
30
30
  CREATE TABLE IF NOT EXISTS {TABLE_NAME} (
31
31
  id INTEGER PRIMARY KEY,
32
- process_id TEXT NOT NULL,
32
+ uid TEXT NOT NULL,
33
33
  reserved_gb REAL NOT NULL
34
34
  )
35
35
  """
@@ -48,7 +48,12 @@ def get_gpu_resources():
48
48
  text=True,
49
49
  )
50
50
  free_memory = result.stdout.strip().split("\n")
51
- total_free_memory = sum(float(mem) for mem in free_memory)
51
+ total_free_memory = 0
52
+ for mem in free_memory:
53
+ try:
54
+ total_free_memory += float(mem)
55
+ except:
56
+ pass
52
57
 
53
58
  # 获取正在使用GPU的进程信息
54
59
  process_result = subprocess.run(
@@ -67,8 +72,12 @@ def get_gpu_resources():
67
72
  for process in process_info:
68
73
  pid, process_name, used_memory = process.split(", ")
69
74
  if "python" in process_name.lower():
70
- python_memory_usage += float(used_memory)
71
-
75
+ try:
76
+ python_memory_usage += float(used_memory)
77
+ except:
78
+ pass
79
+ print("total_free_gpu_memory: ", total_free_memory)
80
+ print("python_gpu_memory_usage: ", python_memory_usage)
72
81
  # 计算排除python进程后的总空闲内存
73
82
  total_free_memory -= python_memory_usage
74
83
  return round(total_free_memory / 1024, 2)
@@ -78,8 +87,9 @@ def get_gpu_resources():
78
87
 
79
88
 
80
89
  # 预留GPU资源
81
- def reserve_gpu(gb):
82
- process_id = str(os.getpid())
90
+ def reserve_gpu(gb, uid=None):
91
+ if uid is None:
92
+ uid = f"pid:{os.getpid()}"
83
93
  with sqlite3.connect(DATABASE_PATH) as conn:
84
94
  cursor = conn.cursor()
85
95
  cursor.execute(f"SELECT SUM(reserved_gb) FROM {TABLE_NAME}")
@@ -89,8 +99,8 @@ def reserve_gpu(gb):
89
99
  available_gb = get_gpu_resources() - total_reserved
90
100
  if available_gb >= gb:
91
101
  cursor.execute(
92
- f"INSERT INTO {TABLE_NAME} (process_id, reserved_gb) VALUES (?, ?)",
93
- (process_id, gb),
102
+ f"INSERT INTO {TABLE_NAME} (uid, reserved_gb) VALUES (?, ?)",
103
+ (uid, gb),
94
104
  )
95
105
  conn.commit()
96
106
  print(f"预留成功,剩余GPU大小: {available_gb - gb} GB")
@@ -100,7 +110,7 @@ def reserve_gpu(gb):
100
110
  return False
101
111
 
102
112
 
103
- def reserve_gpu_retry(gb, retry=None):
113
+ def reserve_gpu_retry(gb, retry=None, uid=None):
104
114
  if retry is None:
105
115
  # 接近无限重试,python中允许无限大的整数,尽管sys.maxsize不是真正的无限大,但足够大
106
116
  retry = sys.maxsize
@@ -108,17 +118,18 @@ def reserve_gpu_retry(gb, retry=None):
108
118
  time.sleep(1)
109
119
  if i % 10 == 0 or i < 10:
110
120
  print(f"重试第{i}次")
111
- if reserve_gpu(gb):
121
+ if reserve_gpu(gb, uid):
112
122
  return True
113
123
  return False
114
124
 
115
125
 
116
126
  # 释放GPU资源
117
- def release_gpu():
118
- process_id = str(os.getpid())
127
+ def release_gpu(uid=None):
128
+ if uid is None:
129
+ uid = f"pid:{os.getpid()}"
119
130
  with sqlite3.connect(DATABASE_PATH) as conn:
120
131
  cursor = conn.cursor()
121
- cursor.execute(f"DELETE FROM {TABLE_NAME} WHERE process_id = ?", (process_id,))
132
+ cursor.execute(f"DELETE FROM {TABLE_NAME} WHERE uid = ?", (uid,))
122
133
  conn.commit()
123
134
  # 计算释放后的剩余GPU大小
124
135
  cursor.execute(f"SELECT SUM(reserved_gb) FROM {TABLE_NAME}")
@@ -139,19 +150,19 @@ def initialize_and_check():
139
150
  initialize_db()
140
151
  with sqlite3.connect(DATABASE_PATH) as conn:
141
152
  cursor = conn.cursor()
142
- cursor.execute(f"SELECT process_id, reserved_gb FROM {TABLE_NAME}")
153
+ cursor.execute(f"SELECT uid, reserved_gb FROM {TABLE_NAME}")
143
154
  rows = cursor.fetchall()
144
155
  for row in rows:
145
- process_id, reserved_gb = row
156
+ uid, reserved_gb = row
146
157
  try:
147
158
  # 检查进程是否存在
148
- psutil.Process(int(process_id))
159
+ if uid.startswith("pid:"):
160
+ pid = int(uid.split(":")[1])
161
+ psutil.Process(pid)
149
162
  except psutil.NoSuchProcess:
150
163
  # 进程不存在,删除对应的记录
151
- cursor.execute(
152
- f"DELETE FROM {TABLE_NAME} WHERE process_id = ?", (process_id,)
153
- )
154
- print(f"进程 {process_id} 不存在,已删除对应的预留记录")
164
+ cursor.execute(f"DELETE FROM {TABLE_NAME} WHERE uid = ?", (uid,))
165
+ print(f"进程 {uid} 不存在,已删除对应的预留记录")
155
166
  conn.commit()
156
167
 
157
168
 
@@ -150,16 +150,21 @@ def create_openai_func_call_agent_executor(
150
150
  # We call the tool_executor and get back a response
151
151
  responses = await tool_executor.abatch(actions, **kwargs)
152
152
  # We use the response to create a ToolMessage
153
- tool_messages = [
154
- ToolMessage(
153
+ tool_messages = []
154
+ for tool_call, response in zip(
155
+ last_message.additional_kwargs["tool_calls"], responses
156
+ ):
157
+ if not isinstance(response, (str, int, float, bool, list, tuple)):
158
+ response = repr(
159
+ response
160
+ ) # 不支持其他类型,包括dict也不支持,因此需要转换为字符串
161
+
162
+ message = ToolMessage(
155
163
  tool_call_id=tool_call["id"],
156
164
  content=response,
157
165
  additional_kwargs={"name": tool_call["function"]["name"]},
158
166
  )
159
- for tool_call, response in zip(
160
- last_message.additional_kwargs["tool_calls"], responses
161
- )
162
- ]
167
+ tool_messages.append(message)
163
168
  return tool_messages
164
169
 
165
170
  workflow = MessageGraph()
@@ -40,12 +40,7 @@ def get_ui():
40
40
  return json.load(f)
41
41
  else:
42
42
  assert by == "workflow"
43
- workflow_file = params["uiData"]["workflowFile"]
44
- node_id = params["uiData"]["nodeId"]
45
- with open(workflow_file, "r", encoding="utf-8") as f:
46
- cells = json.load(f)["graph"]["cells"]
47
- node = [cell for cell in cells if cell["id"] == node_id][0]
48
- return json.loads(node["data"]["ui"])
43
+ return params["uiData"]["uiRecord"][match_ui_file]
49
44
  except Exception as e:
50
45
  if i == 9:
51
46
  raise e
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pycoze
3
- Version: 0.1.73
3
+ Version: 0.1.75
4
4
  Summary: Package for pycoze only!
5
5
  Author: Yuan Jie Xiong
6
6
  Author-email: aiqqqqqqq@qq.com
@@ -9,6 +9,8 @@ pycoze.egg-info/dependency_links.txt
9
9
  pycoze.egg-info/top_level.txt
10
10
  pycoze/access/__init__.py
11
11
  pycoze/access/tool_for_bot.py
12
+ pycoze/ai/__init__.py
13
+ pycoze/ai/gpu_reserve.py
12
14
  pycoze/bot/__init__.py
13
15
  pycoze/bot/bot.py
14
16
  pycoze/bot/agent/__init__.py
@@ -19,8 +21,6 @@ pycoze/bot/agent/agent_types/__init__.py
19
21
  pycoze/bot/agent/agent_types/openai_func_call_agent.py
20
22
  pycoze/bot/agent/agent_types/react_agent.py
21
23
  pycoze/bot/agent/agent_types/react_prompt.py
22
- pycoze/gpu/__init__.py
23
- pycoze/gpu/gpu_reserve.py
24
24
  pycoze/ui/__init__.py
25
25
  pycoze/ui/base.py
26
26
  pycoze/ui/color.py
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name="pycoze",
5
- version="0.1.73",
5
+ version="0.1.75",
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