aient 1.1.83__tar.gz → 1.1.85__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.
- {aient-1.1.83 → aient-1.1.85}/PKG-INFO +1 -1
- {aient-1.1.83 → aient-1.1.85}/aient/core/response.py +23 -15
- {aient-1.1.83 → aient-1.1.85}/aient/models/chatgpt.py +9 -3
- {aient-1.1.83 → aient-1.1.85}/aient.egg-info/PKG-INFO +1 -1
- {aient-1.1.83 → aient-1.1.85}/pyproject.toml +1 -1
- {aient-1.1.83 → aient-1.1.85}/LICENSE +0 -0
- {aient-1.1.83 → aient-1.1.85}/README.md +0 -0
- {aient-1.1.83 → aient-1.1.85}/aient/__init__.py +0 -0
- {aient-1.1.83 → aient-1.1.85}/aient/core/__init__.py +0 -0
- {aient-1.1.83 → aient-1.1.85}/aient/core/log_config.py +0 -0
- {aient-1.1.83 → aient-1.1.85}/aient/core/models.py +0 -0
- {aient-1.1.83 → aient-1.1.85}/aient/core/request.py +0 -0
- {aient-1.1.83 → aient-1.1.85}/aient/core/test/test_base_api.py +0 -0
- {aient-1.1.83 → aient-1.1.85}/aient/core/test/test_geminimask.py +0 -0
- {aient-1.1.83 → aient-1.1.85}/aient/core/test/test_image.py +0 -0
- {aient-1.1.83 → aient-1.1.85}/aient/core/test/test_payload.py +0 -0
- {aient-1.1.83 → aient-1.1.85}/aient/core/utils.py +0 -0
- {aient-1.1.83 → aient-1.1.85}/aient/models/__init__.py +0 -0
- {aient-1.1.83 → aient-1.1.85}/aient/models/audio.py +0 -0
- {aient-1.1.83 → aient-1.1.85}/aient/models/base.py +0 -0
- {aient-1.1.83 → aient-1.1.85}/aient/plugins/__init__.py +0 -0
- {aient-1.1.83 → aient-1.1.85}/aient/plugins/arXiv.py +0 -0
- {aient-1.1.83 → aient-1.1.85}/aient/plugins/config.py +0 -0
- {aient-1.1.83 → aient-1.1.85}/aient/plugins/excute_command.py +0 -0
- {aient-1.1.83 → aient-1.1.85}/aient/plugins/get_time.py +0 -0
- {aient-1.1.83 → aient-1.1.85}/aient/plugins/image.py +0 -0
- {aient-1.1.83 → aient-1.1.85}/aient/plugins/list_directory.py +0 -0
- {aient-1.1.83 → aient-1.1.85}/aient/plugins/read_file.py +0 -0
- {aient-1.1.83 → aient-1.1.85}/aient/plugins/read_image.py +0 -0
- {aient-1.1.83 → aient-1.1.85}/aient/plugins/readonly.py +0 -0
- {aient-1.1.83 → aient-1.1.85}/aient/plugins/registry.py +0 -0
- {aient-1.1.83 → aient-1.1.85}/aient/plugins/run_python.py +0 -0
- {aient-1.1.83 → aient-1.1.85}/aient/plugins/websearch.py +0 -0
- {aient-1.1.83 → aient-1.1.85}/aient/plugins/write_file.py +0 -0
- {aient-1.1.83 → aient-1.1.85}/aient/utils/__init__.py +0 -0
- {aient-1.1.83 → aient-1.1.85}/aient/utils/prompt.py +0 -0
- {aient-1.1.83 → aient-1.1.85}/aient/utils/scripts.py +0 -0
- {aient-1.1.83 → aient-1.1.85}/aient.egg-info/SOURCES.txt +0 -0
- {aient-1.1.83 → aient-1.1.85}/aient.egg-info/dependency_links.txt +0 -0
- {aient-1.1.83 → aient-1.1.85}/aient.egg-info/requires.txt +0 -0
- {aient-1.1.83 → aient-1.1.85}/aient.egg-info/top_level.txt +0 -0
- {aient-1.1.83 → aient-1.1.85}/setup.cfg +0 -0
- {aient-1.1.83 → aient-1.1.85}/test/test_Web_crawler.py +0 -0
- {aient-1.1.83 → aient-1.1.85}/test/test_ddg_search.py +0 -0
- {aient-1.1.83 → aient-1.1.85}/test/test_google_search.py +0 -0
- {aient-1.1.83 → aient-1.1.85}/test/test_ollama.py +0 -0
- {aient-1.1.83 → aient-1.1.85}/test/test_plugin.py +0 -0
- {aient-1.1.83 → aient-1.1.85}/test/test_search.py +0 -0
- {aient-1.1.83 → aient-1.1.85}/test/test_url.py +0 -0
- {aient-1.1.83 → aient-1.1.85}/test/test_whisper.py +0 -0
- {aient-1.1.83 → aient-1.1.85}/test/test_yjh.py +0 -0
@@ -21,13 +21,12 @@ async def check_response(response, error_log):
|
|
21
21
|
return {"error": f"{error_log} HTTP Error", "status_code": response.status_code, "details": error_json}
|
22
22
|
return None
|
23
23
|
|
24
|
-
async def gemini_json_poccess(
|
24
|
+
async def gemini_json_poccess(response_json):
|
25
25
|
promptTokenCount = 0
|
26
26
|
candidatesTokenCount = 0
|
27
27
|
totalTokenCount = 0
|
28
28
|
image_base64 = None
|
29
29
|
|
30
|
-
response_json = await asyncio.to_thread(json.loads, response_str)
|
31
30
|
json_data = safe_get(response_json, "candidates", 0, "content", default=None)
|
32
31
|
finishReason = safe_get(response_json, "candidates", 0 , "finishReason", default=None)
|
33
32
|
if finishReason:
|
@@ -48,7 +47,7 @@ async def gemini_json_poccess(response_str):
|
|
48
47
|
|
49
48
|
function_call_name = safe_get(json_data, "functionCall", "name", default=None)
|
50
49
|
function_full_response = safe_get(json_data, "functionCall", "args", default="")
|
51
|
-
function_full_response = json.dumps
|
50
|
+
function_full_response = await asyncio.to_thread(json.dumps, function_full_response) if function_full_response else None
|
52
51
|
|
53
52
|
blockReason = safe_get(json_data, 0, "promptFeedback", "blockReason", default=None)
|
54
53
|
|
@@ -56,7 +55,8 @@ async def gemini_json_poccess(response_str):
|
|
56
55
|
|
57
56
|
async def fetch_gemini_response_stream(client, url, headers, payload, model, timeout):
|
58
57
|
timestamp = int(datetime.timestamp(datetime.now()))
|
59
|
-
|
58
|
+
json_payload = await asyncio.to_thread(json.dumps, payload)
|
59
|
+
async with client.stream('POST', url, headers=headers, content=json_payload, timeout=timeout) as response:
|
60
60
|
error_message = await check_response(response, "fetch_gemini_response_stream")
|
61
61
|
if error_message:
|
62
62
|
yield error_message
|
@@ -76,7 +76,7 @@ async def fetch_gemini_response_stream(client, url, headers, payload, model, tim
|
|
76
76
|
if line.startswith("data: "):
|
77
77
|
parts_json = line.lstrip("data: ").strip()
|
78
78
|
try:
|
79
|
-
await asyncio.to_thread(json.loads, parts_json)
|
79
|
+
response_json = await asyncio.to_thread(json.loads, parts_json)
|
80
80
|
except json.JSONDecodeError:
|
81
81
|
logger.error(f"JSON decode error: {parts_json}")
|
82
82
|
continue
|
@@ -84,12 +84,12 @@ async def fetch_gemini_response_stream(client, url, headers, payload, model, tim
|
|
84
84
|
parts_json += line
|
85
85
|
parts_json = parts_json.lstrip("[,")
|
86
86
|
try:
|
87
|
-
await asyncio.to_thread(json.loads, parts_json)
|
87
|
+
response_json = await asyncio.to_thread(json.loads, parts_json)
|
88
88
|
except json.JSONDecodeError:
|
89
89
|
continue
|
90
90
|
|
91
91
|
# https://ai.google.dev/api/generate-content?hl=zh-cn#FinishReason
|
92
|
-
is_thinking, reasoning_content, content, image_base64, function_call_name, function_full_response, finishReason, blockReason, promptTokenCount, candidatesTokenCount, totalTokenCount = await gemini_json_poccess(
|
92
|
+
is_thinking, reasoning_content, content, image_base64, function_call_name, function_full_response, finishReason, blockReason, promptTokenCount, candidatesTokenCount, totalTokenCount = await gemini_json_poccess(response_json)
|
93
93
|
|
94
94
|
if is_thinking:
|
95
95
|
sse_string = await generate_sse_response(timestamp, model, reasoning_content=reasoning_content)
|
@@ -125,7 +125,8 @@ async def fetch_gemini_response_stream(client, url, headers, payload, model, tim
|
|
125
125
|
|
126
126
|
async def fetch_vertex_claude_response_stream(client, url, headers, payload, model, timeout):
|
127
127
|
timestamp = int(datetime.timestamp(datetime.now()))
|
128
|
-
|
128
|
+
json_payload = await asyncio.to_thread(json.dumps, payload)
|
129
|
+
async with client.stream('POST', url, headers=headers, content=json_payload, timeout=timeout) as response:
|
129
130
|
error_message = await check_response(response, "fetch_vertex_claude_response_stream")
|
130
131
|
if error_message:
|
131
132
|
yield error_message
|
@@ -198,7 +199,8 @@ async def fetch_gpt_response_stream(client, url, headers, payload, timeout):
|
|
198
199
|
is_thinking = False
|
199
200
|
has_send_thinking = False
|
200
201
|
ark_tag = False
|
201
|
-
|
202
|
+
json_payload = await asyncio.to_thread(json.dumps, payload)
|
203
|
+
async with client.stream('POST', url, headers=headers, content=json_payload, timeout=timeout) as response:
|
202
204
|
error_message = await check_response(response, "fetch_gpt_response_stream")
|
203
205
|
if error_message:
|
204
206
|
yield error_message
|
@@ -312,7 +314,8 @@ async def fetch_azure_response_stream(client, url, headers, payload, timeout):
|
|
312
314
|
is_thinking = False
|
313
315
|
has_send_thinking = False
|
314
316
|
ark_tag = False
|
315
|
-
|
317
|
+
json_payload = await asyncio.to_thread(json.dumps, payload)
|
318
|
+
async with client.stream('POST', url, headers=headers, content=json_payload, timeout=timeout) as response:
|
316
319
|
error_message = await check_response(response, "fetch_azure_response_stream")
|
317
320
|
if error_message:
|
318
321
|
yield error_message
|
@@ -365,7 +368,8 @@ async def fetch_azure_response_stream(client, url, headers, payload, timeout):
|
|
365
368
|
|
366
369
|
async def fetch_cloudflare_response_stream(client, url, headers, payload, model, timeout):
|
367
370
|
timestamp = int(datetime.timestamp(datetime.now()))
|
368
|
-
|
371
|
+
json_payload = await asyncio.to_thread(json.dumps, payload)
|
372
|
+
async with client.stream('POST', url, headers=headers, content=json_payload, timeout=timeout) as response:
|
369
373
|
error_message = await check_response(response, "fetch_cloudflare_response_stream")
|
370
374
|
if error_message:
|
371
375
|
yield error_message
|
@@ -390,7 +394,8 @@ async def fetch_cloudflare_response_stream(client, url, headers, payload, model,
|
|
390
394
|
|
391
395
|
async def fetch_cohere_response_stream(client, url, headers, payload, model, timeout):
|
392
396
|
timestamp = int(datetime.timestamp(datetime.now()))
|
393
|
-
|
397
|
+
json_payload = await asyncio.to_thread(json.dumps, payload)
|
398
|
+
async with client.stream('POST', url, headers=headers, content=json_payload, timeout=timeout) as response:
|
394
399
|
error_message = await check_response(response, "fetch_cohere_response_stream")
|
395
400
|
if error_message:
|
396
401
|
yield error_message
|
@@ -413,7 +418,8 @@ async def fetch_cohere_response_stream(client, url, headers, payload, model, tim
|
|
413
418
|
|
414
419
|
async def fetch_claude_response_stream(client, url, headers, payload, model, timeout):
|
415
420
|
timestamp = int(datetime.timestamp(datetime.now()))
|
416
|
-
|
421
|
+
json_payload = await asyncio.to_thread(json.dumps, payload)
|
422
|
+
async with client.stream('POST', url, headers=headers, content=json_payload, timeout=timeout) as response:
|
417
423
|
error_message = await check_response(response, "fetch_claude_response_stream")
|
418
424
|
if error_message:
|
419
425
|
yield error_message
|
@@ -466,7 +472,8 @@ async def fetch_claude_response_stream(client, url, headers, payload, model, tim
|
|
466
472
|
|
467
473
|
async def fetch_aws_response_stream(client, url, headers, payload, model, timeout):
|
468
474
|
timestamp = int(datetime.timestamp(datetime.now()))
|
469
|
-
|
475
|
+
json_payload = await asyncio.to_thread(json.dumps, payload)
|
476
|
+
async with client.stream('POST', url, headers=headers, content=json_payload, timeout=timeout) as response:
|
470
477
|
error_message = await check_response(response, "fetch_aws_response_stream")
|
471
478
|
if error_message:
|
472
479
|
yield error_message
|
@@ -521,7 +528,8 @@ async def fetch_response(client, url, headers, payload, engine, model, timeout=2
|
|
521
528
|
file = payload.pop("file")
|
522
529
|
response = await client.post(url, headers=headers, data=payload, files={"file": file}, timeout=timeout)
|
523
530
|
else:
|
524
|
-
|
531
|
+
json_payload = await asyncio.to_thread(json.dumps, payload)
|
532
|
+
response = await client.post(url, headers=headers, content=json_payload, timeout=timeout)
|
525
533
|
error_message = await check_response(response, "fetch_response")
|
526
534
|
if error_message:
|
527
535
|
yield error_message
|
@@ -236,6 +236,10 @@ class chatgpt(BaseLLM):
|
|
236
236
|
if type(self.conversation[convo_id][message_index]["content"]) == list \
|
237
237
|
and type(self.conversation[convo_id][message_index + 1]["content"]) == dict:
|
238
238
|
self.conversation[convo_id][message_index + 1]["content"] = [self.conversation[convo_id][message_index + 1]["content"]]
|
239
|
+
if type(self.conversation[convo_id][message_index]["content"]) == str \
|
240
|
+
and type(self.conversation[convo_id][message_index + 1]["content"]) == str \
|
241
|
+
and self.conversation[convo_id][message_index].get("content").endswith(self.conversation[convo_id][message_index + 1].get("content")):
|
242
|
+
self.conversation[convo_id][message_index + 1]["content"] = ""
|
239
243
|
self.conversation[convo_id][message_index]["content"] += self.conversation[convo_id][message_index + 1]["content"]
|
240
244
|
self.conversation[convo_id].pop(message_index + 1)
|
241
245
|
conversation_len = conversation_len - 1
|
@@ -744,7 +748,8 @@ class chatgpt(BaseLLM):
|
|
744
748
|
need_done_prompt = False
|
745
749
|
|
746
750
|
# 发送请求并处理响应
|
747
|
-
|
751
|
+
retry_times = 0
|
752
|
+
while True:
|
748
753
|
tmp_post_json = copy.deepcopy(json_post)
|
749
754
|
if need_done_prompt:
|
750
755
|
tmp_post_json["messages"].extend(need_done_prompt)
|
@@ -809,7 +814,7 @@ class chatgpt(BaseLLM):
|
|
809
814
|
return # Stop iteration
|
810
815
|
except httpx.RemoteProtocolError:
|
811
816
|
continue
|
812
|
-
except httpx.ReadError:
|
817
|
+
except httpx.ReadError as e:
|
813
818
|
self.logger.warning(f"{e}, retrying...")
|
814
819
|
continue
|
815
820
|
except APITimeoutError:
|
@@ -843,7 +848,8 @@ class chatgpt(BaseLLM):
|
|
843
848
|
error_message = "您输入了无效的API URL,请使用正确的URL并使用`/start`命令重新设置API URL。具体错误如下:\n\n" + str(e)
|
844
849
|
raise ConfigurationError(error_message)
|
845
850
|
# 最后一次重试失败,向上抛出异常
|
846
|
-
|
851
|
+
retry_times += 1
|
852
|
+
if retry_times == 9:
|
847
853
|
raise RetryFailedError(str(e))
|
848
854
|
|
849
855
|
def ask_stream(
|
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
|
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
|