gemini-webapi 1.8.4__tar.gz → 1.9.0__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.
Files changed (36) hide show
  1. {gemini_webapi-1.8.4 → gemini_webapi-1.9.0}/PKG-INFO +53 -32
  2. {gemini_webapi-1.8.4 → gemini_webapi-1.9.0}/README.md +52 -31
  3. {gemini_webapi-1.8.4 → gemini_webapi-1.9.0}/src/gemini_webapi/client.py +10 -0
  4. {gemini_webapi-1.8.4 → gemini_webapi-1.9.0}/src/gemini_webapi/constants.py +25 -10
  5. {gemini_webapi-1.8.4 → gemini_webapi-1.9.0}/src/gemini_webapi/types/candidate.py +3 -0
  6. {gemini_webapi-1.8.4 → gemini_webapi-1.9.0}/src/gemini_webapi/types/modeloutput.py +4 -0
  7. {gemini_webapi-1.8.4 → gemini_webapi-1.9.0}/src/gemini_webapi.egg-info/PKG-INFO +53 -32
  8. {gemini_webapi-1.8.4 → gemini_webapi-1.9.0}/tests/test_client_features.py +21 -2
  9. {gemini_webapi-1.8.4 → gemini_webapi-1.9.0}/.github/dependabot.yml +0 -0
  10. {gemini_webapi-1.8.4 → gemini_webapi-1.9.0}/.github/workflows/github-release.yml +0 -0
  11. {gemini_webapi-1.8.4 → gemini_webapi-1.9.0}/.github/workflows/pypi-publish.yml +0 -0
  12. {gemini_webapi-1.8.4 → gemini_webapi-1.9.0}/.gitignore +0 -0
  13. {gemini_webapi-1.8.4 → gemini_webapi-1.9.0}/.vscode/launch.json +0 -0
  14. {gemini_webapi-1.8.4 → gemini_webapi-1.9.0}/.vscode/settings.json +0 -0
  15. {gemini_webapi-1.8.4 → gemini_webapi-1.9.0}/LICENSE +0 -0
  16. {gemini_webapi-1.8.4 → gemini_webapi-1.9.0}/assets/banner.png +0 -0
  17. {gemini_webapi-1.8.4 → gemini_webapi-1.9.0}/assets/favicon.png +0 -0
  18. {gemini_webapi-1.8.4 → gemini_webapi-1.9.0}/assets/logo.svg +0 -0
  19. {gemini_webapi-1.8.4 → gemini_webapi-1.9.0}/pyproject.toml +0 -0
  20. {gemini_webapi-1.8.4 → gemini_webapi-1.9.0}/setup.cfg +0 -0
  21. {gemini_webapi-1.8.4 → gemini_webapi-1.9.0}/src/gemini_webapi/__init__.py +0 -0
  22. {gemini_webapi-1.8.4 → gemini_webapi-1.9.0}/src/gemini_webapi/exceptions.py +0 -0
  23. {gemini_webapi-1.8.4 → gemini_webapi-1.9.0}/src/gemini_webapi/types/__init__.py +0 -0
  24. {gemini_webapi-1.8.4 → gemini_webapi-1.9.0}/src/gemini_webapi/types/image.py +0 -0
  25. {gemini_webapi-1.8.4 → gemini_webapi-1.9.0}/src/gemini_webapi/utils/__init__.py +0 -0
  26. {gemini_webapi-1.8.4 → gemini_webapi-1.9.0}/src/gemini_webapi/utils/get_access_token.py +0 -0
  27. {gemini_webapi-1.8.4 → gemini_webapi-1.9.0}/src/gemini_webapi/utils/load_browser_cookies.py +0 -0
  28. {gemini_webapi-1.8.4 → gemini_webapi-1.9.0}/src/gemini_webapi/utils/logger.py +0 -0
  29. {gemini_webapi-1.8.4 → gemini_webapi-1.9.0}/src/gemini_webapi/utils/rotate_1psidts.py +0 -0
  30. {gemini_webapi-1.8.4 → gemini_webapi-1.9.0}/src/gemini_webapi/utils/upload_file.py +0 -0
  31. {gemini_webapi-1.8.4 → gemini_webapi-1.9.0}/src/gemini_webapi.egg-info/SOURCES.txt +0 -0
  32. {gemini_webapi-1.8.4 → gemini_webapi-1.9.0}/src/gemini_webapi.egg-info/dependency_links.txt +0 -0
  33. {gemini_webapi-1.8.4 → gemini_webapi-1.9.0}/src/gemini_webapi.egg-info/requires.txt +0 -0
  34. {gemini_webapi-1.8.4 → gemini_webapi-1.9.0}/src/gemini_webapi.egg-info/top_level.txt +0 -0
  35. {gemini_webapi-1.8.4 → gemini_webapi-1.9.0}/tests/test_rotate_cookies.py +0 -0
  36. {gemini_webapi-1.8.4 → gemini_webapi-1.9.0}/tests/test_save_image.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: gemini-webapi
