@@ -108,13 +108,14 @@ pip install -q -U python-gemini-api
108
108
With browser open, try auto-collecting cookies first.
109
109
``` python
110
110
from gemini import Gemini
111
- GeminiClient = Gemini(auto_cookies = True )
111
+
112
+ client = Gemini(auto_cookies = True )
112
113
113
114
# Testing needed as cookies vary by region.
114
- # GeminiClient = Gemini(auto_cookies=True, target_cookies=["__Secure-1PSID", "__Secure-1PSIDTS"])
115
- # GeminiClient = Gemini(auto_cookies=True, target_cookies="all") # You can pass whole cookies
115
+ # client = Gemini(auto_cookies=True, target_cookies=["__Secure-1PSID", "__Secure-1PSIDTS"])
116
+ # client = Gemini(auto_cookies=True, target_cookies="all") # You can pass whole cookies
116
117
117
- response = GeminiClient .generate_content(" Hello, Gemini. What's the weather like in Seoul today?" )
118
+ response = client .generate_content(" Hello, Gemini. What's the weather like in Seoul today?" )
118
119
print (response.payload)
119
120
```
120
121
2 . * (Manually)* `F12` for browser console → `Session: Application` → `Cookies` → Copy the value of some working cookie sets. If it doesn' t work, go to step 3.
@@ -149,21 +150,21 @@ pip install -q -U python-gemini-api
149
150
```python
150
151
from gemini import Gemini
151
152
152
- cookies = {} # Cookies may vary by account or region. Consider sending the entire cookie file.
153
- GeminiClient = Gemini(cookies = cookies) # You can use various args
153
+ cookies = {" key " : " value " } # Cookies may vary by account or region. Consider sending the entire cookie file.
154
+ client = Gemini(cookies = cookies) # You can use various args
154
155
155
- response = GeminiClient .generate_content(" Hello, Gemini. What's the weather like in Seoul today?" )
156
+ response = client .generate_content(" Hello, Gemini. What's the weather like in Seoul today?" )
156
157
response.payload
157
158
```
158
159
159
160
** Generate content from image:** you can use image as input .
160
161
```python
161
162
from gemini import Gemini
162
163
163
- cookies = {} # Cookies may vary by account or region. Consider sending the entire cookie file.
164
+ cookies = {" key" : " value" } # Cookies may vary by account or region. Consider sending the entire cookie file.
165
+ client = Gemini(cookies = cookies) # You can use various args
164
166
165
- GeminiClient = Gemini(cookies = cookies) # You can use various args
166
- response = GeminiClient.generate_content(" What does the text in this image say?" , image = ' folder/image.jpg' )
167
+ response = client.generate_content(" What does the text in this image say?" , image = ' folder/image.jpg' )
167
168
response.payload
168
169
```
169
170
@@ -180,6 +181,7 @@ Setting Gemini response language (Optional): Check supported languages [here](ht
180
181
181
182
```python
182
183
import os
184
+
183
185
os.environ[" GEMINI_LANGUAGE" ] = " KR" # Setting Gemini response language (Optional)
184
186
os.environ[" GEMINI_ULTRA" ] = " 1" # Switch to Gemini-advanced response (Experimental, Optional)
185
187
# In some accounts, access to Gemini Ultra may not be available. If that's the case, please revert it back to "0".
@@ -206,9 +208,9 @@ cookies = {
206
208
# Cookies may vary by account or region. Consider sending the entire cookie file.
207
209
}
208
210
209
- GeminiClient = Gemini(cookies = cookies)
210
- # GeminiClient = Gemini(cookie_fp="folder/cookie_file.json") # (*.json, *.txt) are supported.
211
- # GeminiClient = Gemini(auto_cookies=True) # Or use auto_cookies paprameter
211
+ client = Gemini(cookies = cookies)
212
+ # client = Gemini(cookie_fp="folder/cookie_file.json") # (*.json, *.txt) are supported.
213
+ # client = Gemini(auto_cookies=True) # Or use auto_cookies paprameter
212
214
```
213
215
214
216
# #### Auto Cookie Update
@@ -224,7 +226,7 @@ Returns Gemini's response, but the first one might be empty.
224
226
225
227
```python
226
228
prompt = " Hello, Gemini. What's the weather like in Seoul today?"
227
- response = GeminiClient .generate_content(prompt)
229
+ response = client .generate_content(prompt)
228
230
print (response.payload)
229
231
```
230
232
@@ -255,9 +257,9 @@ Send request: returns the request's payload and status_code, making debugging ea
255
257
from gemini import Gemini
256
258
257
259
cookies = {} # Cookies may vary by account or region. Consider sending the entire cookie file.
258
- GeminiClient = Gemini(cookies = cookies) # You can use various args
260
+ client = Gemini(cookies = cookies) # You can use various args
259
261
260
- response_text, response_status = GeminiClient .send_request(" Hello, Gemini. What's the weather like in Seoul today?" )
262
+ response_text, response_status = client .send_request(" Hello, Gemini. What's the weather like in Seoul today?" )
261
263
print (response_text)
262
264
```
263
265
You can track the total number of requests made by accessing the `request_count` property within the `Gemini` class .
@@ -268,7 +270,7 @@ You can track the total number of requests made by accessing the `request_count`
268
270
Returns text generated by Gemini.
269
271
```python
270
272
prompt = " Hello, Gemini. What's the weather like in Seoul today?"
271
- response = GeminiClient .generate_content(prompt)
273
+ response = client .generate_content(prompt)
272
274
print (response.text)
273
275
```
274
276
@@ -281,7 +283,7 @@ Returns images generated by Gemini.
281
283
* Async downloader*
282
284
283
285
```python
284
- response = GeminiClient .generate_content(" Create illustrations of Seoul, South Korea." )
286
+ response = client .generate_content(" Create illustrations of Seoul, South Korea." )
285
287
286
288
generated_images = response.generated_images # Check generated images [Dict]
287
289
@@ -312,7 +314,7 @@ await GeminiImage.save(generated_images, "save_dir", cookies=cookies)
312
314
```python
313
315
from gemini import Gemini, GeminiImage
314
316
315
- response = GeminiClient .generate_content(" Create illustrations of Seoul, South Korea." )
317
+ response = client .generate_content(" Create illustrations of Seoul, South Korea." )
316
318
generated_images = response.generated_images # Check generated images [Dict]
317
319
318
320
GeminiImage.save_sync(generated_images, save_path = " save_dir" , cookies = cookies)
@@ -368,7 +370,7 @@ Returns images in response of Gemini.
368
370
369
371
* Async downloader*
370
372
```python
371
- response = GeminiClient .generate_content(" Create illustrations of Seoul, South Korea." )
373
+ response = client .generate_content(" Create illustrations of Seoul, South Korea." )
372
374
373
375
response_images = response.web_images # Check generated images [Dict]
374
376
@@ -384,7 +386,7 @@ await GeminiImage.save(response_images, "save_dir")
384
386
```python
385
387
from gemini import Gemini, GeminiImage
386
388
387
- response = GeminiClient .generate_content(" Please recommend a travel itinerary for Seoul." )
389
+ response = client .generate_content(" Please recommend a travel itinerary for Seoul." )
388
390
response_images = response.web_images # Check response images [Dict]
389
391
390
392
GeminiImage.save_sync(response_images, save_path = " save_dir" )
@@ -436,7 +438,7 @@ Takes an image as input and returns a response.
436
438
image = ' folder/image.jpg'
437
439
# image = open('folder/image.jpg', 'rb').read() # (jpg, jpeg, png, webp) are supported.
438
440
439
- response = GeminiClient .generate_content(" What does the text in this image say?" , image = image)
441
+ response = client .generate_content(" What does the text in this image say?" , image = image)
440
442
response.response_dict
441
443
```
442
444
@@ -450,7 +452,7 @@ To begin, you must link Google Workspace to activate this extension via the [Gem
450
452
@ Gmail, @ Google Drive, @ Google Docs, @ Google Maps, @ Google Flights, @ Google Hotels, @ YouTube
451
453
```
452
454
```python
453
- response = GeminiClient .generate_content(" @YouTube Search clips related with Google Gemini" )
455
+ response = client .generate_content(" @YouTube Search clips related with Google Gemini" )
454
456
response.response_dict
455
457
```
456
458
< details>< summary> Extension description< / summary>
@@ -489,15 +491,15 @@ You can specify a particular response by setting its Response Candidate ID(RCID)
489
491
490
492
```python
491
493
# Generate content for the prompt "Give me some information about the USA."
492
- response1 = GeminiClient .generate_content(" Give me some information about the USA." )
494
+ response1 = client .generate_content(" Give me some information about the USA." )
493
495
# After reviewing the responses, choose the one you prefer and copy its RCID.
494
- GeminiClient .rcid = " rc_xxxx"
496
+ client .rcid = " rc_xxxx"
495
497
496
498
# Now, generate content for the next prompt "How long does it take from LA to New York?"
497
- response2 = GeminiClient .generate_content(" How long does it take from LA to New York?" )
499
+ response2 = client .generate_content(" How long does it take from LA to New York?" )
498
500
499
- # However, RCID may not persist. If parsing fails, reset `GeminiClient .rcid` to None.
500
- # GeminiClient .rcid = None
501
+ # However, RCID may not persist. If parsing fails, reset `client .rcid` to None.
502
+ # client .rcid = None
501
503
```
502
504
503
505
@@ -510,7 +512,7 @@ In Gemini, generate_content returns the first response. This may vary depending
510
512
from gemini import GeminiModelOutput
511
513
512
514
GeminiModelOutput.chosen = 1 # default is 0
513
- response_choice_1 = GeminiClient .generate_content(" Give me some information about the USA." )
515
+ response_choice_1 = client .generate_content(" Give me some information about the USA." )
514
516
515
517
# If not all Gemini returns are necessarily plural, revert back to 0 in case of errors.
516
518
# GeminiModelOutput.chosen = 0
@@ -526,10 +528,10 @@ Using `Gemini.generate_custom_content`, specify custom parsing to extract specif
526
528
527
529
```python
528
530
# You can create a parser method that takes response_text as the input for custom_parser.
529
- response_text, response_status = GeminiClient .send_request(" Give me some information about the USA." )
531
+ response_text, response_status = client .send_request(" Give me some information about the USA." )
530
532
531
533
# Use custom_parser function or class inheriting from BaseParser
532
- response = GeminiClient .generate_custom_content(" Give me some information about the USA." , * custom_parser)
534
+ response = client .generate_custom_content(" Give me some information about the USA." , * custom_parser)
533
535
```
534
536
535
537
https:// github.com/ dsdanielpark/ Gemini- API / blob/ 31b842488bbc5429ad9c74b1d8b00e20d94e8cb1 / gemini/ client.py# L323
@@ -546,8 +548,8 @@ If you want to **avoid blocked requests** and bans, then use [Smart Proxy by Cra
546
548
proxy_url = " http://xxxxx:@smartproxy.crawlbase.com:8012"
547
549
proxies = {" http" : proxy_url, " https" : proxy_url}
548
550
549
- GeminiClient = Gemini(cookies = cookies, proxies = proxies, timeout = 30 )
550
- GeminiClient .generate_content(" Hello, Gemini. Give me a beautiful photo of Seoul's scenery." )
551
+ client = Gemini(cookies = cookies, proxies = proxies, timeout = 30 )
552
+ client .generate_content(" Hello, Gemini. Give me a beautiful photo of Seoul's scenery." )
551
553
```
552
554
553
555
# ## Reusable session object
@@ -563,8 +565,8 @@ session.headers = Headers.MAIN
563
565
for key, value in cookies.items():
564
566
session.cookies.update({key: value})
565
567
566
- GeminiClient = Gemini(session = session) # You can use various args
567
- response = GeminiClient .generate_content(" Hello, Gemini. What's the weather like in Seoul today?" )
568
+ client = Gemini(session = session) # You can use various args
569
+ response = client .generate_content(" Hello, Gemini. What's the weather like in Seoul today?" )
568
570
```
569
571
570
572
@@ -636,13 +638,13 @@ OpenRouter offers temporary free inference for select models. Obtain an API key
636
638
from gemini import OpenRouter
637
639
638
640
OPENROUTER_API_KEY = " <your_open_router_api_key>"
639
- GemmaClient = OpenRouter(api_key = OPENROUTER_API_KEY , model = " google/gemma-7b-it:free" )
641
+ gemma_client = OpenRouter(api_key = OPENROUTER_API_KEY , model = " google/gemma-7b-it:free" )
640
642
641
643
prompt = " Do you know UCA academy in Korea? https://blog.naver.com/ulsancoding"
642
- response = GemmaClient .create_chat_completion(prompt)
644
+ response = gemma_client .create_chat_completion(prompt)
643
645
print (response)
644
646
645
- # payload = GemmaClient .generate_content(prompt)
647
+ # payload = gemma_client .generate_content(prompt)
646
648
# print(payload.json())
647
649
```
648
650
@@ -713,19 +715,21 @@ Core maintainers:
713
715
714
716
715
717
# # References
716
- [1 ]: Paper - [Introducing GEMINI : Multimodal Generative Models](https:// arxiv.org/ abs / 2312.11805 ) < br>
717
- [2 ]: Website - [Google DeepMind :: GEMINI Introduction](https:// deepmind.google/ technologies/ gemini/ # introduction) <br>
718
- [3 ]: Paper - [GEMMA : A Unified Language Model for Text Generation, Understanding, Translation, Coding, and Math.]() < br>
719
- [4 ]: Website - [AI at Google :: GEMS Documentation](https:// ai.google.dev/ gemma/ docs) < br>
720
- [5 ]: Report - [CodeGMMA: Large Language Models Can Write Realistic Programming Assignments](https:// storage.googleapis.com/ deepmind- media/ gemma/ codegemma_report.pdf? utm_source = substack& utm_medium = email) < br>
721
- [6 ]: Blog Post - [Announcing CodeGen: Building Better Developers’ Tools Using LLMs](https:// huggingface.co/ blog/ codegen) < br>
722
- [7 ]: Collection - [Google :: CodeGen Release](https:// huggingface.co/ collections/ google/ codegen- release- 5d0f4c4eaedbc5cefcfdcbdf ) < br>
723
- [8 ]: Github - [acheong08/ Bard](https:// github.com/ acheong08/ Bard) < br>
724
- [9 ]: GitHub - [HanaokaYuzu/ Gemini- API ](https:// github.com/ HanaokaYuzu/ Gemini- API ) < br>
725
- [10 ]: Github - [dsdanielpark/ Bard- API ](https:// github.com/ dsdanielpark/ Bard- API ) < br>
726
- [11 ]: Github - [GoogleCloudPlatform/ generative- ai](https:// github.com/ GoogleCloudPlatform/ generative- ai) < br>
727
- [12 ]: Github - [OpenRouter](https:// github.com/ OpenRouterTeam/ openrouter- runner) < br>
728
- [13 ]: WebSite - [Google AI Studio](https:// ai.google.dev/ tutorials/ ai- studio_quickstart) < br>
718
+ 1 . [Introducing GEMINI : Multimodal Generative Models](https:// arxiv.org/ abs / 2312.11805 )
719
+ 2 . [Google DeepMind: GEMINI Introduction](https:// deepmind.google/ technologies/ gemini/ # introduction)
720
+ 3 . [GEMMA : A Unified Language Model for Text Generation, Understanding, Translation, Coding, and Math](https:// arxiv.org/ abs / 2403.08295 )
721
+ 4 . [AI at Google: GEMS Documentation](https:// ai.google.dev/ gemma/ docs)
722
+ 5 . [CodeGMMA: Large Language Models Can Write Realistic Programming Assignments](https:// storage.googleapis.com/ deepmind- media/ gemma/ codegemma_report.pdf? utm_source = substack& utm_medium = email)
723
+ 6 . [Announcing CodeGen: Building Better Developers' Tools Using LLMs](https://huggingface.co/blog/codegen)
724
+ 7 . [Google: CodeGen Release](https:// huggingface.co/ collections/ google/ codegen- release- 5d0f4c4eaedbc5cefcfdcbdf )
725
+ 8 . [acheong08/ Bard](https:// github.com/ acheong08/ Bard)
726
+ 9 . [dsdanielpark/ Bard- API ](https:// github.com/ dsdanielpark/ Bard- API )
727
+ 10 . [HanaokaYuzu/ Gemini- API ](https:// github.com/ HanaokaYuzu/ Gemini- API )
728
+ 11 . [GoogleCloudPlatform/ generative- ai](https:// github.com/ GoogleCloudPlatform/ generative- ai)
729
+ 12 . [OpenRouter](https:// github.com/ OpenRouterTeam/ openrouter- runner)
730
+ 13 . [Google AI Studio](https:// ai.google.dev/ tutorials/ ai- studio_quickstart)
731
+
732
+ < br>
729
733
730
734
731
735
> * Warning *
0 commit comments