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 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": True,
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
- async_generator = fetch_response_stream(
764
- self.aclient,
765
- url,
766
- headers,
767
- json_post,
768
- engine_type,
769
- model or self.engine,
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
- generator = fetch_response_stream(
878
- self.aclient,
879
- url,
880
- headers,
881
- json_post,
882
- engine_type,
883
- model or self.engine,
884
- )
885
- # if isinstance(chunk, dict) and "error" in chunk:
886
- # # 处理错误响应
887
- # if chunk["status_code"] in (400, 422, 503):
888
- # json_post, should_retry = await self._handle_response_error(
889
- # type('Response', (), {'status_code': chunk["status_code"], 'text': json.dumps(chunk["details"]), 'aread': lambda: asyncio.sleep(0)}),
890
- # json_post
891
- # )
892
- # if should_retry:
893
- # break # 跳出内部循环,继续外部循环重试
894
- # raise Exception(f"{chunk['status_code']} {chunk['error']} {chunk['details']}")
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
@@ -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.src.aient.plugins.excute_command
279
+ # python -m beswarm.aient.aient.plugins.excute_command
@@ -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.src.aient.plugins.read_file
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))
@@ -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.src.aient.plugins.websearch
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))
@@ -87,4 +87,4 @@ if __name__ == "__main__":
87
87
  with open("test.txt", "r", encoding="utf-8") as file:
88
88
  content = file.read()
89
89
  print(write_to_file("test.txt", content))
90
- # python -m beswarm.aient.src.aient.plugins.write_file
90
+ # python -m beswarm.aient.aient.plugins.write_file
aient/utils/scripts.py CHANGED
@@ -1050,4 +1050,4 @@ if __name__ == "__main__":
1050
1050
  # print(parse_function_xml(test_xml))
1051
1051
  print(remove_xml_tags_and_content(test_xml))
1052
1052
 
1053
- # 运行本文件:python -m beswarm.aient.src.aient.utils.scripts
1053
+ # 运行本文件:python -m beswarm.aient.aient.utils.scripts
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aient
3
- Version: 1.1.59
3
+ Version: 1.1.61
4
4
  Summary: Aient: The Awakening of Agent.
5
5
  Requires-Python: >=3.11
6
6
  Description-Content-Type: text/markdown
@@ -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=LXSMwKRIbWIaPa1Ejk8oCEXVmjZ0rpgFLss35Attn-Q,53493
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=EQe-vSlTrdd5I0reLqkSXqnPn1VoaCF1HeYZ4z0Txew,10646
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=ifG9J499oHqm7wXqGb2ye7YTYHFtwB1Mf4JYyWae7ig,8695
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=9yImBa1s5V7Djqzx6L4naDyIsGIcf_js1LOyLX0aNHw,15338
29
- aient/plugins/write_file.py,sha256=9msWSxWfJNhawLA-CyLLxtLipm53AX8o0VyCSV6VieM,3953
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=h7EA2xBydUF_wdZLsPgjCq4Egdycx1gf2qrdrm0I7y0,40909
33
- aient-1.1.59.dist-info/licenses/LICENSE,sha256=XNdbcWldt0yaNXXWB_Bakoqnxb3OVhUft4MgMA_71ds,1051
34
- aient-1.1.59.dist-info/METADATA,sha256=aWYs-nodkkOBESAPnPGHI8Q6AXYNrd0YnzmTdaji8AQ,4994
35
- aient-1.1.59.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
36
- aient-1.1.59.dist-info/top_level.txt,sha256=3oXzrP5sAVvyyqabpeq8A2_vfMtY554r4bVE-OHBrZk,6
37
- aient-1.1.59.dist-info/RECORD,,
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