aient 1.1.59__py3-none-any.whl → 1.1.61__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 +72 -33
- aient/plugins/excute_command.py +1 -1
- aient/plugins/read_file.py +1 -1
- aient/plugins/websearch.py +1 -1
- aient/plugins/write_file.py +1 -1
- aient/utils/scripts.py +1 -1
- {aient-1.1.59.dist-info → aient-1.1.61.dist-info}/METADATA +1 -1
- {aient-1.1.59.dist-info → aient-1.1.61.dist-info}/RECORD +11 -11
- {aient-1.1.59.dist-info → aient-1.1.61.dist-info}/WHEEL +0 -0
- {aient-1.1.59.dist-info → aient-1.1.61.dist-info}/licenses/LICENSE +0 -0
- {aient-1.1.59.dist-info → aient-1.1.61.dist-info}/top_level.txt +0 -0
aient/models/chatgpt.py
CHANGED
@@ -17,7 +17,7 @@ from ..plugins.registry import registry
|
|
17
17
|
from ..plugins import PLUGINS, get_tools_result_async, function_call_list, update_tools_config
|
18
18
|
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
|
19
19
|
from ..core.request import prepare_request_payload
|
20
|
-
from ..core.response import fetch_response_stream
|
20
|
+
from ..core.response import fetch_response_stream, fetch_response
|
21
21
|
|
22
22
|
def get_filtered_keys_from_object(obj: object, *keys: str) -> Set[str]:
|
23
23
|
"""
|
@@ -288,6 +288,7 @@ class chatgpt(BaseLLM):
|
|
288
288
|
convo_id: str = "default",
|
289
289
|
model: str = "",
|
290
290
|
pass_history: int = 9999,
|
291
|
+
stream: bool = True,
|
291
292
|
**kwargs,
|
292
293
|
):
|
293
294
|
self.conversation[convo_id][0] = {"role": "system","content": self.system_prompt + "\n\n" + self.get_latest_file_content()}
|
@@ -309,12 +310,13 @@ class chatgpt(BaseLLM):
|
|
309
310
|
{"role": "system","content": self.system_prompt + "\n\n" + self.get_latest_file_content()},
|
310
311
|
{"role": role, "content": prompt}
|
311
312
|
],
|
312
|
-
"stream":
|
313
|
-
"stream_options": {
|
314
|
-
"include_usage": True
|
315
|
-
},
|
313
|
+
"stream": stream,
|
316
314
|
"temperature": kwargs.get("temperature", self.temperature)
|
317
315
|
}
|
316
|
+
if stream:
|
317
|
+
request_data["stream_options"] = {
|
318
|
+
"include_usage": True
|
319
|
+
}
|
318
320
|
|
319
321
|
if kwargs.get("max_tokens", self.max_tokens):
|
320
322
|
request_data["max_tokens"] = kwargs.get("max_tokens", self.max_tokens)
|
@@ -687,6 +689,7 @@ class chatgpt(BaseLLM):
|
|
687
689
|
function_call_id: str = "",
|
688
690
|
language: str = "English",
|
689
691
|
system_prompt: str = None,
|
692
|
+
stream: bool = True,
|
690
693
|
**kwargs,
|
691
694
|
):
|
692
695
|
"""
|
@@ -702,7 +705,7 @@ class chatgpt(BaseLLM):
|
|
702
705
|
json_post = None
|
703
706
|
async def get_post_body_async():
|
704
707
|
nonlocal json_post
|
705
|
-
url, headers, json_post, engine_type = await self.get_post_body(prompt, role, convo_id, model, pass_history, **kwargs)
|
708
|
+
url, headers, json_post, engine_type = await self.get_post_body(prompt, role, convo_id, model, pass_history, stream=stream, **kwargs)
|
706
709
|
return url, headers, json_post, engine_type
|
707
710
|
|
708
711
|
# 替换原来的获取请求体的代码
|
@@ -760,14 +763,24 @@ class chatgpt(BaseLLM):
|
|
760
763
|
yield f"data: {json.dumps(tmp_response)}\n\n"
|
761
764
|
async_generator = _mock_response_generator()
|
762
765
|
else:
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
766
|
+
if stream:
|
767
|
+
async_generator = fetch_response_stream(
|
768
|
+
self.aclient,
|
769
|
+
url,
|
770
|
+
headers,
|
771
|
+
json_post,
|
772
|
+
engine_type,
|
773
|
+
model or self.engine,
|
774
|
+
)
|
775
|
+
else:
|
776
|
+
async_generator = fetch_response(
|
777
|
+
self.aclient,
|
778
|
+
url,
|
779
|
+
headers,
|
780
|
+
json_post,
|
781
|
+
engine_type,
|
782
|
+
model or self.engine,
|
783
|
+
)
|
771
784
|
# 异步处理响应流
|
772
785
|
async for chunk in self._process_stream_response(
|
773
786
|
async_generator,
|
@@ -817,6 +830,7 @@ class chatgpt(BaseLLM):
|
|
817
830
|
function_call_id: str = "",
|
818
831
|
language: str = "English",
|
819
832
|
system_prompt: str = None,
|
833
|
+
stream: bool = True,
|
820
834
|
**kwargs,
|
821
835
|
):
|
822
836
|
"""
|
@@ -829,7 +843,7 @@ class chatgpt(BaseLLM):
|
|
829
843
|
self.add_to_conversation(prompt, role, convo_id=convo_id, function_name=function_name, total_tokens=total_tokens, function_arguments=function_arguments, pass_history=pass_history, function_call_id=function_call_id)
|
830
844
|
|
831
845
|
# 获取请求体
|
832
|
-
url, headers, json_post, engine_type = await self.get_post_body(prompt, role, convo_id, model, pass_history, **kwargs)
|
846
|
+
url, headers, json_post, engine_type = await self.get_post_body(prompt, role, convo_id, model, pass_history, stream=stream, **kwargs)
|
833
847
|
self.truncate_conversation(convo_id=convo_id)
|
834
848
|
|
835
849
|
# 打印日志
|
@@ -874,24 +888,24 @@ class chatgpt(BaseLLM):
|
|
874
888
|
yield f"data: {json.dumps(tmp_response)}\n\n"
|
875
889
|
generator = _mock_response_generator()
|
876
890
|
else:
|
877
|
-
|
878
|
-
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
|
883
|
-
|
884
|
-
|
885
|
-
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
|
890
|
-
|
891
|
-
|
892
|
-
|
893
|
-
|
894
|
-
|
891
|
+
if stream:
|
892
|
+
generator = fetch_response_stream(
|
893
|
+
self.aclient,
|
894
|
+
url,
|
895
|
+
headers,
|
896
|
+
json_post,
|
897
|
+
engine_type,
|
898
|
+
model or self.engine,
|
899
|
+
)
|
900
|
+
else:
|
901
|
+
generator = fetch_response(
|
902
|
+
self.aclient,
|
903
|
+
url,
|
904
|
+
headers,
|
905
|
+
json_post,
|
906
|
+
engine_type,
|
907
|
+
model or self.engine,
|
908
|
+
)
|
895
909
|
|
896
910
|
# 处理正常响应
|
897
911
|
async for processed_chunk in self._process_stream_response(
|
@@ -943,11 +957,36 @@ class chatgpt(BaseLLM):
|
|
943
957
|
convo_id=convo_id,
|
944
958
|
pass_history=pass_history,
|
945
959
|
model=model or self.engine,
|
960
|
+
stream=False,
|
946
961
|
**kwargs,
|
947
962
|
)
|
948
963
|
full_response: str = "".join([r async for r in response])
|
949
964
|
return full_response
|
950
965
|
|
966
|
+
def ask(
|
967
|
+
self,
|
968
|
+
prompt: str,
|
969
|
+
role: str = "user",
|
970
|
+
convo_id: str = "default",
|
971
|
+
model: str = "",
|
972
|
+
pass_history: int = 9999,
|
973
|
+
**kwargs,
|
974
|
+
) -> str:
|
975
|
+
"""
|
976
|
+
Non-streaming ask
|
977
|
+
"""
|
978
|
+
response = self.ask_stream(
|
979
|
+
prompt=prompt,
|
980
|
+
role=role,
|
981
|
+
convo_id=convo_id,
|
982
|
+
pass_history=pass_history,
|
983
|
+
model=model or self.engine,
|
984
|
+
stream=False,
|
985
|
+
**kwargs,
|
986
|
+
)
|
987
|
+
full_response: str = "".join([r for r in response])
|
988
|
+
return full_response
|
989
|
+
|
951
990
|
def rollback(self, n: int = 1, convo_id: str = "default") -> None:
|
952
991
|
"""
|
953
992
|
Rollback the conversation
|
aient/plugins/excute_command.py
CHANGED
@@ -276,4 +276,4 @@ for i in content.split("\\n"):
|
|
276
276
|
# print(excute_command(python_long_task_command))
|
277
277
|
|
278
278
|
# print(get_python_executable("python -c 'print(123)'"))
|
279
|
-
# python -m beswarm.aient.
|
279
|
+
# python -m beswarm.aient.aient.plugins.excute_command
|
aient/plugins/read_file.py
CHANGED
@@ -181,7 +181,7 @@ Examples:
|
|
181
181
|
return f"<tool_error>读取文件时发生错误: {e}</tool_error>"
|
182
182
|
|
183
183
|
if __name__ == "__main__":
|
184
|
-
# python -m beswarm.aient.
|
184
|
+
# python -m beswarm.aient.aient.plugins.read_file
|
185
185
|
result = read_file("./work/cax/Lenia Notebook.ipynb")
|
186
186
|
print(result)
|
187
187
|
print(len(result))
|
aient/plugins/websearch.py
CHANGED
@@ -344,7 +344,7 @@ async def get_search_results(query):
|
|
344
344
|
|
345
345
|
if __name__ == "__main__":
|
346
346
|
os.system("clear")
|
347
|
-
# python -m beswarm.aient.
|
347
|
+
# python -m beswarm.aient.aient.plugins.websearch
|
348
348
|
print(get_url_content(""))
|
349
349
|
# from aient.models import chatgpt
|
350
350
|
# print(get_search_results("今天的微博热搜有哪些?", chatgpt.chatgpt_api_url.v1_url))
|
aient/plugins/write_file.py
CHANGED
aient/utils/scripts.py
CHANGED
@@ -12,26 +12,26 @@ aient/core/test/test_payload.py,sha256=8jBiJY1uidm1jzL-EiK0s6UGmW9XkdsuuKFGrwFhF
|
|
12
12
|
aient/models/__init__.py,sha256=ZTiZgbfBPTjIPSKURE7t6hlFBVLRS9lluGbmqc1WjxQ,43
|
13
13
|
aient/models/audio.py,sha256=kRd-8-WXzv4vwvsTGwnstK-WR8--vr9CdfCZzu8y9LA,1934
|
14
14
|
aient/models/base.py,sha256=z-Z0pJfTN2x0cuwfvu0BdMRY9O-RmLwHEnBIJN1x4Fg,6719
|
15
|
-
aient/models/chatgpt.py,sha256=
|
15
|
+
aient/models/chatgpt.py,sha256=pk34Oggn2z3Rnj65PRKufYknBgTK8yngAaMOxk3Nur8,54423
|
16
16
|
aient/plugins/__init__.py,sha256=p3KO6Aa3Lupos4i2SjzLQw1hzQTigOAfEHngsldrsyk,986
|
17
17
|
aient/plugins/arXiv.py,sha256=yHjb6PS3GUWazpOYRMKMzghKJlxnZ5TX8z9F6UtUVow,1461
|
18
18
|
aient/plugins/config.py,sha256=2DXH-LP9KGl_P4467chJu3q4AAbX5nSn4DIkdI0aYH8,7105
|
19
|
-
aient/plugins/excute_command.py,sha256=
|
19
|
+
aient/plugins/excute_command.py,sha256=urbOFUI-Wd-XaNyH3EfNBn7vnimzF84b2uq4jMXPxYM,10642
|
20
20
|
aient/plugins/get_time.py,sha256=Ih5XIW5SDAIhrZ9W4Qe5Hs1k4ieKPUc_LAd6ySNyqZk,654
|
21
21
|
aient/plugins/image.py,sha256=ZElCIaZznE06TN9xW3DrSukS7U3A5_cjk1Jge4NzPxw,2072
|
22
22
|
aient/plugins/list_directory.py,sha256=V_uKkLx_fQDL5z__bSDC-PqAP-o32KmQW6Pdhx0Fx0s,1433
|
23
|
-
aient/plugins/read_file.py,sha256=
|
23
|
+
aient/plugins/read_file.py,sha256=AOGGzSzkALG1R_ncpDmegX_zKFZBZr8ZhTBQCiwhZfU,8691
|
24
24
|
aient/plugins/read_image.py,sha256=4FbIiMNVFUQpNyiH5ApGSRvOD9ujcXGyuqlGTJMd7ac,4017
|
25
25
|
aient/plugins/readonly.py,sha256=qK5-kBM3NDH1b-otFxFHpAjV5BXEY_e7cTWBcpP7G5k,710
|
26
26
|
aient/plugins/registry.py,sha256=YknzhieU_8nQ3oKlUSSWDB4X7t2Jx0JnqT2Jd9Xsvfk,3574
|
27
27
|
aient/plugins/run_python.py,sha256=MohvdtZUTDLrHBDtJ9L2_Qu1pWAGrkbzsGmmn5tMN20,4614
|
28
|
-
aient/plugins/websearch.py,sha256=
|
29
|
-
aient/plugins/write_file.py,sha256=
|
28
|
+
aient/plugins/websearch.py,sha256=aPsBjUQ3zQ4gzNrbVq7BMh28ENj9h_fSAeJFF2h9TNk,15334
|
29
|
+
aient/plugins/write_file.py,sha256=Jt8fOEwqhYiSWpCbwfAr1xoi_BmFnx3076GMhuL06uI,3949
|
30
30
|
aient/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
31
31
|
aient/utils/prompt.py,sha256=UcSzKkFE4-h_1b6NofI6xgk3GoleqALRKY8VBaXLjmI,11311
|
32
|
-
aient/utils/scripts.py,sha256=
|
33
|
-
aient-1.1.
|
34
|
-
aient-1.1.
|
35
|
-
aient-1.1.
|
36
|
-
aient-1.1.
|
37
|
-
aient-1.1.
|
32
|
+
aient/utils/scripts.py,sha256=CjB4qq6MoltfT0AnoekFqhw3p5sH7iWz65RuImTipVo,40905
|
33
|
+
aient-1.1.61.dist-info/licenses/LICENSE,sha256=XNdbcWldt0yaNXXWB_Bakoqnxb3OVhUft4MgMA_71ds,1051
|
34
|
+
aient-1.1.61.dist-info/METADATA,sha256=pp6yzSaglBHddABnIYJI5V7pnye9vkaOdXwa8LTiMM8,4994
|
35
|
+
aient-1.1.61.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
36
|
+
aient-1.1.61.dist-info/top_level.txt,sha256=3oXzrP5sAVvyyqabpeq8A2_vfMtY554r4bVE-OHBrZk,6
|
37
|
+
aient-1.1.61.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|