aient 1.1.32__py3-none-any.whl → 1.1.33__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.
- aient/models/chatgpt.py +2 -2
- aient/utils/scripts.py +40 -9
- {aient-1.1.32.dist-info → aient-1.1.33.dist-info}/METADATA +1 -1
- {aient-1.1.32.dist-info → aient-1.1.33.dist-info}/RECORD +7 -7
- {aient-1.1.32.dist-info → aient-1.1.33.dist-info}/WHEEL +0 -0
- {aient-1.1.32.dist-info → aient-1.1.33.dist-info}/licenses/LICENSE +0 -0
- {aient-1.1.32.dist-info → aient-1.1.33.dist-info}/top_level.txt +0 -0
aient/models/chatgpt.py
CHANGED
@@ -12,7 +12,7 @@ from pathlib import Path
|
|
12
12
|
|
13
13
|
from .base import BaseLLM
|
14
14
|
from ..plugins import PLUGINS, get_tools_result_async, function_call_list, update_tools_config
|
15
|
-
from ..utils.scripts import safe_get, async_generator_to_sync, parse_function_xml, parse_continuous_json, convert_functions_to_xml
|
15
|
+
from ..utils.scripts import safe_get, async_generator_to_sync, parse_function_xml, parse_continuous_json, convert_functions_to_xml, remove_xml_tags_and_content
|
16
16
|
from ..core.request import prepare_request_payload
|
17
17
|
from ..core.response import fetch_response_stream
|
18
18
|
|
@@ -465,7 +465,7 @@ class chatgpt(BaseLLM):
|
|
465
465
|
if isinstance(self.conversation[convo_id][-1]["content"], str) and \
|
466
466
|
"<tool_error>" in self.conversation[convo_id][-1]["content"]:
|
467
467
|
need_function_call = False
|
468
|
-
full_response = "接下来我需要做什么?"
|
468
|
+
full_response = remove_xml_tags_and_content(full_response) + "上面是我的分析,还没有实际行动。\n\n接下来我需要做什么?"
|
469
469
|
else:
|
470
470
|
need_function_call = False
|
471
471
|
if self.print_log:
|
aient/utils/scripts.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
import os
|
2
|
+
import re
|
2
3
|
import json
|
3
4
|
import requests
|
4
5
|
import urllib.parse
|
@@ -148,6 +149,35 @@ def safe_get(data, *keys, default=None):
|
|
148
149
|
return default
|
149
150
|
return data
|
150
151
|
|
152
|
+
def remove_xml_tags_and_content(text: str) -> str:
|
153
|
+
"""
|
154
|
+
删除字符串中所有的XML标签及其包裹的内容。
|
155
|
+
这个函数通过迭代地移除最内层的标签来处理嵌套标签和自闭合标签。
|
156
|
+
|
157
|
+
Args:
|
158
|
+
text: 包含XML标签的输入字符串。
|
159
|
+
|
160
|
+
Returns:
|
161
|
+
清理掉XML标签和内容后的字符串。
|
162
|
+
"""
|
163
|
+
# 正则表达式匹配成对的标签及其内容(非贪婪模式)以及自闭合标签
|
164
|
+
# 捕获组 \1 用于确保开始和结束标签名匹配
|
165
|
+
pair_pattern = r'<([a-zA-Z0-9_:]+)\b[^>]*>.*?</\1>'
|
166
|
+
self_closing_pattern = r'<[^>/]+/>'
|
167
|
+
|
168
|
+
cleaned_text = text
|
169
|
+
while True:
|
170
|
+
# 使用 re.sub 替换所有非重叠的匹配项
|
171
|
+
new_text = re.sub(pair_pattern, '', cleaned_text, flags=re.DOTALL)
|
172
|
+
new_text = re.sub(self_closing_pattern, '', new_text)
|
173
|
+
|
174
|
+
# 如果没有更多内容被移除,则退出循环
|
175
|
+
if new_text == cleaned_text:
|
176
|
+
break
|
177
|
+
cleaned_text = new_text
|
178
|
+
|
179
|
+
return cleaned_text.strip()
|
180
|
+
|
151
181
|
import asyncio
|
152
182
|
def async_generator_to_sync(async_gen):
|
153
183
|
"""
|
@@ -919,14 +949,15 @@ if __name__ == "__main__":
|
|
919
949
|
|
920
950
|
请提供前两个 `excute_command` 的执行结果。
|
921
951
|
"""
|
922
|
-
|
923
|
-
好的,我现在执行第一步。
|
924
|
-
<tools>
|
925
|
-
<list_directory>
|
926
|
-
<path>/Downloads/GitHub/beswarm/work/test</path>
|
927
|
-
</list_directory>
|
928
|
-
</tools>
|
929
|
-
"""
|
930
|
-
print(parse_function_xml(test_xml))
|
952
|
+
# test_xml = """
|
953
|
+
# 好的,我现在执行第一步。
|
954
|
+
# <tools>
|
955
|
+
# <list_directory>
|
956
|
+
# <path>/Downloads/GitHub/beswarm/work/test</path>
|
957
|
+
# </list_directory>
|
958
|
+
# </tools>
|
959
|
+
# """
|
960
|
+
# print(parse_function_xml(test_xml))
|
961
|
+
print(remove_xml_tags_and_content(test_xml))
|
931
962
|
|
932
963
|
# 运行本文件:python -m beswarm.aient.src.aient.utils.scripts
|
@@ -14,7 +14,7 @@ aient/core/test/test_payload.py,sha256=8jBiJY1uidm1jzL-EiK0s6UGmW9XkdsuuKFGrwFhF
|
|
14
14
|
aient/models/__init__.py,sha256=ouNDNvoBBpIFrLsk09Q_sq23HR0GbLAKfGLIFmfEuXE,219
|
15
15
|
aient/models/audio.py,sha256=kRd-8-WXzv4vwvsTGwnstK-WR8--vr9CdfCZzu8y9LA,1934
|
16
16
|
aient/models/base.py,sha256=z-Z0pJfTN2x0cuwfvu0BdMRY9O-RmLwHEnBIJN1x4Fg,6719
|
17
|
-
aient/models/chatgpt.py,sha256=
|
17
|
+
aient/models/chatgpt.py,sha256=MKCdstV_gTkcf_bT2mmQVDLgK5f4PUUfEO3_WHzahpE,46665
|
18
18
|
aient/models/claude.py,sha256=JezghW7y0brl4Y5qiSHvnYR5prQCFywX4RViHt39pGI,26037
|
19
19
|
aient/models/duckduckgo.py,sha256=1l7vYCs9SG5SWPCbcl7q6pCcB5AUF_r-a4l9frz3Ogo,8115
|
20
20
|
aient/models/gemini.py,sha256=chGLc-8G_DAOxr10HPoOhvVFW1RvMgHd6mt--VyAW98,14730
|
@@ -36,9 +36,9 @@ aient/plugins/websearch.py,sha256=FsUxM9GL4AAjmYJ8TS2jSqv4qfCAoOkCQZH59whtAXk,15
|
|
36
36
|
aient/plugins/write_file.py,sha256=7spYxloI_aUbeANEQK-oXrGPoBqSfsD7sdfMAWlNxhU,3656
|
37
37
|
aient/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
38
38
|
aient/utils/prompt.py,sha256=UcSzKkFE4-h_1b6NofI6xgk3GoleqALRKY8VBaXLjmI,11311
|
39
|
-
aient/utils/scripts.py,sha256=
|
40
|
-
aient-1.1.
|
41
|
-
aient-1.1.
|
42
|
-
aient-1.1.
|
43
|
-
aient-1.1.
|
44
|
-
aient-1.1.
|
39
|
+
aient/utils/scripts.py,sha256=8NJCASleffBsA20E3K7HvChCH6rb-7-Qa_ygXXpEsCE,37051
|
40
|
+
aient-1.1.33.dist-info/licenses/LICENSE,sha256=XNdbcWldt0yaNXXWB_Bakoqnxb3OVhUft4MgMA_71ds,1051
|
41
|
+
aient-1.1.33.dist-info/METADATA,sha256=2cPqc-MuWBbf9Mg6lujoA-Fb4fHQKuvGtc3WbaKJwKE,4968
|
42
|
+
aient-1.1.33.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
43
|
+
aient-1.1.33.dist-info/top_level.txt,sha256=3oXzrP5sAVvyyqabpeq8A2_vfMtY554r4bVE-OHBrZk,6
|
44
|
+
aient-1.1.33.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|