Skip to content

Commit

Permalink
build: rename package import name from "gemini" to "gemini_webapi"
Browse files Browse the repository at this point in the history
- close #8
  • Loading branch information
HanaokaYuzu committed Mar 1, 2024
1 parent b5c58a8 commit be49bc3
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 12 deletions.
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ A reverse-engineered asynchronous python wrapper for [Google Gemini](https://gem
## Installation

```bash
pip install gemini-webapi
pip install gemini_webapi
```

## Authentication
Expand All @@ -36,7 +36,7 @@ Import required packages and initialize a client with your cookies obtained from

```python
import asyncio
from gemini import GeminiClient
from gemini_webapi import GeminiClient

# Replace "COOKIE VALUE HERE" with your actual cookie values
Secure_1PSID = "COOKIE VALUE HERE"
Expand Down Expand Up @@ -163,14 +163,17 @@ A response from Gemini usually contains multiple reply candidates with different
async def main():
# Start a conversation and list all reply candidates
chat = client.start_chat()
response = await chat.send_message("What's the best Japanese dish? Recommend one only.")
response = await chat.send_message("Recommend a science fiction book for me.")
for candidate in response.candidates:
print(candidate, "\n\n----------------------------------\n")

# Control the ongoing conversation flow by choosing candidate manually
new_candidate = chat.choose_candidate(index=1) # Choose the second candidate here
followup_response = await chat.send_message("Tell me more about it.") # Will generate contents based on the chosen candidate
print(new_candidate, followup_response, sep="\n\n----------------------------------\n\n")
if len(response.candidates) > 1:
# Control the ongoing conversation flow by choosing candidate manually
new_candidate = chat.choose_candidate(index=1) # Choose the second candidate here
followup_response = await chat.send_message("Tell me more about it.") # Will generate contents based on the chosen candidate
print(new_candidate, followup_response, sep="\n\n----------------------------------\n\n")
else:
print("Only one candidate available.")

asyncio.run(main())
```
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Issues = "https://github.com/HanaokaYuzu/Gemini-API/issues"

[tool.setuptools.packages.find]
where = ["src"]
include = ["gemini"]
include = ["gemini_webapi"]

[tool.setuptools_scm]
version_scheme = "post-release"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ async def save(
-------
`str | None`
Absolute path of the saved image if successful, None if filename is invalid and `skip_invalid_filename` is True
Raises
------
`httpx.HTTPError`
If the network request failed
"""
filename = filename or self.url.split("/")[-1].split("?")[0]
try:
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions tests/test_client_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from loguru import logger

from gemini import GeminiClient, AuthError
from gemini_webapi import GeminiClient, AuthError


class TestGeminiClient(unittest.IsolatedAsyncioTestCase):
Expand Down Expand Up @@ -65,7 +65,7 @@ async def test_extension_youtube(self):
async def test_reply_candidates(self):
chat = self.geminiclient.start_chat()
response = await chat.send_message(
"What's the best Japanese dish? Recommend one only."
"Recommend a science fiction book for me."
)

if len(response.candidates) == 1:
Expand Down
10 changes: 8 additions & 2 deletions tests/test_save_image.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import os
import unittest

from gemini import GeminiClient, AuthError
from httpx import HTTPError
from loguru import logger

from gemini_webapi import GeminiClient, AuthError


class TestGeminiClient(unittest.IsolatedAsyncioTestCase):
Expand All @@ -22,7 +25,10 @@ async def test_save_web_image(self):
self.assertTrue(response.images)
for i, image in enumerate(response.images):
self.assertTrue(image.url)
await image.save(verbose=True, skip_invalid_filename=True)
try:
await image.save(verbose=True, skip_invalid_filename=True)
except HTTPError as e:
logger.warning(e)

async def test_save_generated_image(self):
response = await self.geminiclient.generate_content(
Expand Down

0 comments on commit be49bc3

Please sign in to comment.