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 authored Mar 7, 2024
1 parent 96773d7 commit e3c2162
Showing 1 changed file with 26 additions and 17 deletions.
43 changes: 26 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pip install -q -U python-gemini-api
## Usage


### #01. Initialization
### # 01. Initialization


```python
Expand All @@ -102,8 +102,9 @@ GeminiClient = Gemini(cookies=cookies)
> [!IMPORTANT]
> **If the session connects successfully and 'generate_content' runs well, PLEASE CLOSE Gemini website.** If Gemini web stays open in the browser, cookies may expire faster.
<br>

### #02. Generate Content
### # 02. Generate Content


```python
Expand All @@ -113,17 +114,23 @@ print(response.response_dict)
```
The output of the `generate_content` function is `GeminiModelOutput`, with the following structure:

- Properties:
- **rcid**: Returns the RCID 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.
- **response_dict**: Returns the response dictionary, if available.
**Properties:**
- *rcid*: returns the response choice 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.
- *response_dict*: returns the response dictionary, if available.

> [!IMPORTANT]
> Once connected and generating valid content, **avoid closing the browser or revisiting Gemini web** for cookie stability.

> [!NOTE]
> If the session fails to connect, works improperly, or terminates, returning an error, it is recommended to manually renew the cookies. The error is likely due to incorrect cookie values. Refresh or log out of Gemini web to renew cookies and try again. *Once connected and generating valid content, avoid closing the browser or revisiting Gemini web for cookie stability.*
> If the session fails to connect, works improperly, or terminates, returning an error, it is recommended to manually renew the cookies. The error is likely due to incorrect cookie values. Refresh or log out of Gemini web to renew cookies and try again.
<br>

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


<br>


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

*Sync*
```python
from gemini import Gemini, GeminiImage

prompt = "Generate seoul N tower illustrations."
prompt = "Generate Seoul, South Korea illustrations."
response = GeminiClient.generate_content(prompt)

generated_images = response.generated_image # Check generated images [Dict]
Expand All @@ -154,7 +161,7 @@ import asyncio
from gemini import Gemini, GeminiImage

async def generate_and_save_images_async():
prompt = "Generate seoul N tower illustrations."
prompt = "Generate Seoul, South Korea illustrations."
response = await GeminiClient.generate_content_async(prompt)

generated_images = response.generated_image # Check generated images [Dict]
Expand All @@ -168,14 +175,16 @@ if __name__ == "__main__":
```


### #05. Retrieving Images from Gemini Responses
<br>

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

*Sync*
```python
from gemini import Gemini, GeminiImage

prompt = "Generate seoul N tower illustrations."
prompt = "Generate Seoul, South Korea illustrations."
response = GeminiClient.generate_content(prompt)

response_images = response.web_images # Check response images [Dict]
Expand All @@ -188,7 +197,7 @@ import asyncio
from gemini import Gemini, GeminiImage

async def fetch_and_save_images_async():
prompt = "Generate seoul N tower illustrations."
prompt = "Generate Seoul, South Korea illustrations."
response = await GeminiClient.generate_content_async(prompt)

response_images = response.web_images # Check response images [Dict]
Expand Down

0 comments on commit e3c2162

Please sign in to comment.