aient 1.2.27__tar.gz → 1.2.30__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 (56) hide show
  1. {aient-1.2.27 → aient-1.2.30}/PKG-INFO +1 -1
  2. {aient-1.2.27 → aient-1.2.30}/aient/core/request.py +4 -2
  3. {aient-1.2.27 → aient-1.2.30}/aient/core/response.py +3 -2
  4. {aient-1.2.27 → aient-1.2.30}/aient/core/utils.py +44 -1
  5. {aient-1.2.27 → aient-1.2.30}/aient/models/audio.py +2 -2
  6. {aient-1.2.27 → aient-1.2.30}/aient/models/base.py +2 -2
  7. {aient-1.2.27 → aient-1.2.30}/aient/models/chatgpt.py +2 -2
  8. {aient-1.2.27 → aient-1.2.30}/aient/plugins/image.py +2 -2
  9. {aient-1.2.27 → aient-1.2.30}/aient/utils/prompt.py +0 -4
  10. {aient-1.2.27 → aient-1.2.30}/aient/utils/scripts.py +0 -8
  11. {aient-1.2.27 → aient-1.2.30}/aient.egg-info/PKG-INFO +1 -1
  12. {aient-1.2.27 → aient-1.2.30}/aient.egg-info/SOURCES.txt +1 -3
  13. {aient-1.2.27 → aient-1.2.30}/pyproject.toml +1 -1
  14. {aient-1.2.27 → aient-1.2.30}/test/test_whisper.py +1 -1
  15. aient-1.2.27/test/test_search.py +0 -18
  16. aient-1.2.27/test/test_yjh.py +0 -21
  17. {aient-1.2.27 → aient-1.2.30}/LICENSE +0 -0
  18. {aient-1.2.27 → aient-1.2.30}/README.md +0 -0
  19. {aient-1.2.27 → aient-1.2.30}/aient/__init__.py +0 -0
  20. {aient-1.2.27 → aient-1.2.30}/aient/architext/architext/__init__.py +0 -0
  21. {aient-1.2.27 → aient-1.2.30}/aient/architext/architext/core.py +0 -0
  22. {aient-1.2.27 → aient-1.2.30}/aient/architext/test/openai_client.py +0 -0
  23. {aient-1.2.27 → aient-1.2.30}/aient/architext/test/test.py +0 -0
  24. {aient-1.2.27 → aient-1.2.30}/aient/architext/test/test_save_load.py +0 -0
  25. {aient-1.2.27 → aient-1.2.30}/aient/core/__init__.py +0 -0
  26. {aient-1.2.27 → aient-1.2.30}/aient/core/log_config.py +0 -0
  27. {aient-1.2.27 → aient-1.2.30}/aient/core/models.py +0 -0
  28. {aient-1.2.27 → aient-1.2.30}/aient/core/test/test_base_api.py +0 -0
  29. {aient-1.2.27 → aient-1.2.30}/aient/core/test/test_geminimask.py +0 -0
  30. {aient-1.2.27 → aient-1.2.30}/aient/core/test/test_image.py +0 -0
  31. {aient-1.2.27 → aient-1.2.30}/aient/core/test/test_payload.py +0 -0
  32. {aient-1.2.27 → aient-1.2.30}/aient/models/__init__.py +0 -0
  33. {aient-1.2.27 → aient-1.2.30}/aient/plugins/__init__.py +0 -0
  34. {aient-1.2.27 → aient-1.2.30}/aient/plugins/arXiv.py +0 -0
  35. {aient-1.2.27 → aient-1.2.30}/aient/plugins/config.py +0 -0
  36. {aient-1.2.27 → aient-1.2.30}/aient/plugins/excute_command.py +0 -0
  37. {aient-1.2.27 → aient-1.2.30}/aient/plugins/get_time.py +0 -0
  38. {aient-1.2.27 → aient-1.2.30}/aient/plugins/list_directory.py +0 -0
  39. {aient-1.2.27 → aient-1.2.30}/aient/plugins/read_file.py +0 -0
  40. {aient-1.2.27 → aient-1.2.30}/aient/plugins/read_image.py +0 -0
  41. {aient-1.2.27 → aient-1.2.30}/aient/plugins/readonly.py +0 -0
  42. {aient-1.2.27 → aient-1.2.30}/aient/plugins/registry.py +0 -0
  43. {aient-1.2.27 → aient-1.2.30}/aient/plugins/run_python.py +0 -0
  44. {aient-1.2.27 → aient-1.2.30}/aient/plugins/websearch.py +0 -0
  45. {aient-1.2.27 → aient-1.2.30}/aient/plugins/write_file.py +0 -0
  46. {aient-1.2.27 → aient-1.2.30}/aient/utils/__init__.py +0 -0
  47. {aient-1.2.27 → aient-1.2.30}/aient.egg-info/dependency_links.txt +0 -0
  48. {aient-1.2.27 → aient-1.2.30}/aient.egg-info/requires.txt +0 -0
  49. {aient-1.2.27 → aient-1.2.30}/aient.egg-info/top_level.txt +0 -0
  50. {aient-1.2.27 → aient-1.2.30}/setup.cfg +0 -0
  51. {aient-1.2.27 → aient-1.2.30}/test/test_Web_crawler.py +0 -0
  52. {aient-1.2.27 → aient-1.2.30}/test/test_ddg_search.py +0 -0
  53. {aient-1.2.27 → aient-1.2.30}/test/test_google_search.py +0 -0
  54. {aient-1.2.27 → aient-1.2.30}/test/test_ollama.py +0 -0
  55. {aient-1.2.27 → aient-1.2.30}/test/test_plugin.py +0 -0
  56. {aient-1.2.27 → aient-1.2.30}/test/test_url.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aient
