gemini-webapi 1.8.3__py3-none-any.whl → 1.9.0__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 +10 -0
- gemini_webapi/constants.py +26 -11
- gemini_webapi/types/candidate.py +3 -0
- gemini_webapi/types/modeloutput.py +4 -0
- {gemini_webapi-1.8.3.dist-info → gemini_webapi-1.9.0.dist-info}/METADATA +53 -32
- {gemini_webapi-1.8.3.dist-info → gemini_webapi-1.9.0.dist-info}/RECORD +9 -9
- {gemini_webapi-1.8.3.dist-info → gemini_webapi-1.9.0.dist-info}/LICENSE +0 -0
- {gemini_webapi-1.8.3.dist-info → gemini_webapi-1.9.0.dist-info}/WHEEL +0 -0
- {gemini_webapi-1.8.3.dist-info → gemini_webapi-1.9.0.dist-info}/top_level.txt +0 -0
gemini_webapi/client.py
CHANGED
|
@@ -364,6 +364,10 @@ class GeminiClient:
|
|
|
364
364
|
# Plain request
|
|
365
365
|
body = json.loads(response_json[0][2])
|
|
366
366
|
|
|
367
|
+
if not body[4]:
|
|
368
|
+
# Request with thinking models
|
|
369
|
+
body = json.loads(response_json[1][2])
|
|
370
|
+
|
|
367
371
|
if not body[4]:
|
|
368
372
|
# Request with Gemini extensions enabled
|
|
369
373
|
body = json.loads(response_json[4][2])
|
|
@@ -386,6 +390,11 @@ class GeminiClient:
|
|
|
386
390
|
):
|
|
387
391
|
text = candidate[22] and candidate[22][0] or text
|
|
388
392
|
|
|
393
|
+
try:
|
|
394
|
+
thoughts = candidate[37][0][0]
|
|
395
|
+
except (TypeError, IndexError):
|
|
396
|
+
thoughts = None
|
|
397
|
+
|
|
389
398
|
web_images = (
|
|
390
399
|
candidate[12]
|
|
391
400
|
and candidate[12][1]
|
|
@@ -435,6 +444,7 @@ class GeminiClient:
|
|
|
435
444
|
Candidate(
|
|
436
445
|
rcid=candidate[0],
|
|
437
446
|
text=text,
|
|
447
|
+
thoughts=thoughts,
|
|
438
448
|
web_images=web_images,
|
|
439
449
|
generated_images=generated_images,
|
|
440
450
|
)
|
gemini_webapi/constants.py
CHANGED
|
@@ -25,9 +25,34 @@ class Headers(Enum):
|
|
|
25
25
|
|
|
26
26
|
class Model(Enum):
|
|
27
27
|
UNSPECIFIED = ("unspecified", {}, False)
|
|
28
|
+
G_2_0_FLASH = (
|
|
29
|
+
"gemini-2.0-flash",
|
|
30
|
+
{"x-goog-ext-525001261-jspb": '[null,null,null,null,"f299729663a2343f"]'},
|
|
31
|
+
False,
|
|
32
|
+
)
|
|
33
|
+
G_2_0_FLASH_EXP = (
|
|
34
|
+
"gemini-2.0-flash-exp",
|
|
35
|
+
{"x-goog-ext-525001261-jspb": '[null,null,null,null,"f299729663a2343f"]'},
|
|
36
|
+
False,
|
|
37
|
+
) # Deprecated, should be removed in the future
|
|
38
|
+
G_2_0_FLASH_THINKING = (
|
|
39
|
+
"gemini-2.0-flash-thinking",
|
|
40
|
+
{"x-goog-ext-525001261-jspb": '[null,null,null,null,"9c17b1863f581b8a"]'},
|
|
41
|
+
False,
|
|
42
|
+
)
|
|
43
|
+
G_2_0_FLASH_THINKING_WITH_APPS = (
|
|
44
|
+
"gemini-2.0-flash-thinking-with-apps",
|
|
45
|
+
{"x-goog-ext-525001261-jspb": '[null,null,null,null,"f8f8f5ea629f5d37"]'},
|
|
46
|
+
False,
|
|
47
|
+
)
|
|
48
|
+
G_2_0_EXP_ADVANCED = (
|
|
49
|
+
"gemini-2.0-exp-advanced",
|
|
50
|
+
{"x-goog-ext-525001261-jspb": '[null,null,null,null,"b1e46a6037e6aa9f"]'},
|
|
51
|
+
True,
|
|
52
|
+
)
|
|
28
53
|
G_1_5_FLASH = (
|
|
29
54
|
"gemini-1.5-flash",
|
|
30
|
-
{"x-goog-ext-525001261-jspb": '[null,null,null,null,"
|
|
55
|
+
{"x-goog-ext-525001261-jspb": '[null,null,null,null,"418ab5ea040b5c43"]'},
|
|
31
56
|
False,
|
|
32
57
|
)
|
|
33
58
|
G_1_5_PRO = (
|
|
@@ -40,16 +65,6 @@ class Model(Enum):
|
|
|
40
65
|
{"x-goog-ext-525001261-jspb": '[null,null,null,null,"e5a44cb1dae2b489"]'},
|
|
41
66
|
True,
|
|
42
67
|
)
|
|
43
|
-
G_2_0_FLASH_EXP = (
|
|
44
|
-
"gemini-2.0-flash-exp",
|
|
45
|
-
{"x-goog-ext-525001261-jspb": '[null,null,null,null,"948b866104ccf484"]'},
|
|
46
|
-
False,
|
|
47
|
-
)
|
|
48
|
-
G_2_0_EXP_ADVANCED = (
|
|
49
|
-
"gemini-2.0-exp-advanced",
|
|
50
|
-
{"x-goog-ext-525001261-jspb": '[null,null,null,null,"b1e46a6037e6aa9f"]'},
|
|
51
|
-
True,
|
|
52
|
-
)
|
|
53
68
|
|
|
54
69
|
def __init__(self, name, header, advanced_only):
|
|
55
70
|
self.model_name = name
|
gemini_webapi/types/candidate.py
CHANGED
|
@@ -13,6 +13,8 @@ class Candidate(BaseModel):
|
|
|
13
13
|
Reply candidate ID to build the metadata
|
|
14
14
|
text: `str`
|
|
15
15
|
Text output
|
|
16
|
+
thoughts: `str`, optional
|
|
17
|
+
Model's thought process, can be empty. Only populated with `-thinking` models
|
|
16
18
|
web_images: `list[WebImage]`, optional
|
|
17
19
|
List of web images in reply, can be empty.
|
|
18
20
|
generated_images: `list[GeneratedImage]`, optional
|
|
@@ -21,6 +23,7 @@ class Candidate(BaseModel):
|
|
|
21
23
|
|
|
22
24
|
rcid: str
|
|
23
25
|
text: str
|
|
26
|
+
thoughts: str | None = None
|
|
24
27
|
web_images: list[WebImage] = []
|
|
25
28
|
generated_images: list[GeneratedImage] = []
|
|
26
29
|
|
|
@@ -32,6 +32,10 @@ class ModelOutput(BaseModel):
|
|
|
32
32
|
def text(self) -> str:
|
|
33
33
|
return self.candidates[self.chosen].text
|
|
34
34
|
|
|
35
|
+
@property
|
|
36
|
+
def thoughts(self) -> str | None:
|
|
37
|
+
return self.candidates[self.chosen].thoughts
|
|
38
|
+
|
|
35
39
|
@property
|
|
36
40
|
def images(self) -> list[Image]:
|
|
37
41
|
return self.candidates[self.chosen].images
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.2
|
|
2
2
|
Name: gemini-webapi
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.9.0
|
|
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
|
|
@@ -725,14 +725,15 @@ A reverse-engineered asynchronous python wrapper for [Google Gemini](https://gem
|
|
|
725
725
|
- [Authentication](#authentication)
|
|
726
726
|
- [Usage](#usage)
|
|
727
727
|
- [Initialization](#initialization)
|
|
728
|
+
- [Select language model](#select-language-model)
|
|
728
729
|
- [Generate contents from text](#generate-contents-from-text)
|
|
729
730
|
- [Generate contents from image](#generate-contents-from-image)
|
|
730
731
|
- [Conversations across multiple turns](#conversations-across-multiple-turns)
|
|
731
732
|
- [Continue previous conversations](#continue-previous-conversations)
|
|
733
|
+
- [Retrieve model's thought process](#retrieve-models-thought-process)
|
|
732
734
|
- [Retrieve images in response](#retrieve-images-in-response)
|
|
733
735
|
- [Generate images with ImageFx](#generate-images-with-imagefx)
|
|
734
736
|
- [Save images to local files](#save-images-to-local-files)
|
|
735
|
-
- [Specify language model version](#specify-language-model-version)
|
|
736
737
|
- [Generate contents with Gemini extensions](#generate-contents-with-gemini-extensions)
|
|
737
738
|
- [Check and switch to other reply candidates](#check-and-switch-to-other-reply-candidates)
|
|
738
739
|
- [Control log level](#control-log-level)
|
|
@@ -815,6 +816,41 @@ asyncio.run(main())
|
|
|
815
816
|
>
|
|
816
817
|
> `auto_close` and `close_delay` are optional arguments for automatically closing the client after a certain period of inactivity. This feature is disabled by default. In an always-on service like chatbot, it's recommended to set `auto_close` to `True` combined with reasonable seconds of `close_delay` for better resource management.
|
|
817
818
|
|
|
819
|
+
### Select language model
|
|
820
|
+
|
|
821
|
+
You can specify which language model to use by passing `model` argument to `GeminiClient.generate_content` or `GeminiClient.start_chat`. The default value is `unspecified`.
|
|
822
|
+
|
|
823
|
+
Currently available models (as of Feb 5, 2025):
|
|
824
|
+
|
|
825
|
+
- `unspecified` - Default model (same as `gemini-2.0-flash` if account does NOT have Gemini Advanced subscription)
|
|
826
|
+
- `gemini-2.0-flash` - Gemini 2.0 Flash
|
|
827
|
+
- `gemini-2.0-flash-thinking` - Gemini 2.0 Flash Thinking Experimental
|
|
828
|
+
- `gemini-2.0-flash-thinking-with-apps` - Gemini 2.0 Flash Thinking Experimental with apps
|
|
829
|
+
- `gemini-1.5-flash` - Gemini 1.5 Flash
|
|
830
|
+
|
|
831
|
+
Models pending update (may not work as expected):
|
|
832
|
+
|
|
833
|
+
- `gemini-2.0-exp-advanced` - Gemini 2.0 Experimental Advanced **(requires Gemini Advanced account)**
|
|
834
|
+
- `gemini-1.5-pro` - Gemini 1.5 Pro **(requires Gemini Advanced account)**
|
|
835
|
+
- `gemini-1.5-pro-research` - Gemini 1.5 Pro with Deep Research **(requires Gemini Advanced account)**
|
|
836
|
+
|
|
837
|
+
```python
|
|
838
|
+
from gemini_webapi.constants import Model
|
|
839
|
+
|
|
840
|
+
async def main():
|
|
841
|
+
response1 = await client.generate_content(
|
|
842
|
+
"What's you language model version? Reply version number only.",
|
|
843
|
+
model=Model.G_2_0_FLASH,
|
|
844
|
+
)
|
|
845
|
+
print(f"Model version ({Model.G_2_0_FLASH.model_name}): {response1.text}")
|
|
846
|
+
|
|
847
|
+
chat = client.start_chat(model="gemini-2.0-flash-thinking")
|
|
848
|
+
response2 = await chat.send_message("What's you language model version? Reply version number only.")
|
|
849
|
+
print(f"Model version (gemini-2.0-flash-thinking): {response2.text}")
|
|
850
|
+
|
|
851
|
+
asyncio.run(main())
|
|
852
|
+
```
|
|
853
|
+
|
|
818
854
|
### Generate contents from text
|
|
819
855
|
|
|
820
856
|
Ask a one-turn quick question by calling `GeminiClient.generate_content`.
|
|
@@ -885,6 +921,21 @@ async def main():
|
|
|
885
921
|
asyncio.run(main())
|
|
886
922
|
```
|
|
887
923
|
|
|
924
|
+
### Retrieve model's thought process
|
|
925
|
+
|
|
926
|
+
When using models with thinking capabilities, the model's thought process will be populated in `ModelOutput.thoughts`.
|
|
927
|
+
|
|
928
|
+
```python
|
|
929
|
+
async def main():
|
|
930
|
+
response = await client.generate_content(
|
|
931
|
+
"What's 1+1?", model="gemini-2.0-flash-thinking"
|
|
932
|
+
)
|
|
933
|
+
print(response.thoughts)
|
|
934
|
+
print(response.text)
|
|
935
|
+
|
|
936
|
+
asyncio.run(main())
|
|
937
|
+
```
|
|
938
|
+
|
|
888
939
|
### Retrieve images in response
|
|
889
940
|
|
|
890
941
|
Images in the API's output are stored as a list of `Image` objects. You can access the image title, URL, and description by calling `image.title`, `image.url` and `image.alt` respectively.
|
|
@@ -938,36 +989,6 @@ async def main():
|
|
|
938
989
|
asyncio.run(main())
|
|
939
990
|
```
|
|
940
991
|
|
|
941
|
-
### Specify language model version
|
|
942
|
-
|
|
943
|
-
You can choose a specified language model version by passing `model` argument to `GeminiClient.generate_content` or `GeminiClient.start_chat`. The default value is `unspecified`.
|
|
944
|
-
|
|
945
|
-
Currently available models (as of Dec 21, 2024):
|
|
946
|
-
|
|
947
|
-
- `unspecified` - Default model (Gemini 1.5 Pro if account has Gemini Advanced subscription, otherwise Gemini 1.5 Flash)
|
|
948
|
-
- `gemini-1.5-flash` - Gemini 1.5 Flash
|
|
949
|
-
- `gemini-1.5-pro` - Gemini 1.5 Pro **(requires Gemini Advanced account)**
|
|
950
|
-
- `gemini-1.5-pro-research` - Gemini 1.5 Pro with Deep Research **(requires Gemini Advanced account)**
|
|
951
|
-
- `gemini-2.0-flash-exp` - Gemini 2.0 Flash Experimental
|
|
952
|
-
- `gemini-2.0-exp-advanced` - Gemini 2.0 Experimental Advanced **(requires Gemini Advanced account)**
|
|
953
|
-
|
|
954
|
-
```python
|
|
955
|
-
from gemini_webapi.constants import Model
|
|
956
|
-
|
|
957
|
-
async def main():
|
|
958
|
-
response1 = await client.generate_content(
|
|
959
|
-
"What's you language model version? Reply version number only.",
|
|
960
|
-
model="gemini-1.5-flash",
|
|
961
|
-
)
|
|
962
|
-
print(f"Model version (gemini-1.5-flash): {response1.text}")
|
|
963
|
-
|
|
964
|
-
chat = client.start_chat(model=Model.G_2_0_FLASH_EXP)
|
|
965
|
-
response2 = await chat.send_message("What's you language model version? Reply version number only.")
|
|
966
|
-
print(f"Model version ({Model.G_2_0_FLASH_EXP.model_name}): {response2.text}")
|
|
967
|
-
|
|
968
|
-
asyncio.run(main())
|
|
969
|
-
```
|
|
970
|
-
|
|
971
992
|
### Generate contents with Gemini extensions
|
|
972
993
|
|
|
973
994
|
> [!IMPORTANT]
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
gemini_webapi/__init__.py,sha256=28uNIywK4vCXxENaSagNWUzhqr1RyNtLzDF6WRRM4KQ,194
|
|
2
|
-
gemini_webapi/client.py,sha256=
|
|
3
|
-
gemini_webapi/constants.py,sha256=
|
|
2
|
+
gemini_webapi/client.py,sha256=vb39HrpExZ69rDzZpAtapZSohccyGiC5oXQ9-TEbE3M,23122
|
|
3
|
+
gemini_webapi/constants.py,sha256=_8TdJH3dvzSDo0qfhKCAerWXBbH71u0B0mSGOkkJQ5w,2737
|
|
4
4
|
gemini_webapi/exceptions.py,sha256=6e-EXHGApi4iC0GDw7RKc3YqVK8UvEkHYaJyGQbReLw,548
|
|
5
5
|
gemini_webapi/types/__init__.py,sha256=d2kvXnE004s2E2KDmPPLi5N-BQ59FgDSlrGrO3Wphww,163
|
|
6
|
-
gemini_webapi/types/candidate.py,sha256=
|
|
6
|
+
gemini_webapi/types/candidate.py,sha256=dMoGr53WR7FYDRrXpG9Yd_n9YTHGwGaFHZ8zPt8RMWw,1178
|
|
7
7
|
gemini_webapi/types/image.py,sha256=4BC8hxAWJrYFwzA60CivF1di4RZkzPKjcaSPPFKmRdY,5237
|
|
8
|
-
gemini_webapi/types/modeloutput.py,sha256=
|
|
8
|
+
gemini_webapi/types/modeloutput.py,sha256=h07kQOkL5r-oPLvZ59uVtO1eP4FGy5ZpzuYQzAeQdr8,1196
|
|
9
9
|
gemini_webapi/utils/__init__.py,sha256=mcm1kgQ5HHKyZrhHS-rd_GXbKMpIDUsq02XtmlQNN_I,357
|
|
10
10
|
gemini_webapi/utils/get_access_token.py,sha256=uyb6tuzPr3mHttCjiM86M29ykrnHqsUClYdf5sVkyEQ,5465
|
|
11
11
|
gemini_webapi/utils/load_browser_cookies.py,sha256=A5n_VsB7Rm8ck5lpy856UNJEhv30l3dvQ3j0g3ln1fE,1535
|
|
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=A-ZQ54gy2wOVA_giEEVLQQK5zTJfrgq99Z5YYYOAFYc,1163
|
|
15
|
-
gemini_webapi-1.
|
|
16
|
-
gemini_webapi-1.
|
|
17
|
-
gemini_webapi-1.
|
|
18
|
-
gemini_webapi-1.
|
|
19
|
-
gemini_webapi-1.
|
|
15
|
+
gemini_webapi-1.9.0.dist-info/LICENSE,sha256=hIahDEOTzuHCU5J2nd07LWwkLW7Hko4UFO__ffsvB-8,34523
|
|
16
|
+
gemini_webapi-1.9.0.dist-info/METADATA,sha256=5PMao_8uRFquzfpa4oQcu8Jr5twEsH7zt-EXeDMrzmg,57775
|
|
17
|
+
gemini_webapi-1.9.0.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
|
18
|
+
gemini_webapi-1.9.0.dist-info/top_level.txt,sha256=dtWtug_ZrmnUqCYuu8NmGzTgWglHeNzhHU_hXmqZGWE,14
|
|
19
|
+
gemini_webapi-1.9.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|