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
Browse files Browse the repository at this point in the history
  • Loading branch information
dsdanielpark committed Mar 21, 2024
1 parent a813b92 commit b2d96de
Showing 1 changed file with 37 additions and 28 deletions.
65 changes: 37 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ Collaborated competently with [Antonio Cheong](https://github.com/acheong08).
- [Usage](#usage)
- [# 01. Initialization](#-01-initialization)
- [# 02. Generate content](#-02-generate-content)
- [# 03. Text generation](#-03-text-generation)
- [# 04. Image generation](#-04-image-generation)
- [# 05. Retrieving Images from Gemini Responses](#-05-retrieving-images-from-gemini-responses)
- [# 06. Generate content from images](#-06-generate-content-from-images)
- [# 07. Generate content using Google Services](#-07-generate-content-using-google-services)
- [# 08. Fix context setting rcid](#-08-fix-context-setting-rcid)
- [# 09. Changing the Selected Response from 0 to n](#-09-changing-the-selected-response-from-0-to-n)
- [# 10. Generate custom content](#-10-generate-custom-content)
- [# 03. Send request](#-03-send-request)
- [# 04. Text generation](#-04-text-generation)
- [# 05. Image generation](#-05-image-generation)
- [# 06. Retrieving Images from Gemini Responses](#-06-retrieving-images-from-gemini-responses)
- [# 07. Generate content from images](#-07-generate-content-from-images)
- [# 08. Generate content using Google Services](#-08-generate-content-using-google-services)
- [# 09. Fix context setting rcid](#-09-fix-context-setting-rcid)
- [# 10. Changing the Selected Response from 0 to n](#-10-changing-the-selected-response-from-0-to-n)
- [# 11. Generate custom content](#-11-generate-custom-content)
- [More features](#more-features)
- [Open-source LLM, Gemma](#open-source-llm-gemma)
- [How to use Gemma](#how-to-use-gemma)
Expand Down Expand Up @@ -105,7 +106,7 @@ pip install -q -U python-gemini-api

<br>

## Usage
## Quick Start

*Simple usage*

Expand All @@ -116,16 +117,6 @@ import os
os.environ["GEMINI_LANGUAGE"] = "KR"
```

Send request: returns original payload.
```python
from gemini import Gemini

cookies = {} # Cookies may vary by account or region. Consider sending the entire cookie file.
GeminiClient = Gemini(cookies=cookies) # You can use various args

response_text, response_status = GeminiClient.send_request("Hello, Gemini. What's the weather like in Seoul today?")
print(response_text)
```


Generate content: returns parsed response.
Expand Down Expand Up @@ -153,9 +144,11 @@ response.payload
> [!NOTE]
> If the generate_content method returns an empty payload, try executing it again without reinitializing the Gemini object.

<br>

## Usage


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

Expand Down Expand Up @@ -220,7 +213,23 @@ https://github.com/dsdanielpark/Gemini-API/blob/fdf064c57bc1fb47fbbb4b93067618a2
<br>

### # 03. Text generation

### # 03. Send request
Send request: returns the request's payload and status_code, making debugging easier.
```python
from gemini import Gemini

cookies = {} # Cookies may vary by account or region. Consider sending the entire cookie file.
GeminiClient = Gemini(cookies=cookies) # You can use various args

response_text, response_status = GeminiClient.send_request("Hello, Gemini. What's the weather like in Seoul today?")
print(response_text)
```


<br>

### # 04. Text generation
Returns text generated by Gemini.
```python
prompt = "Hello, Gemini. What's the weather like in Seoul today?"
Expand All @@ -231,7 +240,7 @@ print(response.text)

<br>

### # 04. Image generation
### # 05. Image generation
Returns images generated by Gemini.
https://github.com/dsdanielpark/Gemini-API/blob/fdf064c57bc1fb47fbbb4b93067618a200e77f62/gemini/src/model/image.py#L12

Expand Down Expand Up @@ -321,7 +330,7 @@ if __name__ == "__main__":
<br>

### # 05. Retrieving Images from Gemini Responses
### # 06. Retrieving Images from Gemini Responses
Returns images in response of Gemini.

*Sync downloader*
Expand Down Expand Up @@ -384,7 +393,7 @@ if __name__ == "__main__":

<br>

### # 06. Generate content from images
### # 07. Generate content from images
Takes an image as input and returns a response.

```python
Expand All @@ -397,7 +406,7 @@ response.response_dict

<br>

### # 07. Generate content using Google Services
### # 08. Generate content using Google Services
To begin, you must link Google Workspace to activate this extension via the [Gemini web extension](https://gemini.google.com/extensions). Please refer to the [official notice](https://support.google.com/gemini/answer/13695044) and review the [privacy policies](https://support.google.com/gemini/answer/13594961?visit_id=638457301410420313-1578971242&p=privacy_help&rd=1) for more details.

*extention flags*
Expand Down Expand Up @@ -439,7 +448,7 @@ response.response_dict
<br>


### # 08. Fix context setting rcid
### # 09. Fix context setting rcid
You can specify a particular response by setting its response candidate id(rcid).

```python
Expand All @@ -454,7 +463,7 @@ response2 = GeminiClient.generate_content("How long does it take from LA to New

<br>

### # 09. Changing the Selected Response from 0 to *n*
### # 10. 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
Expand All @@ -464,7 +473,7 @@ response1 = GeminiClient.generate_content("Give me some information about the US

<br>

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

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

0 comments on commit b2d96de

Please sign in to comment.