-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- fix: update index of GeneratedImage.alt - fix: now secure_1psidts will only be passed to cookies if it is not empty - feat: add an optional parameter to Image.save() to skip images with invalid file names - feat: Image.save() now returns saved file path on success - refactor: code reorganization and cleanup - test: updated unit tests
- Loading branch information
1 parent
b4f8e92
commit b5c58a8
Showing
11 changed files
with
157 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
from .client import GeminiClient, ChatSession # noqa: F401 | ||
from .exceptions import * # noqa: F401, F403 | ||
from .types import * # noqa: F401, F403 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
class AuthError(Exception): | ||
""" | ||
Exception for authentication errors caused by invalid credentials/cookies. | ||
""" | ||
|
||
pass | ||
|
||
|
||
class APIError(Exception): | ||
""" | ||
Exception for package-level errors which need to be fixed in the future development (e.g. validation errors). | ||
""" | ||
|
||
pass | ||
|
||
|
||
class GeminiError(Exception): | ||
""" | ||
Exception for errors returned from Gemini server which are not handled by the package. | ||
""" | ||
|
||
pass | ||
|
||
|
||
class TimeoutError(GeminiError): | ||
""" | ||
Exception for request timeouts. | ||
""" | ||
|
||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .image import Image, WebImage, GeneratedImage # noqa: F401 | ||
from .candidate import Candidate # noqa: F401 | ||
from .modeloutput import ModelOutput # noqa: F401 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from pydantic import BaseModel | ||
|
||
from .image import Image, WebImage, GeneratedImage | ||
|
||
|
||
class Candidate(BaseModel): | ||
""" | ||
A single reply candidate object in the model output. A full response from Gemini usually contains multiple reply candidates. | ||
Parameters | ||
---------- | ||
rcid: `str` | ||
Reply candidate ID to build the metadata | ||
text: `str` | ||
Text output | ||
web_images: `list[WebImage]`, optional | ||
List of web images in reply, can be empty. | ||
generated_images: `list[GeneratedImage]`, optional | ||
List of generated images in reply, can be empty | ||
""" | ||
|
||
rcid: str | ||
text: str | ||
web_images: list[WebImage] = [] | ||
generated_images: list[GeneratedImage] = [] | ||
|
||
def __str__(self): | ||
return self.text | ||
|
||
def __repr__(self): | ||
return f"Candidate(rcid='{self.rcid}', text='{len(self.text) <= 20 and self.text or self.text[:20] + '...'}', images={self.images})" | ||
|
||
@property | ||
def images(self) -> list[Image]: | ||
return self.web_images + self.generated_images |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from pydantic import BaseModel | ||
|
||
from .image import Image | ||
from .candidate import Candidate | ||
|
||
|
||
class ModelOutput(BaseModel): | ||
""" | ||
Classified output from gemini.google.com | ||
Parameters | ||
---------- | ||
metadata: `list[str]` | ||
List of chat metadata `[cid, rid, rcid]`, can be shorter than 3 elements, like `[cid, rid]` or `[cid]` only | ||
candidates: `list[Candidate]` | ||
List of all candidates returned from gemini | ||
chosen: `int`, optional | ||
Index of the chosen candidate, by default will choose the first one | ||
""" | ||
|
||
metadata: list[str] | ||
candidates: list[Candidate] | ||
chosen: int = 0 | ||
|
||
def __str__(self): | ||
return self.text | ||
|
||
def __repr__(self): | ||
return f"ModelOutput(metadata={self.metadata}, chosen={self.chosen}, candidates={self.candidates})" | ||
|
||
@property | ||
def text(self) -> str: | ||
return self.candidates[self.chosen].text | ||
|
||
@property | ||
def images(self) -> list[Image]: | ||
return self.candidates[self.chosen].images | ||
|
||
@property | ||
def rcid(self) -> str: | ||
return self.candidates[self.chosen].rcid |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.