aient 1.1.63__py3-none-any.whl → 1.1.65__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/core/response.py CHANGED
@@ -426,53 +426,41 @@ async def fetch_claude_response_stream(client, url, headers, payload, model):
426
426
  line, buffer = buffer.split("\n", 1)
427
427
  # logger.info(line)
428
428
 
429
- if line.startswith("data:"):
430
- line = line.lstrip("data: ")
429
+ if line.startswith("data:") and (line := line.lstrip("data: ")):
431
430
  resp: dict = json.loads(line)
432
- message = resp.get("message")
433
- if message:
434
- role = message.get("role")
435
- if role:
436
- sse_string = await generate_sse_response(timestamp, model, None, None, None, None, role)
437
- yield sse_string
438
- tokens_use = message.get("usage")
439
- if tokens_use:
440
- input_tokens = tokens_use.get("input_tokens", 0)
441
- usage = resp.get("usage")
442
- if usage:
443
- output_tokens = usage.get("output_tokens", 0)
431
+
432
+ input_tokens = input_tokens or safe_get(resp, "message", "usage", "input_tokens", default=0)
433
+ # cache_creation_input_tokens = safe_get(resp, "message", "usage", "cache_creation_input_tokens", default=0)
434
+ # cache_read_input_tokens = safe_get(resp, "message", "usage", "cache_read_input_tokens", default=0)
435
+ output_tokens = safe_get(resp, "usage", "output_tokens", default=0)
436
+ if output_tokens:
444
437
  total_tokens = input_tokens + output_tokens
445
438
  sse_string = await generate_sse_response(timestamp, model, None, None, None, None, None, total_tokens, input_tokens, output_tokens)
446
439
  yield sse_string
447
- # print("\n\rtotal_tokens", total_tokens)
448
-
449
- tool_use = resp.get("content_block")
450
- tools_id = None
451
- function_call_name = None
452
- if tool_use and "tool_use" == tool_use['type']:
453
- # print("tool_use", tool_use)
454
- tools_id = tool_use["id"]
455
- if "name" in tool_use:
456
- function_call_name = tool_use["name"]
457
- sse_string = await generate_sse_response(timestamp, model, None, tools_id, function_call_name, None)
458
- yield sse_string
459
- delta = resp.get("delta")
460
- # print("delta", delta)
461
- if not delta:
440
+ break
441
+
442
+ text = safe_get(resp, "delta", "text", default="")
443
+ if text:
444
+ sse_string = await generate_sse_response(timestamp, model, text)
445
+ yield sse_string
462
446
  continue
463
- if "text" in delta:
464
- content = delta["text"]
465
- sse_string = await generate_sse_response(timestamp, model, content, None, None)
447
+
448
+ function_call_name = safe_get(resp, "content_block", "name", default=None)
449
+ tools_id = safe_get(resp, "content_block", "id", default=None)
450
+ if tools_id and function_call_name:
451
+ sse_string = await generate_sse_response(timestamp, model, None, tools_id, function_call_name, None)
466
452
  yield sse_string
467
- if "thinking" in delta and delta["thinking"]:
468
- content = delta["thinking"]
469
- sse_string = await generate_sse_response(timestamp, model, reasoning_content=content)
453
+
454
+ thinking_content = safe_get(resp, "delta", "thinking", default="")
455
+ if thinking_content:
456
+ sse_string = await generate_sse_response(timestamp, model, reasoning_content=thinking_content)
470
457
  yield sse_string
471
- if "partial_json" in delta:
472
- # {"type":"input_json_delta","partial_json":""}
473
- function_call_content = delta["partial_json"]
458
+
459
+ function_call_content = safe_get(resp, "delta", "partial_json", default="")
460
+ if function_call_content:
474
461
  sse_string = await generate_sse_response(timestamp, model, None, None, None, function_call_content)
475
462
  yield sse_string
463
+
476
464
  yield "data: [DONE]" + end_of_line
477
465
 
478
466
  async def fetch_aws_response_stream(client, url, headers, payload, model):
aient/core/utils.py CHANGED
@@ -46,7 +46,10 @@ class BaseAPI:
46
46
  before_v1 = ""
47
47
  self.base_url: str = urlunparse(parsed_url[:2] + ("",) + ("",) * 3)
48
48
  self.v1_url: str = urlunparse(parsed_url[:2]+ (before_v1,) + ("",) * 3)
49
- self.v1_models: str = urlunparse(parsed_url[:2] + (before_v1 + "models",) + ("",) * 3)
49
+ if "v1/messages" in parsed_url.path:
50
+ self.v1_models: str = urlunparse(parsed_url[:2] + ("v1/models",) + ("",) * 3)
51
+ else:
52
+ self.v1_models: str = urlunparse(parsed_url[:2] + (before_v1 + "models",) + ("",) * 3)
50
53
  self.chat_url: str = urlunparse(parsed_url[:2] + (before_v1 + "chat/completions",) + ("",) * 3)
51
54
  self.image_url: str = urlunparse(parsed_url[:2] + (before_v1 + "images/generations",) + ("",) * 3)
52
55
  if parsed_url.hostname == "dashscope.aliyuncs.com":
@@ -192,7 +195,10 @@ def update_initial_model(provider):
192
195
  endpoint_models_url = endpoint.v1_models
193
196
  if isinstance(api, list):
194
197
  api = api[0]
