gemini-webapi 1.10.2__py3-none-any.whl → 1.11.1__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.
- gemini_webapi/client.py +35 -6
- gemini_webapi/constants.py +17 -2
- gemini_webapi/exceptions.py +24 -0
- {gemini_webapi-1.10.2.dist-info → gemini_webapi-1.11.1.dist-info}/METADATA +3 -2
- {gemini_webapi-1.10.2.dist-info → gemini_webapi-1.11.1.dist-info}/RECORD +8 -8
- {gemini_webapi-1.10.2.dist-info → gemini_webapi-1.11.1.dist-info}/WHEEL +1 -1
- {gemini_webapi-1.10.2.dist-info → gemini_webapi-1.11.1.dist-info}/licenses/LICENSE +0 -0
- {gemini_webapi-1.10.2.dist-info → gemini_webapi-1.11.1.dist-info}/top_level.txt +0 -0
gemini_webapi/client.py
CHANGED
|
@@ -8,8 +8,16 @@ from typing import Any, Optional
|
|
|
8
8
|
|
|
9
9
|
from httpx import AsyncClient, ReadTimeout
|
|
10
10
|
|
|
11
|
-
from .constants import Endpoint, Headers, Model
|
|
12
|
-
from .exceptions import
|
|
11
|
+
from .constants import Endpoint, ErrorCode, Headers, Model
|
|
12
|
+
from .exceptions import (
|
|
13
|
+
AuthError,
|
|
14
|
+
APIError,
|
|
15
|
+
TimeoutError,
|
|
16
|
+
GeminiError,
|
|
17
|
+
UsageLimitExceeded,
|
|
18
|
+
ModelInvalid,
|
|
19
|
+
TemporarilyBlocked,
|
|
20
|
+
)
|
|
13
21
|
from .types import WebImage, GeneratedImage, Candidate, ModelOutput
|
|
14
22
|
from .utils import (
|
|
15
23
|
upload_file,
|
|
@@ -376,10 +384,31 @@ class GeminiClient:
|
|
|
376
384
|
raise Exception
|
|
377
385
|
except Exception:
|
|
378
386
|
await self.close()
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
387
|
+
|
|
388
|
+
try:
|
|
389
|
+
match ErrorCode(response_json[0][5][2][0][1][0]):
|
|
390
|
+
case ErrorCode.USAGE_LIMIT_EXCEEDED:
|
|
391
|
+
raise UsageLimitExceeded(
|
|
392
|
+
f"Failed to generate contents. Usage limit of {model.model_name} model has exceeded. Please try switching to another model."
|
|
393
|
+
)
|
|
394
|
+
case ErrorCode.MODEL_HEADER_INVALID:
|
|
395
|
+
raise ModelInvalid(
|
|
396
|
+
"Failed to generate contents. The specified model is not available. Please update gemini_webapi to the latest version. "
|
|
397
|
+
"If the error persists and is caused by the package, please report it on GitHub."
|
|
398
|
+
)
|
|
399
|
+
case ErrorCode.IP_TEMPORARILY_BLOCKED:
|
|
400
|
+
raise TemporarilyBlocked(
|
|
401
|
+
"Failed to generate contents. Your IP address is temporarily blocked by Google. Please try using a proxy or waiting for a while."
|
|
402
|
+
)
|
|
403
|
+
case _:
|
|
404
|
+
raise Exception
|
|
405
|
+
except GeminiError:
|
|
406
|
+
raise
|
|
407
|
+
except Exception:
|
|
408
|
+
logger.debug(f"Invalid response: {response.text}")
|
|
409
|
+
raise APIError(
|
|
410
|
+
"Failed to generate contents. Invalid response data received. Client will try to re-initialize on next request."
|
|
411
|
+
)
|
|
383
412
|
|
|
384
413
|
try:
|
|
385
414
|
candidates = []
|
gemini_webapi/constants.py
CHANGED
|
@@ -27,17 +27,22 @@ class Model(Enum):
|
|
|
27
27
|
UNSPECIFIED = ("unspecified", {}, False)
|
|
28
28
|
G_2_0_FLASH = (
|
|
29
29
|
"gemini-2.0-flash",
|
|
30
|
-
{"x-goog-ext-525001261-jspb": '[
|
|
30
|
+
{"x-goog-ext-525001261-jspb": '[1,null,null,null,"f299729663a2343f"]'},
|
|
31
31
|
False,
|
|
32
32
|
)
|
|
33
33
|
G_2_0_FLASH_THINKING = (
|
|
34
34
|
"gemini-2.0-flash-thinking",
|
|
35
35
|
{"x-goog-ext-525001261-jspb": '[null,null,null,null,"7ca48d02d802f20a"]'},
|
|
36
36
|
False,
|
|
37
|
+
) # Deprecated
|
|
38
|
+
G_2_5_FLASH = (
|
|
39
|
+
"gemini-2.5-flash",
|
|
40
|
+
{"x-goog-ext-525001261-jspb": '[1,null,null,null,"35609594dbe934d8"]'},
|
|
41
|
+
False,
|
|
37
42
|
)
|
|
38
43
|
G_2_5_PRO = (
|
|
39
44
|
"gemini-2.5-pro",
|
|
40
|
-
{"x-goog-ext-525001261-jspb": '[
|
|
45
|
+
{"x-goog-ext-525001261-jspb": '[1,null,null,null,"2525e3954d185b3c"]'},
|
|
41
46
|
False,
|
|
42
47
|
)
|
|
43
48
|
G_2_0_EXP_ADVANCED = (
|
|
@@ -64,3 +69,13 @@ class Model(Enum):
|
|
|
64
69
|
raise ValueError(
|
|
65
70
|
f"Unknown model name: {name}. Available models: {', '.join([model.model_name for model in cls])}"
|
|
66
71
|
)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
class ErrorCode(Enum):
|
|
75
|
+
"""
|
|
76
|
+
Known error codes returned from server.
|
|
77
|
+
"""
|
|
78
|
+
|
|
79
|
+
USAGE_LIMIT_EXCEEDED = 1037
|
|
80
|
+
MODEL_HEADER_INVALID = 1052
|
|
81
|
+
IP_TEMPORARILY_BLOCKED = 1060
|
gemini_webapi/exceptions.py
CHANGED
|
@@ -28,3 +28,27 @@ class TimeoutError(GeminiError):
|
|
|
28
28
|
"""
|
|
29
29
|
|
|
30
30
|
pass
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class UsageLimitExceeded(GeminiError):
|
|
34
|
+
"""
|
|
35
|
+
Exception for model usage limit exceeded errors.
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
pass
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class ModelInvalid(GeminiError):
|
|
42
|
+
"""
|
|
43
|
+
Exception for invalid model header string errors.
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
pass
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class TemporarilyBlocked(GeminiError):
|
|
50
|
+
"""
|
|
51
|
+
Exception for 429 Too Many Requests when IP is temporarily blocked.
|
|
52
|
+
"""
|
|
53
|
+
|
|
54
|
+
pass
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: gemini-webapi
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.11.1
|
|
4
4
|
Summary: ✨ An elegant async Python wrapper for Google Gemini web app
|
|
5
5
|
Author: UZQueen
|
|
6
6
|
License: GNU AFFERO GENERAL PUBLIC LICENSE
|
|
@@ -822,9 +822,10 @@ You can specify which language model to use by passing `model` argument to `Gemi
|
|
|
822
822
|
|
|
823
823
|
Currently available models (as of Feb 5, 2025):
|
|
824
824
|
|
|
825
|
-
- `unspecified` - Default model
|
|
825
|
+
- `unspecified` - Default model
|
|
826
826
|
- `gemini-2.0-flash` - Gemini 2.0 Flash
|
|
827
827
|
- `gemini-2.0-flash-thinking` - Gemini 2.0 Flash Thinking Experimental
|
|
828
|
+
- `gemini-2.5-flash` - Gemini 2.5 Flash
|
|
828
829
|
- `gemini-2.5-pro` - Gemini 2.5 Pro (daily usage limit imposed)
|
|
829
830
|
|
|
830
831
|
Models pending update (may not work as expected):
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
gemini_webapi/__init__.py,sha256=28uNIywK4vCXxENaSagNWUzhqr1RyNtLzDF6WRRM4KQ,194
|
|
2
|
-
gemini_webapi/client.py,sha256=
|
|
3
|
-
gemini_webapi/constants.py,sha256=
|
|
4
|
-
gemini_webapi/exceptions.py,sha256=
|
|
2
|
+
gemini_webapi/client.py,sha256=waD8cnC8ol00T64F9NHihB43Wxzui9guYwrOpTvGw-8,24460
|
|
3
|
+
gemini_webapi/constants.py,sha256=xQloL6yHngniVEX5UnrsEKGTmMAieqxH7UUceefUVd8,2530
|
|
4
|
+
gemini_webapi/exceptions.py,sha256=7p6R5WZsAgwmggqoTM3No0i76PhYbPAFBdS7iqBExLE,922
|
|
5
5
|
gemini_webapi/types/__init__.py,sha256=d2kvXnE004s2E2KDmPPLi5N-BQ59FgDSlrGrO3Wphww,163
|
|
6
6
|
gemini_webapi/types/candidate.py,sha256=dMoGr53WR7FYDRrXpG9Yd_n9YTHGwGaFHZ8zPt8RMWw,1178
|
|
7
7
|
gemini_webapi/types/image.py,sha256=4BC8hxAWJrYFwzA60CivF1di4RZkzPKjcaSPPFKmRdY,5237
|
|
@@ -12,8 +12,8 @@ gemini_webapi/utils/load_browser_cookies.py,sha256=A5n_VsB7Rm8ck5lpy856UNJEhv30l
|
|
|
12
12
|
gemini_webapi/utils/logger.py,sha256=PF4ROQq7scRRrWzeYdeYiYs2S2Jqr0bgjyrPbXVOCqE,816
|
|
13
13
|
gemini_webapi/utils/rotate_1psidts.py,sha256=NyQ9OYPLBOcvpc8bodvEYDIVFrsYN0kdfc831lPEctM,1680
|
|
14
14
|
gemini_webapi/utils/upload_file.py,sha256=SJOMr6kryK_ClrKmqI96fqZBNFOMPsyAvFINAGAU3rk,1468
|
|
15
|
-
gemini_webapi-1.
|
|
16
|
-
gemini_webapi-1.
|
|
17
|
-
gemini_webapi-1.
|
|
18
|
-
gemini_webapi-1.
|
|
19
|
-
gemini_webapi-1.
|
|
15
|
+
gemini_webapi-1.11.1.dist-info/licenses/LICENSE,sha256=hIahDEOTzuHCU5J2nd07LWwkLW7Hko4UFO__ffsvB-8,34523
|
|
16
|
+
gemini_webapi-1.11.1.dist-info/METADATA,sha256=ClvGwberW9SgN8v81Zz0t0drx1ulluD6WQclybfzKnY,57167
|
|
17
|
+
gemini_webapi-1.11.1.dist-info/WHEEL,sha256=pxyMxgL8-pra_rKaQ4drOZAegBVuX-G_4nRHjjgWbmo,91
|
|
18
|
+
gemini_webapi-1.11.1.dist-info/top_level.txt,sha256=dtWtug_ZrmnUqCYuu8NmGzTgWglHeNzhHU_hXmqZGWE,14
|
|
19
|
+
gemini_webapi-1.11.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|