3
- Version: 1.2.27
3
+ Version: 1.2.30
4
4
  Summary: Aient: The Awakening of Agent.
5
5
  Requires-Python: >=3.11
6
6
  Description-Content-Type: text/markdown
@@ -1,5 +1,6 @@
1
1
  import re
2
2
  import json
3
+ import copy
3
4
  import httpx
4
5
  import base64
5
6
  import asyncio
@@ -57,7 +58,7 @@ async def get_gemini_payload(request, engine, provider, api_key=None):
57
58
  try:
58
59
  request_messages = [Message(role="user", content=request.prompt)]
59
60
  except:
60
- request_messages = request.messages
61
+ request_messages = copy.deepcopy(request.messages)
61
62
  for msg in request_messages:
62
63
  if msg.role == "assistant":
63
64
  msg.role = "model"
@@ -399,7 +400,8 @@ async def get_vertex_gemini_payload(request, engine, provider, api_key=None):
399
400
  systemInstruction = None
400
401
  system_prompt = ""
401
402
  function_arguments = None
402
- for msg in request.messages:
403
+ request_messages = copy.deepcopy(request.messages)
404
+ for msg in request_messages:
403
405
  if msg.role == "assistant":
404
406
  msg.role = "model"
405
407
  tool_calls = None
@@ -8,7 +8,7 @@ from datetime import datetime
8
8
 
9
9
  from .log_config import logger
10
10
 
11
- from .utils import safe_get, generate_sse_response, generate_no_stream_response, end_of_line, parse_json_safely
11
+ from .utils import safe_get, generate_sse_response, generate_no_stream_response, end_of_line, parse_json_safely, upload_image_to_0x0st
12
12
 
13
13
  async def check_response(response, error_log):
14
14
  if response and not (200 <= response.status_code < 300):
@@ -277,7 +277,8 @@ async def fetch_gpt_response_stream(client, url, headers, payload, timeout):
277
277
  openrouter_reasoning = safe_get(line, "choices", 0, "delta", "reasoning", default="")
