beswarm 0.2.55__py3-none-any.whl → 0.2.57__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/agents/planact.py CHANGED
@@ -210,6 +210,9 @@ class WorkerAgent(BaseAgent):
210
210
  if response.strip() == '':
211
211
  self.logger.error("\n❌ 工作智能体回复为空,请重新生成指令。")
212
212
  self.broker.publish(message, self.error_topic)
213
+ elif "HTTP Error', 'status_code': 524" in response:
214
+ self.logger.error("\n❌ 工作智能体回复超时 100 秒,请重新生成指令。")
215
+ self.broker.publish(message, self.error_topic)
213
216
  else:
214
217
  self.broker.publish({"status": "new_message", "result": "\n✅ 工作智能体:\n" + response}, self.status_topic)
215
218
  self.broker.publish({
@@ -390,7 +390,7 @@ async def fetch_cloudflare_response_stream(client, url, headers, payload, model)
390
390
  async def fetch_cohere_response_stream(client, url, headers, payload, model):
391
391
  timestamp = int(datetime.timestamp(datetime.now()))
392
392
  async with client.stream('POST', url, headers=headers, json=payload) as response:
393
- error_message = await check_response(response, "fetch_gpt_response_stream")
393
+ error_message = await check_response(response, "fetch_cohere_response_stream")
394
394
  if error_message:
395
395
  yield error_message
396
396
  return
@@ -6,9 +6,8 @@ import httpx
6
6
  import asyncio
7
7
  import logging
8
8
  import inspect
9
- import requests
10
9
  from typing import Set
11
- from typing import Union, Optional, Callable, List, Dict, Any
10
+ from typing import Union, Optional, Callable
12
11
  from pathlib import Path
13
12
 
14
13
 
@@ -360,6 +359,7 @@ class chatgpt(BaseLLM):
360
359
  system_prompt=None,
361
360
  pass_history=9999,
362
361
  is_async=False,
362
+ stream: bool = True,
363
363
  **kwargs
364
364
  ):
365
365
  """
@@ -388,6 +388,7 @@ class chatgpt(BaseLLM):
388
388
  elif isinstance(line, (dict, list)):
389
389
  if isinstance(line, dict) and safe_get(line, "choices", 0, "message", "content"):
390
390
  full_response = line["choices"][0]["message"]["content"]
391
+ total_tokens = safe_get(line, "usage", "total_tokens", default=0)
391
392
  return full_response
392
393
  else:
393
394
  return str(line)
@@ -471,6 +472,8 @@ class chatgpt(BaseLLM):
471
472
  # self.logger.info(f"worker Response: {full_response}")
472
473
  if not full_response.strip().endswith('[done]'):
473
474
  raise Exception(f"Response is not ended with [done]: {full_response}")
475
+ elif not full_response.strip():
476
+ raise Exception(f"Response is empty")
474
477
  else:
475
478
  full_response = full_response.strip().rstrip('[done]')
476
479
  full_response = full_response.replace("<tool_code>", "").replace("</tool_code>", "")
@@ -635,6 +638,9 @@ class chatgpt(BaseLLM):
635
638
  else:
636
639
  all_responses.append(f"[{tool_name}({tool_args}) Result]:\n\n{tool_response}")
637
640
 
641
+ if self.check_done:
642
+ all_responses.append("Your message **must** end with [done] to signify the end of your output.")
643
+
638
644
  # 合并所有工具响应
639
645
  function_response = "\n\n".join(all_responses).strip()
640
646
  if missing_required_params:
@@ -655,7 +661,7 @@ class chatgpt(BaseLLM):
655
661
  model=model or self.engine, function_arguments=function_full_response,
656
662
  function_call_id=function_call_id, api_key=kwargs.get('api_key', self.api_key),
657
663
  api_url=kwargs.get('api_url', self.api_url.chat_url),
658
- plugins=kwargs.get("plugins", self.plugins), system_prompt=system_prompt
664
+ plugins=kwargs.get("plugins", self.plugins), system_prompt=system_prompt, stream=stream
659
665
  ):
660
666
  yield chunk
661
667
  else:
@@ -665,7 +671,7 @@ class chatgpt(BaseLLM):
665
671
  model=model or self.engine, function_arguments=function_full_response,
666
672
  function_call_id=function_call_id, api_key=kwargs.get('api_key', self.api_key),
667
673
  api_url=kwargs.get('api_url', self.api_url.chat_url),
668
- plugins=kwargs.get("plugins", self.plugins), system_prompt=system_prompt
674
+ plugins=kwargs.get("plugins", self.plugins), system_prompt=system_prompt, stream=stream
669
675
  ):
670
676
  yield chunk
671
677
  else:
@@ -719,7 +725,7 @@ class chatgpt(BaseLLM):
719
725
  self.logger.info(f"api_key: {kwargs.get('api_key', self.api_key)}")
720
726
 
721
727
  # 发送请求并处理响应
722
- for i in range(10):
728
+ for i in range(30):
723
729
  if self.print_log:
724
730
  replaced_text = json.loads(re.sub(r';base64,([A-Za-z0-9+/=]+)', ';base64,***', json.dumps(json_post)))
725
731
  replaced_text_str = json.dumps(replaced_text, indent=4, ensure_ascii=False)
@@ -759,7 +765,7 @@ class chatgpt(BaseLLM):
759
765
  generator, convo_id=convo_id, function_name=function_name,
760
766
  total_tokens=total_tokens, function_arguments=function_arguments,
761
767
  function_call_id=function_call_id, model=model, language=language,
762
- system_prompt=system_prompt, pass_history=pass_history, is_async=True, **kwargs
768
+ system_prompt=system_prompt, pass_history=pass_history, is_async=True, stream=stream, **kwargs
763
769
  ):
764
770
  yield processed_chunk
765
771
 
@@ -771,8 +777,8 @@ class chatgpt(BaseLLM):
771
777
  except httpx.RemoteProtocolError:
772
778
  continue
773
779
  except Exception as e:
774
- if "Response is not ended with [done]:" in str(e):
775
- self.logger.error(f"Response is not ended with [done]: {e}")
780
+ if "Response is" in str(e):
781
+ self.logger.error(f"{e}")
776
782
  continue
777
783
  self.logger.error(f"发生了未预料的错误:{e}")
778
784
  import traceback
@@ -862,7 +868,7 @@ class chatgpt(BaseLLM):
862
868
  convo_id=convo_id,
863
869
  pass_history=pass_history,
864
870
  model=model or self.engine,
865
- stream=False,
871
+ stream=True,
866
872
  **kwargs,
867
873
  )
868
874
  full_response: str = "".join([r async for r in response])
@@ -886,7 +892,7 @@ class chatgpt(BaseLLM):
886
892
  convo_id=convo_id,
887
893
  pass_history=pass_history,
888
894
  model=model or self.engine,
889
- stream=False,
895
+ stream=True,
890
896
  **kwargs,
891
897
  )
892
898
  full_response: str = "".join([r for r in response])
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: beswarm
3
- Version: 0.2.55
3
+ Version: 0.2.57
4
4
  Summary: MAS
5
5
  Requires-Python: >=3.11
6
6
  Description-Content-Type: text/markdown
@@ -6,13 +6,13 @@ beswarm/prompt.py,sha256=INVRWQZP6lysvGUcPOYI_er5-bi1gGe_qa6BTov7PmY,32362
6
6
  beswarm/taskmanager.py,sha256=ErgZa9_aBeWdmt5neRw6sDVdwSWewxip458gAjeQhS4,12188
7
7
  beswarm/utils.py,sha256=0J-b38P5QGT-A_38co7FjzaUNJykaskI7mbbcQ4w_68,8215
8
8
  beswarm/agents/chatgroup.py,sha256=PzrmRcDKAbB7cxL16nMod_CzPosDV6bfTmXxQVuv-AQ,12012
9
- beswarm/agents/planact.py,sha256=xi259X0y1Sd2HBM42pp0JtCtGE3glhO12l5u5F0SvOU,19926
9
+ beswarm/agents/planact.py,sha256=ndsisPbGhHN04O85Htc12bC1UWPdgq_CNA1077nxeD0,20147
10
10
  beswarm/aient/aient/__init__.py,sha256=SRfF7oDVlOOAi6nGKiJIUK6B_arqYLO9iSMp-2IZZps,21
11
11
  beswarm/aient/aient/core/__init__.py,sha256=NxjebTlku35S4Dzr16rdSqSTWUvvwEeACe8KvHJnjPg,34
12
12
  beswarm/aient/aient/core/log_config.py,sha256=kz2_yJv1p-o3lUQOwA3qh-LSc3wMHv13iCQclw44W9c,274
13
13
  beswarm/aient/aient/core/models.py,sha256=d4MISNezTSe0ls0-fjuToI2SoT-sk5fWqAJuKVinIlo,7502
14
14
  beswarm/aient/aient/core/request.py,sha256=4FFCwQ7h7b6bqtrA8qw-DPJVXZTj2i1CkYccFeEwUPw,76552
15
- beswarm/aient/aient/core/response.py,sha256=sPcNV9qLosj3lIXElezUZEjIyglspdkBg-EsIUhr9bQ,33203
15
+ beswarm/aient/aient/core/response.py,sha256=tYKWOeexYEhWK4napIAfYjCn2rQ1zpxRvknsBBWrv2M,33206
16
16
  beswarm/aient/aient/core/utils.py,sha256=D98d5Cy1h4ejKtuxS0EEDtL4YqpaZLB5tuXoVP0IBWQ,28462
17
17
  beswarm/aient/aient/core/test/test_base_api.py,sha256=pWnycRJbuPSXKKU9AQjWrMAX1wiLC_014Qc9hh5C2Pw,524
18
18
  beswarm/aient/aient/core/test/test_geminimask.py,sha256=HFX8jDbNg_FjjgPNxfYaR-0-roUrOO-ND-FVsuxSoiw,13254
@@ -21,7 +21,7 @@ beswarm/aient/aient/core/test/test_payload.py,sha256=8jBiJY1uidm1jzL-EiK0s6UGmW9
21
21
  beswarm/aient/aient/models/__init__.py,sha256=ZTiZgbfBPTjIPSKURE7t6hlFBVLRS9lluGbmqc1WjxQ,43
22
22
  beswarm/aient/aient/models/audio.py,sha256=kRd-8-WXzv4vwvsTGwnstK-WR8--vr9CdfCZzu8y9LA,1934
23
23
  beswarm/aient/aient/models/base.py,sha256=-nnihYnx-vHZMqeVO9ljjt3k4FcD3n-iMk4tT-10nRQ,7232
24
- beswarm/aient/aient/models/chatgpt.py,sha256=LnbWADil5oNmdBaAtXb1XcQwoaERqanO7Or9wzsg82w,49348
24
+ beswarm/aient/aient/models/chatgpt.py,sha256=4Pv-OW2iP2K9FmSyJruqpWlFOdAP8TAb0aEJzYrCpY8,49675
25
25
  beswarm/aient/aient/plugins/__init__.py,sha256=p3KO6Aa3Lupos4i2SjzLQw1hzQTigOAfEHngsldrsyk,986
26
26
  beswarm/aient/aient/plugins/arXiv.py,sha256=yHjb6PS3GUWazpOYRMKMzghKJlxnZ5TX8z9F6UtUVow,1461
27
27
  beswarm/aient/aient/plugins/config.py,sha256=2DXH-LP9KGl_P4467chJu3q4AAbX5nSn4DIkdI0aYH8,7105
@@ -116,7 +116,7 @@ beswarm/tools/search_web.py,sha256=NYrb5KL_WUGPm-fOKT8Cyjon04lxBU-gaLdrVjeYgGo,1
116
116
  beswarm/tools/subtasks.py,sha256=mIjA2QrRy9Fos4rYm8fCfu2QrsE_MGnQI9IR8dOxsGs,9885
117
117
  beswarm/tools/worker.py,sha256=_cSkRUKRJMAiZiTfnBze_e9Kc7k7KvbB5hdxdvp4FW4,2009
118
118
  beswarm/tools/write_csv.py,sha256=u0Hq18Ksfheb52MVtyLNCnSDHibITpsYBPs2ub7USYA,1466
119
- beswarm-0.2.55.dist-info/METADATA,sha256=iUHDB2olCdaPgC5J8ppmSdqdH6NXChIfnDsclhikhpY,3878
120
- beswarm-0.2.55.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
121
- beswarm-0.2.55.dist-info/top_level.txt,sha256=pJw4O87wvt5882smuSO6DfByJz7FJ8SxxT8h9fHCmpo,8
122
- beswarm-0.2.55.dist-info/RECORD,,
119
+ beswarm-0.2.57.dist-info/METADATA,sha256=lT4Ai8xT6sA0ulnKU_SvtbKpkNTYBn5bkDCZgEYj0GE,3878
120
+ beswarm-0.2.57.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
121
+ beswarm-0.2.57.dist-info/top_level.txt,sha256=pJw4O87wvt5882smuSO6DfByJz7FJ8SxxT8h9fHCmpo,8
122
+ beswarm-0.2.57.dist-info/RECORD,,