gemini-webapi 1.17.0__tar.gz → 1.17.1__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.
- {gemini_webapi-1.17.0 → gemini_webapi-1.17.1}/.github/workflows/pypi-publish.yml +2 -2
- {gemini_webapi-1.17.0 → gemini_webapi-1.17.1}/PKG-INFO +23 -6
- {gemini_webapi-1.17.0 → gemini_webapi-1.17.1}/README.md +22 -5
- {gemini_webapi-1.17.0 → gemini_webapi-1.17.1}/src/gemini_webapi/client.py +26 -13
- {gemini_webapi-1.17.0 → gemini_webapi-1.17.1}/src/gemini_webapi/constants.py +31 -7
- {gemini_webapi-1.17.0 → gemini_webapi-1.17.1}/src/gemini_webapi.egg-info/PKG-INFO +23 -6
- {gemini_webapi-1.17.0 → gemini_webapi-1.17.1}/.github/dependabot.yml +0 -0
- {gemini_webapi-1.17.0 → gemini_webapi-1.17.1}/.github/workflows/github-release.yml +0 -0
- {gemini_webapi-1.17.0 → gemini_webapi-1.17.1}/.gitignore +0 -0
- {gemini_webapi-1.17.0 → gemini_webapi-1.17.1}/.vscode/launch.json +0 -0
- {gemini_webapi-1.17.0 → gemini_webapi-1.17.1}/.vscode/settings.json +0 -0
- {gemini_webapi-1.17.0 → gemini_webapi-1.17.1}/LICENSE +0 -0
- {gemini_webapi-1.17.0 → gemini_webapi-1.17.1}/assets/banner.png +0 -0
- {gemini_webapi-1.17.0 → gemini_webapi-1.17.1}/assets/favicon.png +0 -0
- {gemini_webapi-1.17.0 → gemini_webapi-1.17.1}/assets/logo.svg +0 -0
- {gemini_webapi-1.17.0 → gemini_webapi-1.17.1}/assets/sample.pdf +0 -0
- {gemini_webapi-1.17.0 → gemini_webapi-1.17.1}/pyproject.toml +0 -0
- {gemini_webapi-1.17.0 → gemini_webapi-1.17.1}/setup.cfg +0 -0
- {gemini_webapi-1.17.0 → gemini_webapi-1.17.1}/src/gemini_webapi/__init__.py +0 -0
- {gemini_webapi-1.17.0 → gemini_webapi-1.17.1}/src/gemini_webapi/components/__init__.py +0 -0
- {gemini_webapi-1.17.0 → gemini_webapi-1.17.1}/src/gemini_webapi/components/gem_mixin.py +0 -0
- {gemini_webapi-1.17.0 → gemini_webapi-1.17.1}/src/gemini_webapi/exceptions.py +0 -0
- {gemini_webapi-1.17.0 → gemini_webapi-1.17.1}/src/gemini_webapi/types/__init__.py +0 -0
- {gemini_webapi-1.17.0 → gemini_webapi-1.17.1}/src/gemini_webapi/types/candidate.py +0 -0
- {gemini_webapi-1.17.0 → gemini_webapi-1.17.1}/src/gemini_webapi/types/gem.py +0 -0
- {gemini_webapi-1.17.0 → gemini_webapi-1.17.1}/src/gemini_webapi/types/grpc.py +0 -0
- {gemini_webapi-1.17.0 → gemini_webapi-1.17.1}/src/gemini_webapi/types/image.py +0 -0
- {gemini_webapi-1.17.0 → gemini_webapi-1.17.1}/src/gemini_webapi/types/modeloutput.py +0 -0
- {gemini_webapi-1.17.0 → gemini_webapi-1.17.1}/src/gemini_webapi/utils/__init__.py +0 -0
- {gemini_webapi-1.17.0 → gemini_webapi-1.17.1}/src/gemini_webapi/utils/decorators.py +0 -0
- {gemini_webapi-1.17.0 → gemini_webapi-1.17.1}/src/gemini_webapi/utils/get_access_token.py +0 -0
- {gemini_webapi-1.17.0 → gemini_webapi-1.17.1}/src/gemini_webapi/utils/load_browser_cookies.py +0 -0
- {gemini_webapi-1.17.0 → gemini_webapi-1.17.1}/src/gemini_webapi/utils/logger.py +0 -0
- {gemini_webapi-1.17.0 → gemini_webapi-1.17.1}/src/gemini_webapi/utils/parsing.py +0 -0
- {gemini_webapi-1.17.0 → gemini_webapi-1.17.1}/src/gemini_webapi/utils/rotate_1psidts.py +0 -0
- {gemini_webapi-1.17.0 → gemini_webapi-1.17.1}/src/gemini_webapi/utils/upload_file.py +0 -0
- {gemini_webapi-1.17.0 → gemini_webapi-1.17.1}/src/gemini_webapi.egg-info/SOURCES.txt +0 -0
- {gemini_webapi-1.17.0 → gemini_webapi-1.17.1}/src/gemini_webapi.egg-info/dependency_links.txt +0 -0
- {gemini_webapi-1.17.0 → gemini_webapi-1.17.1}/src/gemini_webapi.egg-info/requires.txt +0 -0
- {gemini_webapi-1.17.0 → gemini_webapi-1.17.1}/src/gemini_webapi.egg-info/top_level.txt +0 -0
- {gemini_webapi-1.17.0 → gemini_webapi-1.17.1}/tests/test_client_features.py +0 -0
- {gemini_webapi-1.17.0 → gemini_webapi-1.17.1}/tests/test_gem_mixin.py +0 -0
- {gemini_webapi-1.17.0 → gemini_webapi-1.17.1}/tests/test_save_image.py +0 -0
|
@@ -36,7 +36,7 @@ jobs:
|
|
|
36
36
|
- name: Build package
|
|
37
37
|
run: python -m build
|
|
38
38
|
- name: Archive production artifacts
|
|
39
|
-
uses: actions/upload-artifact@
|
|
39
|
+
uses: actions/upload-artifact@v5.0.0
|
|
40
40
|
with:
|
|
41
41
|
name: dist
|
|
42
42
|
path: dist
|
|
@@ -52,7 +52,7 @@ jobs:
|
|
|
52
52
|
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
|
|
53
53
|
steps:
|
|
54
54
|
- name: Retrieve built artifacts
|
|
55
|
-
uses: actions/download-artifact@
|
|
55
|
+
uses: actions/download-artifact@v6.0.0
|
|
56
56
|
with:
|
|
57
57
|
name: dist
|
|
58
58
|
path: dist
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: gemini-webapi
|
|
3
|
-
Version: 1.17.
|
|
3
|
+
Version: 1.17.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
|
|
@@ -783,11 +783,11 @@ pip install -U browser-cookie3
|
|
|
783
783
|
|
|
784
784
|
```yaml
|
|
785
785
|
services:
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
786
|
+
main:
|
|
787
|
+
environment:
|
|
788
|
+
GEMINI_COOKIE_PATH: /tmp/gemini_webapi
|
|
789
|
+
volumes:
|
|
790
|
+
- ./gemini_cookies:/tmp/gemini_webapi
|
|
791
791
|
```
|
|
792
792
|
|
|
793
793
|
> [!NOTE]
|
|
@@ -929,6 +929,23 @@ async def main():
|
|
|
929
929
|
asyncio.run(main())
|
|
930
930
|
```
|
|
931
931
|
|
|
932
|
+
You can also pass custom model header strings directly to access models which are not listed above.
|
|
933
|
+
|
|
934
|
+
```python
|
|
935
|
+
# "model_name" and "model_header" keys must be present
|
|
936
|
+
custom_model = {
|
|
937
|
+
"model_name": "xxx",
|
|
938
|
+
"model_header": {
|
|
939
|
+
"x-goog-ext-525001261-jspb": "[1,null,null,null,'e6fa609c3fa255c0',null,null,null,[4]]"
|
|
940
|
+
},
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
response = await client.generate_content(
|
|
944
|
+
"What's your model version?",
|
|
945
|
+
model=custom_model
|
|
946
|
+
)
|
|
947
|
+
```
|
|
948
|
+
|
|
932
949
|
### Apply system prompt with Gemini Gems
|
|
933
950
|
|
|
934
951
|
System prompt can be applied to conversations via [Gemini Gems](https://gemini.google.com/gems/view). To use a gem, you can pass `gem` argument to `GeminiClient.generate_content` or `GeminiClient.start_chat`. `gem` can be either a string of gem id or a `gemini_webapi.Gem` object. Only one gem can be applied to a single conversation.
|
|
@@ -99,11 +99,11 @@ pip install -U browser-cookie3
|
|
|
99
99
|
|
|
100
100
|
```yaml
|
|
101
101
|
services:
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
102
|
+
main:
|
|
103
|
+
environment:
|
|
104
|
+
GEMINI_COOKIE_PATH: /tmp/gemini_webapi
|
|
105
|
+
volumes:
|
|
106
|
+
- ./gemini_cookies:/tmp/gemini_webapi
|
|
107
107
|
```
|
|
108
108
|
|
|
109
109
|
> [!NOTE]
|
|
@@ -245,6 +245,23 @@ async def main():
|
|
|
245
245
|
asyncio.run(main())
|
|
246
246
|
```
|
|
247
247
|
|
|
248
|
+
You can also pass custom model header strings directly to access models which are not listed above.
|
|
249
|
+
|
|
250
|
+
```python
|
|
251
|
+
# "model_name" and "model_header" keys must be present
|
|
252
|
+
custom_model = {
|
|
253
|
+
"model_name": "xxx",
|
|
254
|
+
"model_header": {
|
|
255
|
+
"x-goog-ext-525001261-jspb": "[1,null,null,null,'e6fa609c3fa255c0',null,null,null,[4]]"
|
|
256
|
+
},
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
response = await client.generate_content(
|
|
260
|
+
"What's your model version?",
|
|
261
|
+
model=custom_model
|
|
262
|
+
)
|
|
263
|
+
```
|
|
264
|
+
|
|
248
265
|
### Apply system prompt with Gemini Gems
|
|
249
266
|
|
|
250
267
|
System prompt can be applied to conversations via [Gemini Gems](https://gemini.google.com/gems/view). To use a gem, you can pass `gem` argument to `GeminiClient.generate_content` or `GeminiClient.start_chat`. `gem` can be either a string of gem id or a `gemini_webapi.Gem` object. Only one gem can be applied to a single conversation.
|
|
@@ -240,7 +240,7 @@ class GeminiClient(GemMixin):
|
|
|
240
240
|
self,
|
|
241
241
|
prompt: str,
|
|
242
242
|
files: list[str | Path] | None = None,
|
|
243
|
-
model: Model | str = Model.UNSPECIFIED,
|
|
243
|
+
model: Model | str | dict = Model.UNSPECIFIED,
|
|
244
244
|
gem: Gem | str | None = None,
|
|
245
245
|
chat: Optional["ChatSession"] = None,
|
|
246
246
|
**kwargs,
|
|
@@ -254,9 +254,10 @@ class GeminiClient(GemMixin):
|
|
|
254
254
|
Prompt provided by user.
|
|
255
255
|
files: `list[str | Path]`, optional
|
|
256
256
|
List of file paths to be attached.
|
|
257
|
-
model: `Model
|
|
257
|
+
model: `Model | str | dict`, optional
|
|
258
258
|
Specify the model to use for generation.
|
|
259
|
-
Pass either a `gemini_webapi.constants.Model` enum or a model name string.
|
|
259
|
+
Pass either a `gemini_webapi.constants.Model` enum or a model name string to use predefined models.
|
|
260
|
+
Pass a dictionary to use custom model header strings ("model_name" and "model_header" keys must be provided).
|
|
260
261
|
gem: `Gem | str`, optional
|
|
261
262
|
Specify a gem to use as system prompt for the chat session.
|
|
262
263
|
Pass either a `gemini_webapi.types.Gem` object or a gem id string.
|
|
@@ -287,8 +288,15 @@ class GeminiClient(GemMixin):
|
|
|
287
288
|
|
|
288
289
|
assert prompt, "Prompt cannot be empty."
|
|
289
290
|
|
|
290
|
-
if
|
|
291
|
+
if isinstance(model, str):
|
|
291
292
|
model = Model.from_name(model)
|
|
293
|
+
elif isinstance(model, dict):
|
|
294
|
+
model = Model.from_dict(model)
|
|
295
|
+
elif not isinstance(model, Model):
|
|
296
|
+
raise TypeError(
|
|
297
|
+
f"'model' must be a `gemini_webapi.constants.Model` instance, "
|
|
298
|
+
f"string, or dictionary; got `{type(model).__name__}`"
|
|
299
|
+
)
|
|
292
300
|
|
|
293
301
|
if isinstance(gem, Gem):
|
|
294
302
|
gem_id = gem.id
|
|
@@ -362,7 +370,7 @@ class GeminiClient(GemMixin):
|
|
|
362
370
|
if get_nested_value(part_json, [4]):
|
|
363
371
|
body_index, body = part_index, part_json
|
|
364
372
|
break
|
|
365
|
-
except
|
|
373
|
+
except json.JSONDecodeError:
|
|
366
374
|
continue
|
|
367
375
|
|
|
368
376
|
if not body:
|
|
@@ -443,13 +451,17 @@ class GeminiClient(GemMixin):
|
|
|
443
451
|
if img_part_index < body_index:
|
|
444
452
|
continue
|
|
445
453
|
try:
|
|
446
|
-
|
|
454
|
+
img_part_body = get_nested_value(part, [2])
|
|
455
|
+
if not img_part_body:
|
|
456
|
+
continue
|
|
457
|
+
|
|
458
|
+
img_part_json = json.loads(img_part_body)
|
|
447
459
|
if get_nested_value(
|
|
448
|
-
|
|
460
|
+
img_part_json, [4, candidate_index, 12, 7, 0]
|
|
449
461
|
):
|
|
450
|
-
img_body =
|
|
462
|
+
img_body = img_part_json
|
|
451
463
|
break
|
|
452
|
-
except
|
|
464
|
+
except json.JSONDecodeError:
|
|
453
465
|
continue
|
|
454
466
|
|
|
455
467
|
if not img_body:
|
|
@@ -614,9 +626,10 @@ class ChatSession:
|
|
|
614
626
|
Reply id, if provided together with metadata, will override the second value in it.
|
|
615
627
|
rcid: `str`, optional
|
|
616
628
|
Reply candidate id, if provided together with metadata, will override the third value in it.
|
|
617
|
-
model: `Model
|
|
629
|
+
model: `Model | str | dict`, optional
|
|
618
630
|
Specify the model to use for generation.
|
|
619
|
-
Pass either a `gemini_webapi.constants.Model` enum or a model name string.
|
|
631
|
+
Pass either a `gemini_webapi.constants.Model` enum or a model name string to use predefined models.
|
|
632
|
+
Pass a dictionary to use custom model header strings ("model_name" and "model_header" keys must be provided).
|
|
620
633
|
gem: `Gem | str`, optional
|
|
621
634
|
Specify a gem to use as system prompt for the chat session.
|
|
622
635
|
Pass either a `gemini_webapi.types.Gem` object or a gem id string.
|
|
@@ -637,13 +650,13 @@ class ChatSession:
|
|
|
637
650
|
cid: str | None = None, # chat id
|
|
638
651
|
rid: str | None = None, # reply id
|
|
639
652
|
rcid: str | None = None, # reply candidate id
|
|
640
|
-
model: Model | str = Model.UNSPECIFIED,
|
|
653
|
+
model: Model | str | dict = Model.UNSPECIFIED,
|
|
641
654
|
gem: Gem | str | None = None,
|
|
642
655
|
):
|
|
643
656
|
self.__metadata: list[str | None] = [None, None, None]
|
|
644
657
|
self.geminiclient: GeminiClient = geminiclient
|
|
645
658
|
self.last_output: ModelOutput | None = None
|
|
646
|
-
self.model: Model | str = model
|
|
659
|
+
self.model: Model | str | dict = model
|
|
647
660
|
self.gem: Gem | str | None = gem
|
|
648
661
|
|
|
649
662
|
if metadata:
|
|
@@ -45,17 +45,23 @@ class Model(Enum):
|
|
|
45
45
|
UNSPECIFIED = ("unspecified", {}, False)
|
|
46
46
|
G_3_0_PRO = (
|
|
47
47
|
"gemini-3.0-pro",
|
|
48
|
-
{
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
G_2_5_FLASH = (
|
|
52
|
-
"gemini-2.5-flash",
|
|
53
|
-
{"x-goog-ext-525001261-jspb": '[1,null,null,null,"9ec249fc9ad08861",null,null,0,[4]]'},
|
|
48
|
+
{
|
|
49
|
+
"x-goog-ext-525001261-jspb": '[1,null,null,null,"9d8ca3786ebdfbea",null,null,0,[4]]'
|
|
50
|
+
},
|
|
54
51
|
False,
|
|
55
52
|
)
|
|
56
53
|
G_2_5_PRO = (
|
|
57
54
|
"gemini-2.5-pro",
|
|
58
|
-
{
|
|
55
|
+
{
|
|
56
|
+
"x-goog-ext-525001261-jspb": '[1,null,null,null,"4af6c7f5da75d65d",null,null,0,[4]]'
|
|
57
|
+
},
|
|
58
|
+
False,
|
|
59
|
+
)
|
|
60
|
+
G_2_5_FLASH = (
|
|
61
|
+
"gemini-2.5-flash",
|
|
62
|
+
{
|
|
63
|
+
"x-goog-ext-525001261-jspb": '[1,null,null,null,"9ec249fc9ad08861",null,null,0,[4]]'
|
|
64
|
+
},
|
|
59
65
|
False,
|
|
60
66
|
)
|
|
61
67
|
|
|
@@ -69,10 +75,28 @@ class Model(Enum):
|
|
|
69
75
|
for model in cls:
|
|
70
76
|
if model.model_name == name:
|
|
71
77
|
return model
|
|
78
|
+
|
|
72
79
|
raise ValueError(
|
|
73
80
|
f"Unknown model name: {name}. Available models: {', '.join([model.model_name for model in cls])}"
|
|
74
81
|
)
|
|
75
82
|
|
|
83
|
+
@classmethod
|
|
84
|
+
def from_dict(cls, model_dict: dict):
|
|
85
|
+
if "model_name" not in model_dict or "model_header" not in model_dict:
|
|
86
|
+
raise ValueError(
|
|
87
|
+
"When passing a custom model as a dictionary, 'model_name' and 'model_header' keys must be provided."
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
if not isinstance(model_dict["model_header"], dict):
|
|
91
|
+
raise ValueError(
|
|
92
|
+
"When passing a custom model as a dictionary, 'model_header' must be a dictionary containing valid header strings."
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
custom_model = cls.UNSPECIFIED
|
|
96
|
+
custom_model.model_name = model_dict["model_name"]
|
|
97
|
+
custom_model.model_header = model_dict["model_header"]
|
|
98
|
+
return custom_model
|
|
99
|
+
|
|
76
100
|
|
|
77
101
|
class ErrorCode(IntEnum):
|
|
78
102
|
"""
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: gemini-webapi
|
|
3
|
-
Version: 1.17.
|
|
3
|
+
Version: 1.17.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
|
|
@@ -783,11 +783,11 @@ pip install -U browser-cookie3
|
|
|
783
783
|
|
|
784
784
|
```yaml
|
|
785
785
|
services:
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
786
|
+
main:
|
|
787
|
+
environment:
|
|
788
|
+
GEMINI_COOKIE_PATH: /tmp/gemini_webapi
|
|
789
|
+
volumes:
|
|
790
|
+
- ./gemini_cookies:/tmp/gemini_webapi
|
|
791
791
|
```
|
|
792
792
|
|
|
793
793
|
> [!NOTE]
|
|
@@ -929,6 +929,23 @@ async def main():
|
|
|
929
929
|
asyncio.run(main())
|
|
930
930
|
```
|
|
931
931
|
|
|
932
|
+
You can also pass custom model header strings directly to access models which are not listed above.
|
|
933
|
+
|
|
934
|
+
```python
|
|
935
|
+
# "model_name" and "model_header" keys must be present
|
|
936
|
+
custom_model = {
|
|
937
|
+
"model_name": "xxx",
|
|
938
|
+
"model_header": {
|
|
939
|
+
"x-goog-ext-525001261-jspb": "[1,null,null,null,'e6fa609c3fa255c0',null,null,null,[4]]"
|
|
940
|
+
},
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
response = await client.generate_content(
|
|
944
|
+
"What's your model version?",
|
|
945
|
+
model=custom_model
|
|
946
|
+
)
|
|
947
|
+
```
|
|
948
|
+
|
|
932
949
|
### Apply system prompt with Gemini Gems
|
|
933
950
|
|
|
934
951
|
System prompt can be applied to conversations via [Gemini Gems](https://gemini.google.com/gems/view). To use a gem, you can pass `gem` argument to `GeminiClient.generate_content` or `GeminiClient.start_chat`. `gem` can be either a string of gem id or a `gemini_webapi.Gem` object. Only one gem can be applied to a single conversation.
|
|
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
|
{gemini_webapi-1.17.0 → gemini_webapi-1.17.1}/src/gemini_webapi/utils/load_browser_cookies.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{gemini_webapi-1.17.0 → gemini_webapi-1.17.1}/src/gemini_webapi.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|