278
278
  openrouter_base64_image = safe_get(line, "choices", 0, "delta", "images", 0, "image_url", "url", default="")
279
279
  if openrouter_base64_image:
280
- sse_string = await generate_sse_response(timestamp, payload["model"], content=f"\n\n![image]({openrouter_base64_image})")
280
+ image_url = await upload_image_to_0x0st(openrouter_base64_image)
281
+ sse_string = await generate_sse_response(timestamp, payload["model"], content=f"\n\n![image]({image_url})")
281
282
  yield sse_string
282
283
  continue
283
284
  azure_databricks_claude_summary_content = safe_get(line, "choices", 0, "delta", "content", 0, "summary", 0, "text", default="")
@@ -228,7 +228,12 @@ async def update_initial_model(provider):
228
228
  def safe_get(data, *keys, default=None):
229
229
  for key in keys:
230
230
  try:
231
- data = data[key] if isinstance(data, (dict, list)) else data.get(key)
231
+ if isinstance(data, (dict, list)):
232
+ data = data[key]
233
+ elif isinstance(key, str) and hasattr(data, key):
234
+ data = getattr(data, key)
235
+ else:
236
+ data = data.get(key)
232
237
  except (KeyError, IndexError, AttributeError, TypeError):
233
238
  return default
234
239
  if not data:
@@ -797,6 +802,44 @@ def parse_json_safely(json_str):
797
802
  # 两种方法都失败,抛出异常
798
803
  raise Exception(f"无法解析JSON字符串: {e}, {json_str}")
799
804
 
805
+ async def upload_image_to_0x0st(base64_image: str):
806
+ """
807
+ Uploads a base64 encoded image to 0x0.st.
808
+
809
+ Args:
810
+ base64_image: The base64 encoded image string.
811
+
812
+ Returns:
813
+ The URL of the uploaded image.
814
+ """
815
+ if "," in base64_image:
816
+ base64_image_split = base64_image.split(",")[1]
817
+
818
+ image_data = base64.b64decode(base64_image_split)
819
+
820
+ img_format = get_image_format(image_data)
821
+ if not img_format:
822
+ img_format = 'png' # 如果无法检测到格式,则默认为 png
823
+
824
+ content_type = f'image/{img_format}'
825
+ file_name = f'image.{img_format}'
826
+
827
+ files = {'file': (file_name, image_data, content_type)}
828
+ data = {'expires': '24', 'secret': '123456'}
829
+
830
+ async with httpx.AsyncClient() as client:
831
+ try:
832
+ response = await client.post("https://0x0.st", files=files, data=data)
833
+ response.raise_for_status()
834
+ return response.text.strip()
835
+ except httpx.RequestError as e:
836
+ logger.error(f"请求 0x0.st 时出错: {e}")
837
+ # raise HTTPException(status_code=500, detail="上传图片到 0x0.st 失败")
838
+ except httpx.HTTPStatusError as e:
839
+ logger.error(f"上传图片到 0x0.st 时发生 HTTP 错误: {e.response.status_code}")
840
+ # raise HTTPException(status_code=e.response.status_code, detail=f"上传图片到 0x0.st 失败: {e.response.text}")
841
+ return base64_image
842
+
800
843
  if __name__ == "__main__":
