aient 1.1.77__tar.gz → 1.1.79__tar.gz

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.
Files changed (51) hide show
  1. {aient-1.1.77 → aient-1.1.79}/PKG-INFO +1 -1
  2. {aient-1.1.77 → aient-1.1.79}/aient/core/request.py +34 -15
  3. {aient-1.1.77 → aient-1.1.79}/aient/core/response.py +22 -0
  4. {aient-1.1.77 → aient-1.1.79}/aient/core/utils.py +6 -3
  5. {aient-1.1.77 → aient-1.1.79}/aient/models/chatgpt.py +15 -6
  6. {aient-1.1.77 → aient-1.1.79}/aient.egg-info/PKG-INFO +1 -1
  7. {aient-1.1.77 → aient-1.1.79}/pyproject.toml +1 -1
  8. {aient-1.1.77 → aient-1.1.79}/LICENSE +0 -0
  9. {aient-1.1.77 → aient-1.1.79}/README.md +0 -0
  10. {aient-1.1.77 → aient-1.1.79}/aient/__init__.py +0 -0
  11. {aient-1.1.77 → aient-1.1.79}/aient/core/__init__.py +0 -0
  12. {aient-1.1.77 → aient-1.1.79}/aient/core/log_config.py +0 -0
  13. {aient-1.1.77 → aient-1.1.79}/aient/core/models.py +0 -0
  14. {aient-1.1.77 → aient-1.1.79}/aient/core/test/test_base_api.py +0 -0
  15. {aient-1.1.77 → aient-1.1.79}/aient/core/test/test_geminimask.py +0 -0
  16. {aient-1.1.77 → aient-1.1.79}/aient/core/test/test_image.py +0 -0
  17. {aient-1.1.77 → aient-1.1.79}/aient/core/test/test_payload.py +0 -0
  18. {aient-1.1.77 → aient-1.1.79}/aient/models/__init__.py +0 -0
  19. {aient-1.1.77 → aient-1.1.79}/aient/models/audio.py +0 -0
  20. {aient-1.1.77 → aient-1.1.79}/aient/models/base.py +0 -0
  21. {aient-1.1.77 → aient-1.1.79}/aient/plugins/__init__.py +0 -0
  22. {aient-1.1.77 → aient-1.1.79}/aient/plugins/arXiv.py +0 -0
  23. {aient-1.1.77 → aient-1.1.79}/aient/plugins/config.py +0 -0
  24. {aient-1.1.77 → aient-1.1.79}/aient/plugins/excute_command.py +0 -0
  25. {aient-1.1.77 → aient-1.1.79}/aient/plugins/get_time.py +0 -0
  26. {aient-1.1.77 → aient-1.1.79}/aient/plugins/image.py +0 -0
  27. {aient-1.1.77 → aient-1.1.79}/aient/plugins/list_directory.py +0 -0
  28. {aient-1.1.77 → aient-1.1.79}/aient/plugins/read_file.py +0 -0
  29. {aient-1.1.77 → aient-1.1.79}/aient/plugins/read_image.py +0 -0
  30. {aient-1.1.77 → aient-1.1.79}/aient/plugins/readonly.py +0 -0
  31. {aient-1.1.77 → aient-1.1.79}/aient/plugins/registry.py +0 -0
  32. {aient-1.1.77 → aient-1.1.79}/aient/plugins/run_python.py +0 -0
  33. {aient-1.1.77 → aient-1.1.79}/aient/plugins/websearch.py +0 -0
  34. {aient-1.1.77 → aient-1.1.79}/aient/plugins/write_file.py +0 -0
  35. {aient-1.1.77 → aient-1.1.79}/aient/utils/__init__.py +0 -0
  36. {aient-1.1.77 → aient-1.1.79}/aient/utils/prompt.py +0 -0
  37. {aient-1.1.77 → aient-1.1.79}/aient/utils/scripts.py +0 -0
  38. {aient-1.1.77 → aient-1.1.79}/aient.egg-info/SOURCES.txt +0 -0
  39. {aient-1.1.77 → aient-1.1.79}/aient.egg-info/dependency_links.txt +0 -0
  40. {aient-1.1.77 → aient-1.1.79}/aient.egg-info/requires.txt +0 -0
  41. {aient-1.1.77 → aient-1.1.79}/aient.egg-info/top_level.txt +0 -0
  42. {aient-1.1.77 → aient-1.1.79}/setup.cfg +0 -0
  43. {aient-1.1.77 → aient-1.1.79}/test/test_Web_crawler.py +0 -0
  44. {aient-1.1.77 → aient-1.1.79}/test/test_ddg_search.py +0 -0
  45. {aient-1.1.77 → aient-1.1.79}/test/test_google_search.py +0 -0
  46. {aient-1.1.77 → aient-1.1.79}/test/test_ollama.py +0 -0
  47. {aient-1.1.77 → aient-1.1.79}/test/test_plugin.py +0 -0
  48. {aient-1.1.77 → aient-1.1.79}/test/test_search.py +0 -0
  49. {aient-1.1.77 → aient-1.1.79}/test/test_url.py +0 -0
  50. {aient-1.1.77 → aient-1.1.79}/test/test_whisper.py +0 -0
  51. {aient-1.1.77 → aient-1.1.79}/test/test_yjh.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aient
