Skip to content
This repository was archived by the owner on Jun 12, 2024. It is now read-only.

Commit df0515b

Browse files
committed
2 parents 0455936 + c501950 commit df0515b

File tree

1 file changed

+55
-51
lines changed

1 file changed

+55
-51
lines changed

README.md

Lines changed: 55 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,14 @@ pip install -q -U python-gemini-api
108108
With browser open, try auto-collecting cookies first.
109109
```python
110110
from gemini import Gemini
111-
GeminiClient = Gemini(auto_cookies=True)
111+
112+
client = Gemini(auto_cookies=True)
112113

113114
# 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
116117

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?")
118119
print(response.payload)
119120
```
120121
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
149150
```python
150151
from gemini import Gemini
151152

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
154155

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?")
156157
response.payload
157158
```
158159

159160
**Generate content from image:** you can use image as input.
160161
```python
161162
from gemini import Gemini
162163

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
164166

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')
167168
response.payload
168169
```
169170

@@ -180,6 +181,7 @@ Setting Gemini response language (Optional): Check supported languages [here](ht
180181

181182
```python
182183
import os
184+
183185
os.environ["GEMINI_LANGUAGE"] = "KR" # Setting Gemini response language (Optional)
184186
os.environ["GEMINI_ULTRA"] = "1" # Switch to Gemini-advanced response (Experimental, Optional)
185187
# 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 = {
206208
# Cookies may vary by account or region. Consider sending the entire cookie file.
207209
}
208210

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
212214
```
213215

214216
##### Auto Cookie Update
@@ -224,7 +226,7 @@ Returns Gemini's response, but the first one might be empty.
224226

225227
```python
226228
prompt = "Hello, Gemini. What's the weather like in Seoul today?"
227-
response = GeminiClient.generate_content(prompt)
229+
response = client.generate_content(prompt)
228230
print(response.payload)
229231
```
230232

@@ -255,9 +257,9 @@ Send request: returns the request's payload and status_code, making debugging ea
255257
from gemini import Gemini
256258

257259
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
259261

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?")
261263
print(response_text)
262264
```
263265
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`
268270
Returns text generated by Gemini.
269271
```python
270272
prompt = "Hello, Gemini. What's the weather like in Seoul today?"
271-
response = GeminiClient.generate_content(prompt)
273+
response = client.generate_content(prompt)
272274
print(response.text)
273275
```
274276

@@ -281,7 +283,7 @@ Returns images generated by Gemini.
281283
*Async downloader*
282284

283285
```python
284-
response = GeminiClient.generate_content("Create illustrations of Seoul, South Korea.")
286+
response = client.generate_content("Create illustrations of Seoul, South Korea.")
285287

286288
generated_images = response.generated_images # Check generated images [Dict]
287289

@@ -312,7 +314,7 @@ await GeminiImage.save(generated_images, "save_dir", cookies=cookies)
312314
```python
313315
from gemini import Gemini, GeminiImage
314316

315-
response = GeminiClient.generate_content("Create illustrations of Seoul, South Korea.")
317+
response = client.generate_content("Create illustrations of Seoul, South Korea.")
316318
generated_images = response.generated_images # Check generated images [Dict]
317319

318320
GeminiImage.save_sync(generated_images, save_path="save_dir", cookies=cookies)
@@ -368,7 +370,7 @@ Returns images in response of Gemini.
368370

369371
*Async downloader*
370372
```python
371-
response = GeminiClient.generate_content("Create illustrations of Seoul, South Korea.")
373+
response = client.generate_content("Create illustrations of Seoul, South Korea.")
372374

373375
response_images = response.web_images # Check generated images [Dict]
374376

@@ -384,7 +386,7 @@ await GeminiImage.save(response_images, "save_dir")
384386
```python
385387
from gemini import Gemini, GeminiImage
386388

387-
response = GeminiClient.generate_content("Please recommend a travel itinerary for Seoul.")
389+
response = client.generate_content("Please recommend a travel itinerary for Seoul.")
388390
response_images = response.web_images # Check response images [Dict]
389391

390392
GeminiImage.save_sync(response_images, save_path="save_dir")
@@ -436,7 +438,7 @@ Takes an image as input and returns a response.
436438
image = 'folder/image.jpg'
437439
# image = open('folder/image.jpg', 'rb').read() # (jpg, jpeg, png, webp) are supported.
438440

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)
440442
response.response_dict
441443
```
442444

@@ -450,7 +452,7 @@ To begin, you must link Google Workspace to activate this extension via the [Gem
450452
@Gmail, @Google Drive, @Google Docs, @Google Maps, @Google Flights, @Google Hotels, @YouTube
451453
```
452454
```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")
454456
response.response_dict
455457
```
456458
<details><summary>Extension description</summary>
@@ -489,15 +491,15 @@ You can specify a particular response by setting its Response Candidate ID(RCID)
489491

490492
```python
491493
# 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.")
493495
# After reviewing the responses, choose the one you prefer and copy its RCID.
494-
GeminiClient.rcid = "rc_xxxx"
496+
client.rcid = "rc_xxxx"
495497

496498
# 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?")
498500

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
501503
```
502504

503505

@@ -510,7 +512,7 @@ In Gemini, generate_content returns the first response. This may vary depending
510512
from gemini import GeminiModelOutput
511513

512514
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.")
514516

515517
# If not all Gemini returns are necessarily plural, revert back to 0 in case of errors.
516518
# GeminiModelOutput.chosen = 0
@@ -526,10 +528,10 @@ Using `Gemini.generate_custom_content`, specify custom parsing to extract specif
526528

527529
```python
528530
# 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.")
530532

531533
# 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)
533535
```
534536

535537
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
546548
proxy_url = "http://xxxxx:@smartproxy.crawlbase.com:8012"
547549
proxies = {"http": proxy_url, "https": proxy_url}
548550

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.")
551553
```
552554

553555
### Reusable session object
@@ -563,8 +565,8 @@ session.headers = Headers.MAIN
563565
for key, value in cookies.items():
564566
session.cookies.update({key: value})
565567

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?")
568570
```
569571

570572

@@ -636,13 +638,13 @@ OpenRouter offers temporary free inference for select models. Obtain an API key
636638
from gemini import OpenRouter
637639

638640
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")
640642

641643
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)
643645
print(response)
644646

645-
# payload = GemmaClient.generate_content(prompt)
647+
# payload = gemma_client.generate_content(prompt)
646648
# print(payload.json())
647649
```
648650

@@ -713,19 +715,21 @@ Core maintainers:
713715

714716

715717
## 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>
729733

730734

731735
> *Warning*

0 commit comments

Comments
 (0)