3
- Version: 1.8.4
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 Feb 1, 2025):
946
-
947
- - `unspecified` - Default model (Gemini 2.0 Flash if account does NOT have Gemini Advanced subscription)
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]
@@ -43,14 +43,15 @@ A reverse-engineered asynchronous python wrapper for [Google Gemini](https://gem
43
43
  - [Authentication](#authentication)
44
44
  - [Usage](#usage)
45
45
  - [Initialization](#initialization)
46
+ - [Select language model](#select-language-model)
46
47
  - [Generate contents from text](#generate-contents-from-text)
47
48
  - [Generate contents from image](#generate-contents-from-image)
48
49
  - [Conversations across multiple turns](#conversations-across-multiple-turns)
49
50
  - [Continue previous conversations](#continue-previous-conversations)
51
+ - [Retrieve model's thought process](#retrieve-models-thought-process)
50
52
  - [Retrieve images in response](#retrieve-images-in-response)
51
53
  - [Generate images with ImageFx](#generate-images-with-imagefx)
52
54
  - [Save images to local files](#save-images-to-local-files)
53
- - [Specify language model version](#specify-language-model-version)
54
55
  - [Generate contents with Gemini extensions](#generate-contents-with-gemini-extensions)
55
56
  - [Check and switch to other reply candidates](#check-and-switch-to-other-reply-candidates)
56
57
  - [Control log level](#control-log-level)
@@ -133,6 +134,41 @@ asyncio.run(main())
133
134
  >
134
135
  > `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.
135
136
 
137
+ ### Select language model
138
+
139
+ 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`.
140
+
141
+ Currently available models (as of Feb 5, 2025):
142
+
143
+ - `unspecified` - Default model (same as `gemini-2.0-flash` if account does NOT have Gemini Advanced subscription)
144
+ - `gemini-2.0-flash` - Gemini 2.0 Flash
145
+ - `gemini-2.0-flash-thinking` - Gemini 2.0 Flash Thinking Experimental
146
+ - `gemini-2.0-flash-thinking-with-apps` - Gemini 2.0 Flash Thinking Experimental with apps
147
+ - `gemini-1.5-flash` - Gemini 1.5 Flash
148
+
149
+ Models pending update (may not work as expected):
150
+
151
+ - `gemini-2.0-exp-advanced` - Gemini 2.0 Experimental Advanced **(requires Gemini Advanced account)**
152
+ - `gemini-1.5-pro` - Gemini 1.5 Pro **(requires Gemini Advanced account)**
153
+ - `gemini-1.5-pro-research` - Gemini 1.5 Pro with Deep Research **(requires Gemini Advanced account)**
154
+
155
+ ```python
156
+ from gemini_webapi.constants import Model
157
+
158
+ async def main():
159
+ response1 = await client.generate_content(
160
+ "What's you language model version? Reply version number only.",
161
+ model=Model.G_2_0_FLASH,
162
+ )
163
+ print(f"Model version ({Model.G_2_0_FLASH.model_name}): {response1.text}")
164
+
165
+ chat = client.start_chat(model="gemini-2.0-flash-thinking")
166
+ response2 = await chat.send_message("What's you language model version? Reply version number only.")
167
+ print(f"Model version (gemini-2.0-flash-thinking): {response2.text}")
168
+
169
+ asyncio.run(main())
170
+ ```
171
+
136
172
  ### Generate contents from text
137
173
 
138
174
  Ask a one-turn quick question by calling `GeminiClient.generate_content`.
@@ -203,6 +239,21 @@ async def main():
203
239
  asyncio.run(main())
204
240
  ```
205
241
 
242
+ ### Retrieve model's thought process
243
+
244
+ When using models with thinking capabilities, the model's thought process will be populated in `ModelOutput.thoughts`.
245
+
246
+ ```python
247
+ async def main():
248
+ response = await client.generate_content(
249
+ "What's 1+1?", model="gemini-2.0-flash-thinking"
250
+ )
251
+ print(response.thoughts)
252
+ print(response.text)
253
+
254
+ asyncio.run(main())
255
+ ```
256
+
206
257
  ### Retrieve images in response
207
258
 
208
259
  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.
@@ -256,36 +307,6 @@ async def main():
256
307
  asyncio.run(main())
257
308
  ```
258
309
 
259
- ### Specify language model version
260
-
261
- 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`.
262
-
263
- Currently available models (as of Feb 1, 2025):
264
-
265
- - `unspecified` - Default model (Gemini 2.0 Flash if account does NOT have Gemini Advanced subscription)
266
- - `gemini-1.5-flash` - Gemini 1.5 Flash
267
- - `gemini-1.5-pro` - Gemini 1.5 Pro **(requires Gemini Advanced account)**
268
- - `gemini-1.5-pro-research` - Gemini 1.5 Pro with Deep Research **(requires Gemini Advanced account)**
269
- - `gemini-2.0-flash-exp` - Gemini 2.0 Flash Experimental
270
- - `gemini-2.0-exp-advanced` - Gemini 2.0 Experimental Advanced **(requires Gemini Advanced account)**
271
-
272
- ```python
273
- from gemini_webapi.constants import Model
274
-
275
- async def main():
276
- response1 = await client.generate_content(
277
- "What's you language model version? Reply version number only.",
278
- model="gemini-1.5-flash",
279
- )
280
- print(f"Model version (gemini-1.5-flash): {response1.text}")
281
-
282
- chat = client.start_chat(model=Model.G_2_0_FLASH_EXP)
283
- response2 = await chat.send_message("What's you language model version? Reply version number only.")
284
- print(f"Model version ({Model.G_2_0_FLASH_EXP.model_name}): {response2.text}")
285
-
286
- asyncio.run(main())
287
- ```
288
-
289
310
  ### Generate contents with Gemini extensions
290
311
 
291
312
  > [!IMPORTANT]
@@ -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
  )
@@ -25,6 +25,31 @@ 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
55
  {"x-goog-ext-525001261-jspb": '[null,null,null,null,"418ab5ea040b5c43"]'},
@@ -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,"f299729663a2343f"]'},
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
@@ -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.8.4
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 Feb 1, 2025):
946
-
947
- - `unspecified` - Default model (Gemini 2.0 Flash if account does NOT have Gemini Advanced subscription)
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]
@@ -25,8 +25,27 @@ class TestGeminiClient(unittest.IsolatedAsyncioTestCase):
25
25
 
26
26
  @logger.catch(reraise=True)
27
27
  async def test_successful_request(self):
28
- response = await self.geminiclient.generate_content("Hello World!")
29
- self.assertTrue(response.text)
28
+ response = await self.geminiclient.generate_content(
29
+ "Hello World!", model=Model.G_2_0_FLASH
30
+ )
31
+ logger.debug(response.text)
32
+
33
+ @logger.catch(reraise=True)
34
+ async def test_thinking_model(self):
35
+ response = await self.geminiclient.generate_content(
36
+ "What's 1+1?", model=Model.G_2_0_FLASH_THINKING
37
+ )
38
+ logger.debug(response.thoughts)
39
+ logger.debug(response.text)
40
+
41
+ @logger.catch(reraise=True)
42
+ async def test_thinking_with_apps(self):
43
+ response = await self.geminiclient.generate_content(
44
+ "Tell me a fact about today in history and illustrate it with a youtube video",
45
+ model=Model.G_2_0_FLASH_THINKING_WITH_APPS,
46
+ )
47
+ logger.debug(response.thoughts)
48
+ logger.debug(response.text)
30
49
 
31
50
  @logger.catch(reraise=True)
32
51
  async def test_switch_model(self):
File without changes
File without changes
File without changes