aient 1.1.84__py3-none-any.whl → 1.1.86__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 +5 -6
- aient/models/chatgpt.py +19 -1
- {aient-1.1.84.dist-info → aient-1.1.86.dist-info}/METADATA +1 -1
- {aient-1.1.84.dist-info → aient-1.1.86.dist-info}/RECORD +7 -7
- {aient-1.1.84.dist-info → aient-1.1.86.dist-info}/WHEEL +0 -0
- {aient-1.1.84.dist-info → aient-1.1.86.dist-info}/licenses/LICENSE +0 -0
- {aient-1.1.84.dist-info → aient-1.1.86.dist-info}/top_level.txt +0 -0
aient/core/response.py
CHANGED
@@ -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
|
|
@@ -77,7 +76,7 @@ async def fetch_gemini_response_stream(client, url, headers, payload, model, tim
|
|
77
76
|
if line.startswith("data: "):
|
78
77
|
parts_json = line.lstrip("data: ").strip()
|
79
78
|
try:
|
80
|
-
await asyncio.to_thread(json.loads, parts_json)
|
79
|
+
response_json = await asyncio.to_thread(json.loads, parts_json)
|
81
80
|
except json.JSONDecodeError:
|
82
81
|
logger.error(f"JSON decode error: {parts_json}")
|
83
82
|
continue
|
@@ -85,12 +84,12 @@ async def fetch_gemini_response_stream(client, url, headers, payload, model, tim
|
|
85
84
|
parts_json += line
|
86
85
|
parts_json = parts_json.lstrip("[,")
|
87
86
|
try:
|
88
|
-
await asyncio.to_thread(json.loads, parts_json)
|
87
|
+
response_json = await asyncio.to_thread(json.loads, parts_json)
|
89
88
|
except json.JSONDecodeError:
|
90
89
|
continue
|
91
90
|
|
92
91
|
# https://ai.google.dev/api/generate-content?hl=zh-cn#FinishReason
|
93
|
-
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)
|
94
93
|
|
95
94
|
if is_thinking:
|
96
95
|
sse_string = await generate_sse_response(timestamp, model, reasoning_content=reasoning_content)
|
aient/models/chatgpt.py
CHANGED
@@ -37,10 +37,18 @@ class RateLimitError(Exception):
|
|
37
37
|
"""Custom exception for rate limit (429) errors."""
|
38
38
|
pass
|
39
39
|
|
40
|
+
class BadRequestError(Exception):
|
41
|
+
"""Custom exception for bad request (400) errors."""
|
42
|
+
pass
|
43
|
+
|
40
44
|
class HTTPError(Exception):
|
41
45
|
"""Custom exception for HTTP 500 errors."""
|
42
46
|
pass
|
43
47
|
|
48
|
+
class InputTokenCountExceededError(Exception):
|
49
|
+
"""Custom exception for input token count exceeding the maximum."""
|
50
|
+
pass
|
51
|
+
|
44
52
|
class ConfigurationError(Exception):
|
45
53
|
"""Custom exception for configuration errors."""
|
46
54
|
pass
|
@@ -802,6 +810,10 @@ class chatgpt(BaseLLM):
|
|
802
810
|
raise ModelNotFoundError(f"Model: {model or self.engine} not found!")
|
803
811
|
if "HTTP Error', 'status_code': 429" in processed_chunk:
|
804
812
|
raise RateLimitError(f"Rate limit exceeded for model: {model or self.engine}")
|
813
|
+
if "HTTP Error', 'status_code': 413" in processed_chunk:
|
814
|
+
raise InputTokenCountExceededError(processed_chunk)
|
815
|
+
if "HTTP Error', 'status_code': 400" in processed_chunk:
|
816
|
+
raise BadRequestError(f"Bad Request: {processed_chunk}")
|
805
817
|
if "HTTP Error', 'status_code': " in processed_chunk:
|
806
818
|
raise HTTPError(f"HTTP Error: {processed_chunk}")
|
807
819
|
yield processed_chunk
|
@@ -814,7 +826,7 @@ class chatgpt(BaseLLM):
|
|
814
826
|
return # Stop iteration
|
815
827
|
except httpx.RemoteProtocolError:
|
816
828
|
continue
|
817
|
-
except httpx.ReadError:
|
829
|
+
except httpx.ReadError as e:
|
818
830
|
self.logger.warning(f"{e}, retrying...")
|
819
831
|
continue
|
820
832
|
except APITimeoutError:
|
@@ -826,6 +838,12 @@ class chatgpt(BaseLLM):
|
|
826
838
|
except RateLimitError as e:
|
827
839
|
self.logger.warning(f"{e}, retrying...")
|
828
840
|
continue
|
841
|
+
except InputTokenCountExceededError as e:
|
842
|
+
self.logger.error(f"The request body is too long: {e}")
|
843
|
+
raise
|
844
|
+
except BadRequestError as e:
|
845
|
+
self.logger.error(f"Bad request error: {e}")
|
846
|
+
raise
|
829
847
|
except ValidationError as e:
|
830
848
|
self.logger.warning(f"Validation failed: {e}. Retrying with corrective prompt.")
|
831
849
|
need_done_prompt = [
|
@@ -3,7 +3,7 @@ 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=KMlCRLjtq1wQHZTJGqnbWhPS2cHq6eLdnk7peKDrzR8,7490
|
5
5
|
aient/core/request.py,sha256=QnDhyrjzcJOEQU2oauMQi_HHMRR5NxdkrX7nn5JMwTc,76675
|
6
|
-
aient/core/response.py,sha256=
|
6
|
+
aient/core/response.py,sha256=waC-i5i04bwooqNAgjmX30nx0IJ1nLITPeF0RCYwRs0,35620
|
7
7
|
aient/core/utils.py,sha256=okDFj8S4r71vnkEBYxiOqoKee63UzNyk2y_p4uhWBvY,28848
|
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
|
@@ -12,7 +12,7 @@ aient/core/test/test_payload.py,sha256=8jBiJY1uidm1jzL-EiK0s6UGmW9XkdsuuKFGrwFhF
|
|
12
12
|
aient/models/__init__.py,sha256=ZTiZgbfBPTjIPSKURE7t6hlFBVLRS9lluGbmqc1WjxQ,43
|
13
13
|
aient/models/audio.py,sha256=kRd-8-WXzv4vwvsTGwnstK-WR8--vr9CdfCZzu8y9LA,1934
|
14
14
|
aient/models/base.py,sha256=-nnihYnx-vHZMqeVO9ljjt3k4FcD3n-iMk4tT-10nRQ,7232
|
15
|
-
aient/models/chatgpt.py,sha256
|
15
|
+
aient/models/chatgpt.py,sha256=-3bOA_jLsePy3B77Q5C1C3UglY0NDc9dRMDi7bAdcNw,47056
|
16
16
|
aient/plugins/__init__.py,sha256=p3KO6Aa3Lupos4i2SjzLQw1hzQTigOAfEHngsldrsyk,986
|
17
17
|
aient/plugins/arXiv.py,sha256=yHjb6PS3GUWazpOYRMKMzghKJlxnZ5TX8z9F6UtUVow,1461
|
18
18
|
aient/plugins/config.py,sha256=TGgZ5SnNKZ8MmdznrZ-TEq7s2ulhAAwTSKH89bci3dA,7079
|
@@ -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.
|
34
|
-
aient-1.1.
|
35
|
-
aient-1.1.
|
36
|
-
aient-1.1.
|
37
|
-
aient-1.1.
|
33
|
+
aient-1.1.86.dist-info/licenses/LICENSE,sha256=XNdbcWldt0yaNXXWB_Bakoqnxb3OVhUft4MgMA_71ds,1051
|
34
|
+
aient-1.1.86.dist-info/METADATA,sha256=WTsDczZLe_c5md4EyuWASjIGxISX3QUrMl9LFygjXJ0,4842
|
35
|
+
aient-1.1.86.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
36
|
+
aient-1.1.86.dist-info/top_level.txt,sha256=3oXzrP5sAVvyyqabpeq8A2_vfMtY554r4bVE-OHBrZk,6
|
37
|
+
aient-1.1.86.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|