801
844
  provider = {
802
845
  "base_url": "https://gateway.ai.cloudflare.com/v1/%7Baccount_id%7D/%7Bgateway_id%7D/google-vertex-ai",
@@ -4,13 +4,13 @@ import json
4
4
  from .base import BaseLLM
5
5
 
6
6
  API = os.environ.get('API', None)
7
- API_URL = os.environ.get('API_URL', None)
7
+ BASE_URL = os.environ.get('BASE_URL', None)
8
8
 
9
9
  class whisper(BaseLLM):
10
10
  def __init__(
11
11
  self,
12
12
  api_key: str,
13
- api_url: str = (os.environ.get("API_URL") or "https://api.openai.com/v1/audio/transcriptions"),
13
+ api_url: str = (os.environ.get("BASE_URL") or "https://api.openai.com/v1/audio/transcriptions"),
14
14
  timeout: float = 20,
15
15
  ):
16
16
  super().__init__(api_key, api_url=api_url, timeout=timeout)
@@ -11,8 +11,8 @@ class BaseLLM:
11
11
  def __init__(
12
12
  self,
13
13
  api_key: str = None,
14
- engine: str = os.environ.get("GPT_ENGINE") or "gpt-3.5-turbo",
15
- api_url: str = (os.environ.get("API_URL", None) or "https://api.openai.com/v1/chat/completions"),
14
+ engine: str = os.environ.get("MODEL") or "gpt-3.5-turbo",
15
+ api_url: str = (os.environ.get("BASE_URL", None) or "https://api.openai.com/v1/chat/completions"),
16
16
  system_prompt: str = prompt.chatgpt_system_prompt,
17
17
  proxy: str = None,
18
18
  timeout: float = 600,
@@ -74,8 +74,8 @@ class chatgpt(BaseLLM):
74
74
  def __init__(
75
75
  self,
76
76
  api_key: str = None,
77
- engine: str = os.environ.get("GPT_ENGINE") or "gpt-4o",
78
- api_url: str = (os.environ.get("API_URL") or "https://api.openai.com/v1/chat/completions"),
77
+ engine: str = os.environ.get("MODEL") or "gpt-4o",
78
+ api_url: str = (os.environ.get("BASE_URL") or "https://api.openai.com/v1/chat/completions"),
79
79
  system_prompt: str = "You are ChatGPT, a large language model trained by OpenAI. Respond conversationally",
80
80
  proxy: str = None,
81
81
  timeout: float = 600,
@@ -5,13 +5,13 @@ from ..models.base import BaseLLM
5
5
  from .registry import register_tool
6
6
 
7
7
  API = os.environ.get('API', None)
8
- API_URL = os.environ.get('API_URL', None)
8
+ BASE_URL = os.environ.get('BASE_URL', None)
9
9
 
10
10
  class dalle3(BaseLLM):
11
11
  def __init__(
12
12
  self,
13
13
  api_key: str,
14
- api_url: str = (os.environ.get("API_URL") or "https://api.openai.com/v1/images/generations"),
14
+ api_url: str = (os.environ.get("BASE_URL") or "https://api.openai.com/v1/images/generations"),
15
15
  timeout: float = 20,
16
16
  ):
17
17
  super().__init__(api_key, api_url=api_url, timeout=timeout)
@@ -90,10 +90,6 @@ chatgpt_system_prompt = (
90
90
  "You are ChatGPT, a large language model trained by OpenAI. Use simple characters to represent mathematical symbols. Do not use LaTeX commands. Respond conversationally"
91
91
  )
92
92
 
93
- claude_system_prompt = (
94
- "You are Claude, a large language model trained by Anthropic. Use simple characters to represent mathematical symbols. Do not use LaTeX commands. Respond conversationally in {}."
95
- )
96
-
97
93
  search_system_prompt = (
98
94
  "You are ChatGPT, a large language model trained by OpenAI. Respond conversationally in {}."
99
95
  "You can break down the task into multiple steps and search the web to answer my questions one by one."
@@ -134,14 +134,6 @@ def is_surrounded_by_chinese(text, index):
134
134
  def replace_char(string, index, new_char):
135
135
  return string[:index] + new_char + string[index+1:]
136
136
 
137
- def claude_replace(text):
138
- Punctuation_mapping = {",": ",", ":": ":", "!": "!", "?": "?", ";": ";"}
139
- key_list = list(Punctuation_mapping.keys())
140
- for i in range(len(text)):
141
- if is_surrounded_by_chinese(text, i) and (text[i] in key_list):
142
- text = replace_char(text, i, Punctuation_mapping[text[i]])
143
- return text
144
-
145
137
  def safe_get(data, *keys, default=None):
146
138
  for key in keys:
147
139
  try:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aient
3
- Version: 1.2.27
3
+ Version: 1.2.30
4
4
  Summary: Aient: The Awakening of Agent.
5
5
  Requires-Python: >=3.11
6
6
  Description-Content-Type: text/markdown
@@ -48,7 +48,5 @@ test/test_ddg_search.py
48
48
  test/test_google_search.py
49
49
  test/test_ollama.py
50
50
  test/test_plugin.py
51
- test/test_search.py
52
51
  test/test_url.py
53
- test/test_whisper.py
54
- test/test_yjh.py
52
+ test/test_whisper.py
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "aient"
3
- version = "1.2.27"
3
+ version = "1.2.30"
4
4
  description = "Aient: The Awakening of Agent."
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.11"
@@ -10,5 +10,5 @@ files = {
10
10
  'model': (None, 'whisper-1')
11
11
  }
12
12
 
13
- response = requests.post(os.environ.get('API_URL', None), headers=headers, files=files)
13
+ response = requests.post(os.environ.get('BASE_URL', None), headers=headers, files=files)
14
14
  print(response.text)
@@ -1,18 +0,0 @@
1
- import os
2
- from aient.models import chatgpt
3
-
4
- API = os.environ.get('API', None)
5
- API_URL = os.environ.get('API_URL', None)
6
- GPT_ENGINE = os.environ.get('GPT_ENGINE', 'gpt-4o')
7
-
8
- systemprompt = (
9
- "You are ChatGPT, a large language model trained by OpenAI. Respond conversationally"
10
- )
11
- bot = chatgpt(api_key=API, api_url=API_URL, engine=GPT_ENGINE, system_prompt=systemprompt, print_log=True)
12
- for text in bot.ask_stream("搜索上海的天气"):
13
- # for text in bot.ask_stream("我在广州市,想周一去香港,周四早上回来,是去游玩,请你帮我规划整个行程。包括细节,如交通,住宿,餐饮,价格,等等,最好细节到每天各个部分的时间,花费,等等,尽量具体,用户一看就能直接执行的那种"):
14
- # for text in bot.ask_stream("上海有哪些好玩的地方?"):
15
- # for text in bot.ask_stream("just say test"):
16
- # for text in bot.ask_stream("我在上海想去重庆旅游,我只有2000元预算,我想在重庆玩一周,你能帮我规划一下吗?"):
17
- # for text in bot.ask_stream("我在上海想去重庆旅游,我有一天的时间。你能帮我规划一下吗?"):
18
- print(text, end="")
@@ -1,21 +0,0 @@
1
- import os
2
- from datetime import datetime
3
-
4
- from aient.models import chatgpt
5
- from aient.utils import prompt
6
-
7
- API = os.environ.get('API', None)
8
- API_URL = os.environ.get('API_URL', None)
9
- GPT_ENGINE = os.environ.get('GPT_ENGINE', 'gpt-4o')
10
- LANGUAGE = os.environ.get('LANGUAGE', 'Simplified Chinese')
11
-
12
- current_date = datetime.now()
13
- Current_Date = current_date.strftime("%Y-%m-%d")
14
-
15
- systemprompt = os.environ.get('SYSTEMPROMPT', prompt.system_prompt.format(LANGUAGE, Current_Date))
16
-
17
- bot = chatgpt(api_key=API, api_url=API_URL, engine=GPT_ENGINE, system_prompt=systemprompt)
18
- for text in bot.ask_stream("arXiv:2210.10716 这篇文章讲了啥"):
19
- # for text in bot.ask_stream("今天的微博热搜有哪些?"):
20
- # for text in bot.ask_stream("你现在是什么版本?"):
21
- print(text, end="")
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