195
- headers = {"Authorization": f"Bearer {api}"}
198
+ if "v1/messages" in api_url:
199
+ headers = {"x-api-key": api, "anthropic-version": "2023-06-01"}
200
+ else:
201
+ headers = {"Authorization": f"Bearer {api}"}
196
202
  response = httpx.get(
197
203
  endpoint_models_url,
198
204
  headers=headers,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aient
3
- Version: 1.1.63
3
+ Version: 1.1.65
4
4
  Summary: Aient: The Awakening of Agent.
5
5
  Requires-Python: >=3.11
6
6
  Description-Content-Type: text/markdown
@@ -25,7 +25,7 @@ Dynamic: license-file
25
25
 
26
26
  [English](./README.md) | [Chinese](./README_CN.md)
27
27
 
28
- aient is a powerful library designed to simplify and unify the use of different large language models, including GPT-3.5/4/4 Turbo/4o, o1-preview/o1-mini, DALL-E 3, Claude2/3/3.5, Gemini1.5 Pro/Flash, Vertex AI (Claude, Gemini), DuckDuckGo, and Groq. The library supports GPT format function calls and has built-in Google search and URL summarization features, greatly enhancing the practicality and flexibility of the models.
28
+ aient is a powerful library designed to simplify and unify the use of different large language models, including gpt-4.1/5, o3, DALL-E 3, claude4, gemini-2.5-pro/flash, Vertex AI (Claude, Gemini), and Groq. The library supports GPT format function calls and has built-in Google search and URL summarization features, greatly enhancing the practicality and flexibility of the models.
29
29
 
30
30
  ## ✨ Features
31
31
 
@@ -82,14 +82,13 @@ The following is a list of environment variables related to plugin settings:
82
82
 
83
83
  ## Supported models
84
84
 
85
- - GPT-3.5/4/4 Turbo/4o
86
- - o1-preview/o1-mini
85
+ - gpt-4.1/5
86
+ - o3
87
87
  - DALL-E 3
88
- - Claude2/3/3.5
89
- - Gemini1.5 Pro/Flash
88
+ - claude4
89
+ - gemini-2.5-pro/flash
90
90
  - Vertex AI (Claude, Gemini)
91
91
  - Groq
92
- - DuckDuckGo(gpt-4o-mini, claude-3-haiku, Meta-Llama-3.1-70B, Mixtral-8x7B)
93
92
 
94
93
  ## 🧩 Plugin
95
94
 
@@ -3,8 +3,8 @@ aient/core/__init__.py,sha256=NxjebTlku35S4Dzr16rdSqSTWUvvwEeACe8KvHJnjPg,34
3
3
  aient/core/log_config.py,sha256=kz2_yJv1p-o3lUQOwA3qh-LSc3wMHv13iCQclw44W9c,274
4
4
  aient/core/models.py,sha256=d4MISNezTSe0ls0-fjuToI2SoT-sk5fWqAJuKVinIlo,7502
5
5
  aient/core/request.py,sha256=M1AfroPgFDG7oTLE2gisvR4BdkUeWqoTwfpxl_nxYB8,76923
6
- aient/core/response.py,sha256=KbaNZYl1lwdt6itdJq2SSc5zmcaLSZ0wqLAbMqS6ODU,33760
7
- aient/core/utils.py,sha256=8TR442o3VV7Kl9l6f6LlmOUQ1UDZ-aXMzQqm-qIrqE4,28166
6
+ aient/core/response.py,sha256=sPcNV9qLosj3lIXElezUZEjIyglspdkBg-EsIUhr9bQ,33203
7
+ aient/core/utils.py,sha256=D98d5Cy1h4ejKtuxS0EEDtL4YqpaZLB5tuXoVP0IBWQ,28462
8
8
  aient/core/test/test_base_api.py,sha256=pWnycRJbuPSXKKU9AQjWrMAX1wiLC_014Qc9hh5C2Pw,524
9
9
  aient/core/test/test_geminimask.py,sha256=HFX8jDbNg_FjjgPNxfYaR-0-roUrOO-ND-FVsuxSoiw,13254
10
10
  aient/core/test/test_image.py,sha256=_T4peNGdXKBHHxyQNx12u-NTyFE8TlYI6NvvagsG2LE,319
@@ -30,8 +30,8 @@ aient/plugins/write_file.py,sha256=Jt8fOEwqhYiSWpCbwfAr1xoi_BmFnx3076GMhuL06uI,3
30
30
  aient/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
31
31
  aient/utils/prompt.py,sha256=UcSzKkFE4-h_1b6NofI6xgk3GoleqALRKY8VBaXLjmI,11311
32
32
  aient/utils/scripts.py,sha256=VqtK4RFEx7KxkmcqG3lFDS1DxoNlFFGErEjopVcc8IE,40974
33
- aient-1.1.63.dist-info/licenses/LICENSE,sha256=XNdbcWldt0yaNXXWB_Bakoqnxb3OVhUft4MgMA_71ds,1051
34
- aient-1.1.63.dist-info/METADATA,sha256=1bQur-vcYfC-P3tNZLdn_NtOf-IS7OhYE1VFqnEX1-A,4994
35
- aient-1.1.63.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
36
- aient-1.1.63.dist-info/top_level.txt,sha256=3oXzrP5sAVvyyqabpeq8A2_vfMtY554r4bVE-OHBrZk,6
37
- aient-1.1.63.dist-info/RECORD,,
33
+ aient-1.1.65.dist-info/licenses/LICENSE,sha256=XNdbcWldt0yaNXXWB_Bakoqnxb3OVhUft4MgMA_71ds,1051
34
+ aient-1.1.65.dist-info/METADATA,sha256=ybVwQ1ZUlaD9L4EDMBDp9ORdC8wrcmVBNxfCcRGvrRo,4842
35
+ aient-1.1.65.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
36
+ aient-1.1.65.dist-info/top_level.txt,sha256=3oXzrP5sAVvyyqabpeq8A2_vfMtY554r4bVE-OHBrZk,6
37
+ aient-1.1.65.dist-info/RECORD,,
File without changes