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

Commit

Permalink
doc: update readme for v2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dsdanielpark authored Mar 11, 2024
1 parent fdf064c commit 72e8854
Showing 1 changed file with 35 additions and 18 deletions.
53 changes: 35 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@



A *unofficial* Python wrapper, [python-gemini-api](https://pypi.org/project/python-gemini-api/), operates through reverse-engineering, utilizing cookie values to interact with [Google Gemini](https://gemini.google.com) for users struggling with frequent authentication problems or unable to authenticate via [Google Authentication](https://developers.google.com/identity/protocols/oauth2?hl=en). This repository is not expected to be updated frequently, and it will be modified for personal use.
A *unofficial* Python wrapper, [python-gemini-api](https://pypi.org/project/python-gemini-api/), operates through reverse-engineering, utilizing cookie values to interact with [Google Gemini](https://gemini.google.com) for users struggling with frequent authentication problems or unable to authenticate via [Google Authentication](https://developers.google.com/identity/protocols/oauth2?hl=en). This repository is not expected to be updated frequently.

Collaborated competently with [Antonio Cheong](https://github.com/acheong08).

Expand Down Expand Up @@ -61,7 +61,7 @@ pip install -q -U python-gemini-api
```
## Authentication
> [!NOTE]
> Cookies can change quickly. Don't reopen the same session or repeat prompts too often; they'll expire faster. If the cookie value doesn't export correctly, refresh the Gemini page and export again. Check this [sample cookie file](https://github.com/dsdanielpark/Gemini-API/blob/main/cookies.txt).
> Cookies can change quickly. Don't reopen the same session or repeat prompts too often; they'll expire faster. If the cookie value doesn't export correctly, refresh the Gemini page and export again.
1. Visit https://gemini.google.com/
2. `F12` for browser console → `Session: Application``Cookies` → Copy the value of some working cookie sets. If it doesn't work, go to step 3.
<details><summary>Some working cookie sets</summary>
Expand All @@ -85,7 +85,7 @@ pip install -q -U python-gemini-api


### # 01. Initialization
Please explicitly declare `cookies` in dict format. You can also enter the path to the file containing the cookie with `cookie_fp`.
Please explicitly declare `cookies` in dict format. You can also enter the path to the file containing the cookie with `cookie_fp`. Check this [sample cookie file](https://github.com/dsdanielpark/Gemini-API/blob/main/cookies.txt).

```python
from gemini import Gemini
Expand All @@ -109,8 +109,9 @@ GeminiClient = Gemini(cookies=cookies)
<br>

### # 02. Generate content
To check regardless of the data type of the model output, return the response_dict argument. And use it appropriately.

To check regardless of the data type of the model output, return the response_dict argument. And use it appropriately.
https://github.com/dsdanielpark/Gemini-API/blob/fdf064c57bc1fb47fbbb4b93067618a200e77f62/gemini/core.py#L252
```python
prompt = "Hello, Gemini. What's the weather like in Seoul today?"
response = GeminiClient.generate_content(prompt)
Expand All @@ -119,11 +120,13 @@ print(response.response_dict)
> [!IMPORTANT]
> Once connected and generating valid content, **Be sure to CLOSE the gemini website or CLOSE your browser** for cookie stability.
<br>

The output of the `generate_content` function is `GeminiModelOutput`, with the following structure:
The output of the generate_content function is `GeminiModelOutput`, with the following structure:

**Properties of `GeminiModelOutput`:**
- *rcid*: returns the response choice id of the chosen candidate.
**Properties of GeminiModelOutput:**
https://github.com/dsdanielpark/Gemini-API/blob/fdf064c57bc1fb47fbbb4b93067618a200e77f62/gemini/src/model/output.py#L16
- *rcid*: returns the response candidate id of the chosen candidate.
- *text*: returns the text of the chosen candidate.
- *web_images*: returns a list of web images from the chosen candidate.
- *generated_images*: returns a list of generated images from the chosen candidate.
Expand All @@ -149,7 +152,7 @@ print(response.text)

### # 04. Image generation
Returns images generated by Gemini.

https://github.com/dsdanielpark/Gemini-API/blob/fdf064c57bc1fb47fbbb4b93067618a200e77f62/gemini/src/model/image.py#L12

*Sync downloader*
```python
Expand All @@ -167,6 +170,8 @@ GeminiImage.save_sync(generated_images, save_path="save_dir", cookies=cookies)

<details><summary>Display images in IPython</summary>

You can display the image or transmit it to another application in byte format.

```python
bytes_images_dict = GeminiImage.fetch_images_dict_sync(generated_images, cookies) # Get bytes images dict
from IPython.display import display, Image
Expand All @@ -181,6 +186,7 @@ GeminiImage.save_sync(generated_images, save_path="save_dir", cookies=cookies)
</details>



*Async downloader*

```python
Expand Down Expand Up @@ -324,27 +330,27 @@ response.response_dict
<details><summary>Extension description</summary>

- Google Workspace
- Services: @Gmail, @Google Drive, @Google Docs
- Services: **@Gmail, @Google Drive, @Google Docs**
- Description: Summarize, search, and find desired information quickly in your content for efficient personal task management.
- Features: Information retrieval, document summarization, information categorization

- Google Maps
- Service: @Google Maps
- Service: **@Google Maps**
- Description: Execute plans using location-based information. Note: Google Maps features may be limited in some regions.
- Features: Route guidance, nearby search, navigation

- Google Flights
- Service: @Google Flights
- Service: **@Google Flights**
- Description: Search real-time flight information to plan tailored travel itineraries.
- Features: Holiday preparation, price comparison, trip planning

- Google Hotels
- Service: @Google Hotels
- Service: **@Google Hotels**
- Description: Search for hotels considering what matters most to you, like having a conversation with a friend.
- Features: Packing for travel, sightseeing, special relaxation

- YouTube
- Service: @YouTube
- Service: **@YouTube**
- Description: Explore YouTube videos and ask questions about what interests you.
- Features: Problem-solving, generating ideas, search, exploring topics
</details>
Expand All @@ -353,7 +359,7 @@ response.response_dict


### # 08. Fix context setting rcid
You can specify a particular response by setting its Response Choice ID (RCID).
You can specify a particular response by setting its response candidate id(rcid).

```python
# Generate content for the prompt "Give me some information about the USA."
Expand All @@ -367,8 +373,8 @@ response2 = GeminiClient.generate_content("How long does it take from LA to New

<br>

### # 09. Changing the Selected Response from 0 to n
In Gemini, generate_content returns the first response. This may vary depending on length or sorting. Therefore, you can specify the index of the chosen response from 0 to n as follows. However, if there is only one response, revert it back to 0.
### # 09. Changing the Selected Response from 0 to *n*
In Gemini, generate_content returns the first response. This may vary depending on length or sorting. Therefore, you can specify the index of the chosen response from 0 to *n* as follows. However, if there is only one response, revert it back to 0.
```python
from gemini import GeminiModelOutput
GeminiModelOutput.chosen = 1 # default is 0
Expand All @@ -377,6 +383,15 @@ response1 = GeminiClient.generate_content("Give me some information about the US

<br>

### # 10. Generate custom content
Parse the response text to extract desired values.

https://github.com/dsdanielpark/Gemini-API/blob/fdf064c57bc1fb47fbbb4b93067618a200e77f62/gemini/core.py#L317

Using `Gemini.generate_custom_content`, specify custom parsing to extract specific values. Utilize ParseMethod1 and ParseMethod2 by default, and you can pass custom parsing methods as arguments if desired. Refer to [custom_parser.py](https://github.com/dsdanielpark/Gemini-API/blob/main/gemini/src/parser/custom_parser.py).

<br>

## Further

### Use rotating proxies
Expand Down Expand Up @@ -430,14 +445,16 @@ print(tokenizer.decode(outputs[0]))
You can find most help on the [FAQ](https://github.com/dsdanielpark/Gemini-API/blob/main/documents/README_FAQ.md) and [Issue](https://github.com/dsdanielpark/Gemini-API/issues) pages. Alternatively, utilize the official Gemini API at [Google AI Studio](https://ai.google.dev/tutorials/ai-studio_quickstart).


## Sponsor
Use [Crawlbase](https://crawlbase.com/) API for efficient data scraping to train AI models, boasting a 98% success rate and 99.9% uptime. It's quick to start, GDPR/CCPA compliant, supports massive data extraction, and is trusted by 70k+ developers.


## [Issues](https://github.com/dsdanielpark/Gemini-API/issues)
Sincerely grateful for any reports on new features or bugs. Your valuable feedback on the code is highly appreciated. Frequent errors may occur due to changes in Google's service API interface. Both [Issue reports](https://github.com/dsdanielpark/Gemini-API/issues) and [Pull requests](https://github.com/dsdanielpark/Gemini-API/pulls) contributing to improvements are always welcome. We strive to maintain an active and courteous open community.


## Sponsor
Use [Crawlbase](https://crawlbase.com/) API for efficient data scraping to train AI models, boasting a 98% success rate and 99.9% uptime. It's quick to start, GDPR/CCPA compliant, supports massive data extraction, and is trusted by 70k+ developers.

## Contributors
We would like to express our sincere gratitude to all the contributors.

Expand Down

0 comments on commit 72e8854

Please sign in to comment.