beswarm 0.1.84__py3-none-any.whl → 0.1.85__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.
- beswarm/tools/worker.py +18 -5
- beswarm/utils.py +22 -0
- {beswarm-0.1.84.dist-info → beswarm-0.1.85.dist-info}/METADATA +1 -1
- {beswarm-0.1.84.dist-info → beswarm-0.1.85.dist-info}/RECORD +6 -6
- {beswarm-0.1.84.dist-info → beswarm-0.1.85.dist-info}/WHEEL +0 -0
- {beswarm-0.1.84.dist-info → beswarm-0.1.85.dist-info}/top_level.txt +0 -0
beswarm/tools/worker.py
CHANGED
@@ -3,12 +3,13 @@ import re
|
|
3
3
|
import copy
|
4
4
|
import json
|
5
5
|
import platform
|
6
|
+
from pathlib import Path
|
6
7
|
from datetime import datetime
|
7
8
|
|
8
9
|
from ..aient.src.aient.models import chatgpt
|
9
10
|
from ..aient.src.aient.plugins import register_tool, get_function_call_list
|
10
11
|
from ..prompt import worker_system_prompt, instruction_system_prompt
|
11
|
-
from ..utils import extract_xml_content, get_current_screen_image_message
|
12
|
+
from ..utils import extract_xml_content, get_current_screen_image_message, replace_xml_content
|
12
13
|
|
13
14
|
@register_tool()
|
14
15
|
async def worker(goal, tools, work_dir, cache_messages=None):
|
@@ -48,7 +49,13 @@ async def worker(goal, tools, work_dir, cache_messages=None):
|
|
48
49
|
"function_call_max_loop": 100,
|
49
50
|
}
|
50
51
|
if cache_messages:
|
51
|
-
|
52
|
+
if isinstance(cache_messages, bool) and cache_messages == True:
|
53
|
+
cache_file_path = Path(work_dir) / ".beswarm" / "work_agent_conversation_history.json"
|
54
|
+
if cache_file_path.exists():
|
55
|
+
with cache_file_path.open("r", encoding="utf-8") as f:
|
56
|
+
cache_messages = json.load(f)
|
57
|
+
first_user_message = replace_xml_content(cache_messages[1]["content"], "goal", goal)
|
58
|
+
work_agent_config["cache_messages"] = cache_messages[0:1] + [{"role": "user", "content": first_user_message}] + cache_messages[2:]
|
52
59
|
|
53
60
|
instruction_agent_config = {
|
54
61
|
"api_key": os.getenv("API_KEY"),
|
@@ -131,7 +138,7 @@ async def worker(goal, tools, work_dir, cache_messages=None):
|
|
131
138
|
if conversation_history == []:
|
132
139
|
next_instruction = (
|
133
140
|
"任务描述:\n"
|
134
|
-
f"{goal}
|
141
|
+
f"<goal>{goal}</goal>\n\n"
|
135
142
|
"现在开始执行第一步:\n"
|
136
143
|
f"{next_instruction}"
|
137
144
|
)
|
@@ -186,7 +193,13 @@ async def worker_gen(goal, tools, work_dir, cache_messages=None):
|
|
186
193
|
"function_call_max_loop": 100,
|
187
194
|
}
|
188
195
|
if cache_messages:
|
189
|
-
|
196
|
+
if isinstance(cache_messages, bool) and cache_messages == True:
|
197
|
+
cache_file_path = Path(work_dir) / ".beswarm" / "work_agent_conversation_history.json"
|
198
|
+
if cache_file_path.exists():
|
199
|
+
with cache_file_path.open("r", encoding="utf-8") as f:
|
200
|
+
cache_messages = json.load(f)
|
201
|
+
first_user_message = replace_xml_content(cache_messages[1]["content"], "goal", goal)
|
202
|
+
work_agent_config["cache_messages"] = cache_messages[0:1] + [{"role": "user", "content": first_user_message}] + cache_messages[2:]
|
190
203
|
|
191
204
|
instruction_agent_config = {
|
192
205
|
"api_key": os.getenv("API_KEY"),
|
@@ -270,7 +283,7 @@ async def worker_gen(goal, tools, work_dir, cache_messages=None):
|
|
270
283
|
if conversation_history == []:
|
271
284
|
next_instruction = (
|
272
285
|
"任务描述:\n"
|
273
|
-
f"{goal}
|
286
|
+
f"<goal>{goal}</goal>\n\n"
|
274
287
|
"现在开始执行第一步:\n"
|
275
288
|
f"{next_instruction}"
|
276
289
|
)
|
beswarm/utils.py
CHANGED
@@ -10,6 +10,28 @@ def extract_xml_content(text, xml_tag):
|
|
10
10
|
return ''
|
11
11
|
return result
|
12
12
|
|
13
|
+
def replace_xml_content(original_string: str, tag_name: str, replacement_content: str) -> str:
|
14
|
+
"""
|
15
|
+
将指定XML标签内的内容替换为新内容。
|
16
|
+
|
17
|
+
此函数使用正则表达式查找所有匹配的XML标签对(例如 `<tag>...</tag>`),
|
18
|
+
并将其中的内容替换为 `replacement_content`。
|
19
|
+
|
20
|
+
Args:
|
21
|
+
original_string (str): 包含XML标记的原始字符串。
|
22
|
+
tag_name (str): 要定位的XML标签的名称(不带尖括号)。
|
23
|
+
replacement_content (str): 用于替换标签内部内容的新字符串。
|
24
|
+
|
25
|
+
Returns:
|
26
|
+
str: 返回内容已被替换的新字符串。如果未找到匹配的标签,则返回原始字符串。
|
27
|
+
"""
|
28
|
+
pattern = f"<{tag_name}>.*?<\\/{tag_name}>"
|
29
|
+
replacement = f"<{tag_name}>{replacement_content}</{tag_name}>"
|
30
|
+
|
31
|
+
new_string = re.sub(pattern, replacement, original_string, flags=re.DOTALL)
|
32
|
+
|
33
|
+
return new_string
|
34
|
+
|
13
35
|
import io
|
14
36
|
import base64
|
15
37
|
from .aient.src.aient.core.utils import get_image_message, get_text_message
|
@@ -1,6 +1,6 @@
|
|
1
1
|
beswarm/__init__.py,sha256=HZjUOJtZR5QhMuDbq-wukQQn1VrBusNWai_ysGo-VVI,20
|
2
2
|
beswarm/prompt.py,sha256=1jNxVXjfhb-A8CVHoudRxytV4qDT6FZIIk1NRCCE1Ns,31365
|
3
|
-
beswarm/utils.py,sha256=
|
3
|
+
beswarm/utils.py,sha256=cOYwuONpNG_dkSYIvdEqQOxRUdIy0Bh9CTYkvKKskdw,2816
|
4
4
|
beswarm/aient/main.py,sha256=SiYAIgQlLJqYusnTVEJOx1WNkSJKMImhgn5aWjfroxg,3814
|
5
5
|
beswarm/aient/setup.py,sha256=ub3Tx7R0rcvHG9bJy7qp-mDWUjcxJJ3yQm8jpOtx8AY,487
|
6
6
|
beswarm/aient/src/aient/__init__.py,sha256=SRfF7oDVlOOAi6nGKiJIUK6B_arqYLO9iSMp-2IZZps,21
|
@@ -128,8 +128,8 @@ beswarm/tools/screenshot.py,sha256=u6t8FCgW5YHJ_Oc4coo8e0F3wTusWE_-H8dFh1rBq9Q,1
|
|
128
128
|
beswarm/tools/search_arxiv.py,sha256=GpuIOYX8T0iRC-X-hmuR9AUJVn15WWZq864DaoC7BUc,8004
|
129
129
|
beswarm/tools/search_web.py,sha256=B24amOnGHnmdV_6S8bw8O2PdhZRRIDtJjg-wXcfP7dQ,11859
|
130
130
|
beswarm/tools/think.py,sha256=WLw-7jNIsnS6n8MMSYUin_f-BGLENFmnKM2LISEp0co,1760
|
131
|
-
beswarm/tools/worker.py,sha256=
|
132
|
-
beswarm-0.1.
|
133
|
-
beswarm-0.1.
|
134
|
-
beswarm-0.1.
|
135
|
-
beswarm-0.1.
|
131
|
+
beswarm/tools/worker.py,sha256=BfaU_iBDN4XrueCWkvBtpgcHva95e9X26T8HVNVDynY,15569
|
132
|
+
beswarm-0.1.85.dist-info/METADATA,sha256=1Vtaw1TKQI8N3yi1xyqYZH018FvC_xdMaDeaceql9Lk,3553
|
133
|
+
beswarm-0.1.85.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
134
|
+
beswarm-0.1.85.dist-info/top_level.txt,sha256=pJw4O87wvt5882smuSO6DfByJz7FJ8SxxT8h9fHCmpo,8
|
135
|
+
beswarm-0.1.85.dist-info/RECORD,,
|
File without changes
|
File without changes
|