3
- Version: 1.1.77
3
+ Version: 1.1.79
4
4
  Summary: Aient: The Awakening of Agent.
5
5
  Requires-Python: >=3.11
6
6
  Description-Content-Type: text/markdown
@@ -3,9 +3,9 @@ import json
3
3
  import httpx
4
4
  import base64
5
5
  import asyncio
6
- import urllib.parse
7
6
  from io import IOBase
8
7
  from typing import Tuple
8
+ from urllib.parse import urlparse
9
9
 
10
10
  from .models import RequestModel, Message
11
11
  from .utils import (
@@ -41,7 +41,7 @@ async def get_gemini_payload(request, engine, provider, api_key=None):
41
41
  else:
42
42
  gemini_stream = "generateContent"
43
43
  url = provider['base_url']
44
- parsed_url = urllib.parse.urlparse(url)
44
+ parsed_url = urlparse(url)
45
45
  if "/v1beta" in parsed_url.path:
46
46
  api_version = "v1beta"
47
47
  else:
@@ -1952,21 +1952,40 @@ async def get_embedding_payload(request, engine, provider, api_key=None):
1952
1952
  headers = {
1953
1953
  "Content-Type": "application/json",
1954
1954
  }
1955
- if api_key:
1956
- headers['Authorization'] = f"Bearer {api_key}"
1957
- url = provider['base_url']
1958
- url = BaseAPI(url).embeddings
1959
1955
 
1960
- payload = {
1961
- "input": request.input,
1962
- "model": original_model,
1963
- }
1956
+ url = provider['base_url']
1957
+ parsed_url = urlparse(url)
1958
+ if "embedding-00" in original_model and "127.0.0.1" not in url and \
1959
+ (parsed_url.path.endswith("/v1beta") or \
1960
+ parsed_url.path.endswith("/v1") or \
1961
+ (parsed_url.netloc == 'generativelanguage.googleapis.com' and "openai/chat/completions" not in parsed_url.path)):
1962
+ if api_key:
1963
+ headers['x-goog-api-key'] = f"{api_key}"
1964
+ parsed_url = urllib.parse.urlparse(url)
1965
+ url = f"{parsed_url.scheme}://{parsed_url.netloc}{parsed_url.path.split('/models')[0].rstrip('/')}/models/{original_model}:embedContent"
1966
+ payload = {
1967
+ "content": {
1968
+ "parts": [
1969
+ {
1970
+ "text": request.input
1971
+ }
1972
+ ]
1973
+ }
1974
+ }
1975
+ else:
1976
+ if api_key:
1977
+ headers['Authorization'] = f"Bearer {api_key}"
1978
+ url = BaseAPI(url).embeddings
1979
+ payload = {
1980
+ "input": request.input,
1981
+ "model": original_model,
1982
+ }
1964
1983
 
1965
- if request.encoding_format:
1966
- if url.startswith("https://api.jina.ai"):
1967
- payload["embedding_type"] = request.encoding_format
1968
- else:
1969
- payload["encoding_format"] = request.encoding_format
1984
+ if request.encoding_format:
1985
+ if url.startswith("https://api.jina.ai"):
1986
+ payload["embedding_type"] = request.encoding_format
1987
+ else:
1988
+ payload["encoding_format"] = request.encoding_format
1970
1989
 
1971
1990
  return url, headers, payload
1972
1991
 
@@ -626,6 +626,28 @@ async def fetch_response(client, url, headers, payload, engine, model, timeout=2
626
626
  response_json = await asyncio.to_thread(json.loads, response_bytes)
627
627
  content = safe_get(response_json, "output", "choices", 0, "message", "content", 0, default=None)
628
628
  yield content
629
+
630
+ elif "embedContent" in url:
631
+ response_bytes = await response.aread()
632
+ response_json = await asyncio.to_thread(json.loads, response_bytes)
633
+ content = safe_get(response_json, "embedding", "values", default=[])
634
+ response_embedContent = {
635
+ "object": "list",
636
+ "data": [
637
+ {
638
+ "object": "embedding",
639
+ "embedding":content,
640
+ "index": 0
641
+ }
642
+ ],
643
+ "model": model,
644
+ "usage": {
645
+ "prompt_tokens": 0,
646
+ "total_tokens": 0
647
+ }
648
+ }
649
+
650
+ yield response_embedContent
629
651
  else:
630
652
  response_bytes = await response.aread()
631
653
  response_json = await asyncio.to_thread(json.loads, response_bytes)
@@ -518,7 +518,7 @@ async def generate_sse_response(timestamp, model, content=None, tools_id=None, f
518
518
  sample_data["choices"][0]["delta"] = {}
519
519
  sample_data["choices"][0]["finish_reason"] = stop
520
520
 
521
- json_data = json.dumps(sample_data, ensure_ascii=False)
521
+ json_data = await asyncio.to_thread(json.dumps, sample_data, ensure_ascii=False)
522
522
  # print("json_data", json.dumps(sample_data, indent=4, ensure_ascii=False))
523
523
 
524
524
  # 构建SSE响应
@@ -557,6 +557,9 @@ async def generate_no_stream_response(timestamp, model, content=None, tools_id=N
557
557
  if function_call_name:
558
558
  if not tools_id:
559
559
  tools_id = f"call_{random_str}"
560
+
561
+ arguments_json = await asyncio.to_thread(json.dumps, function_call_content, ensure_ascii=False)
562
+
560
563
  sample_data = {
561
564
  "id": f"chatcmpl-{random_str}",
562
565
  "object": "chat.completion",
@@ -574,7 +577,7 @@ async def generate_no_stream_response(timestamp, model, content=None, tools_id=N
574
577
  "type": "function",
575
578
  "function": {
576
579
  "name": function_call_name,
577
- "arguments": json.dumps(function_call_content, ensure_ascii=False)
580
+ "arguments": arguments_json
578
581
  }
579
582
  }
580
583
  ],
@@ -605,7 +608,7 @@ async def generate_no_stream_response(timestamp, model, content=None, tools_id=N
605
608
  if total_tokens:
606
609
  sample_data["usage"] = {"prompt_tokens": prompt_tokens, "completion_tokens": completion_tokens, "total_tokens": total_tokens}
607
610
 
608
- json_data = json.dumps(sample_data, ensure_ascii=False)
611
+ json_data = await asyncio.to_thread(json.dumps, sample_data, ensure_ascii=False)
609
612
  # print("json_data", json.dumps(sample_data, indent=4, ensure_ascii=False))
610
613
 
611
614
  return json_data
@@ -37,6 +37,14 @@ class RateLimitError(Exception):
37
37
  """Custom exception for rate limit (429) errors."""
38
38
  pass
39
39
 
40
+ class ConfigurationError(Exception):
41
+ """Custom exception for configuration errors."""
42
+ pass
43
+
44
+ class RetryFailedError(Exception):
45
+ """Custom exception for retry failures."""
46
+ pass
47
+
40
48
  class TaskComplete(Exception):
41
49
  """Exception-like signal to indicate the task is complete."""
42
50
  def __init__(self, message):
@@ -523,6 +531,7 @@ class chatgpt(BaseLLM):
523
531
  # 删除 task_complete 跟其他工具一起调用的情况,因为 task_complete 必须单独调用
524
532
  if len(function_parameter) > 1:
525
533
  function_parameter = [tool_dict for tool_dict in function_parameter if tool_dict.get("function_name", "") != "task_complete"]
534
+ function_parameter = [tool_dict for tool_dict in function_parameter if tool_dict.get("function_name", "") != "get_task_result"]
526
535
  if len(function_parameter) == 1 and function_parameter[0].get("function_name", "") == "task_complete":
527
536
  raise TaskComplete(safe_get(function_parameter, 0, "parameter", "message", default="The task has been completed."))
528
537
 
@@ -731,7 +740,7 @@ class chatgpt(BaseLLM):
731
740
  need_done_prompt = False
732
741
 
733
742
  # 发送请求并处理响应
734
- for i in range(30):
743
+ for i in range(10):
735
744
  tmp_post_json = copy.deepcopy(json_post)
736
745
  if need_done_prompt:
737
746
  tmp_post_json["messages"].extend(need_done_prompt)
@@ -789,8 +798,8 @@ class chatgpt(BaseLLM):
789
798
 
790
799
  # 成功处理,跳出重试循环
791
800
  break
792
- except (httpx.ConnectError, httpx.ReadTimeout):
793
- self.logger.error("连接或读取超时错误,请检查服务器状态或网络连接。")
801
+ except (httpx.ConnectError, httpx.ReadTimeout, httpx.PoolTimeout):
802
+ self.logger.error("Connection or read timeout.")
794
803
  return # Stop iteration
795
804
  except httpx.RemoteProtocolError:
796
805
  continue
@@ -820,10 +829,10 @@ class chatgpt(BaseLLM):
820
829
  self.logger.error(traceback.format_exc())
821
830
  if "Invalid URL" in str(e):
822
831
  error_message = "您输入了无效的API URL,请使用正确的URL并使用`/start`命令重新设置API URL。具体错误如下:\n\n" + str(e)
823
- raise Exception(json.dumps({"type": "configuration_error", "message": error_message}, ensure_ascii=False))
832
+ raise ConfigurationError(error_message)
824
833
  # 最后一次重试失败,向上抛出异常
825
- if i == 11:
826
- raise Exception(json.dumps({"type": "retry_failed", "message": str(e)}, ensure_ascii=False))
834
+ if i == 10:
835
+ raise RetryFailedError(str(e))
827
836
 
828
837
  def ask_stream(
829
838
  self,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aient
3
- Version: 1.1.77
3
+ Version: 1.1.79
4
4
  Summary: Aient: The Awakening of Agent.
5
5
  Requires-Python: >=3.11
6
6
  Description-Content-Type: text/markdown
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "aient"
3
- version = "1.1.77"
3
+ version = "1.1.79"
4
4
  description = "Aient: The Awakening of Agent."
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.11"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes