Skip to content

Commit

Permalink
docs: update README.md with auto_close explanation and sample code of…
Browse files Browse the repository at this point in the history
… Gemini extensions
  • Loading branch information
HanaokaYuzu committed Feb 29, 2024
1 parent 3341fd2 commit b4f8e92
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ Secure_1PSIDTS = "COOKIE VALUE HERE"

async def main():
client = GeminiClient(Secure_1PSID, Secure_1PSIDTS, proxy=None)
await client.init(timeout=30)
await client.init(timeout=30, auto_close=False, close_delay=300)

asyncio.run(main())
```

Note: `auto_close` and `close_delay` are optional arguments for automatically closing the client after a certain period of inactivity. This feature is disabled by default. In a keep-alive service like chatbot, it's recommended to set `auto_close` to `True` combined with reasonable seconds of `close_delay` for better resource management.

### Generate contents from text inputs

Ask a one-turn quick question by calling `GeminiClient.generate_content`.
Expand Down Expand Up @@ -140,6 +142,19 @@ asyncio.run(main())
Note: for the last item, instead of region requirement, it actually only requires your Google account's **preferred language** to be set to one of the supported languages. You can change your language settings [here](https://myaccount.google.com/language).

After activating extensions for your account, you can access them in your prompts either by natural language or by starting your prompt with "@" followed by the extension keyword.

```python
async def main():
response1 = await client.generate_content("@Gmail What's the latest message in my mailbox?")
print(response1, "\n\n----------------------------------\n")

response2 = await client.generate_content("@Youtube What's the lastest activity of Taylor Swift?")
print(response2, "\n\n----------------------------------\n")

asyncio.run(main())
```

### Check and switch to other answer candidates

A response from Gemini usually contains multiple reply candidates with different generated contents. You can check all candidates and choose one to continue the conversation. By default, the first candidate will be chosen automatically.
Expand Down

0 comments on commit b4f8e92

Please sign in to comment.