Skip to content

Commit

Permalink
style: format docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
HanaokaYuzu committed Jul 30, 2024
1 parent 86605f2 commit eb92274
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/gemini_webapi/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ async def init(
verbose: `bool`, optional
If `True`, will print more infomation in logs.
"""

try:
access_token, valid_cookies = await get_access_token(
base_cookies=self.cookies, proxies=self.proxies, verbose=verbose
Expand Down Expand Up @@ -210,6 +211,7 @@ async def close(self, delay: float = 0) -> None:
delay: `float`, optional
Time to wait before closing the client in seconds.
"""

if delay:
await asyncio.sleep(delay)

Expand All @@ -226,6 +228,7 @@ async def reset_close_task(self) -> None:
"""
Reset the timer for closing the client when a new request is made.
"""

if self.close_task:
self.close_task.cancel()
self.close_task = None
Expand All @@ -235,6 +238,7 @@ async def start_auto_refresh(self) -> None:
"""
Start the background task to automatically refresh cookies.
"""

while True:
try:
new_1psidts = await rotate_1psidts(self.cookies, self.proxies)
Expand Down Expand Up @@ -287,6 +291,7 @@ async def generate_content(
- If request failed with status code other than 200.
- If response structure is invalid and failed to parse.
"""

assert prompt, "Prompt cannot be empty."

if self.auto_close:
Expand Down Expand Up @@ -434,6 +439,7 @@ def start_chat(self, **kwargs) -> "ChatSession":
:class:`ChatSession`
Empty chat object for retrieving conversation history.
"""

return ChatSession(geminiclient=self, **kwargs)


Expand Down Expand Up @@ -524,6 +530,7 @@ async def send_message(
- If request failed with status code other than 200.
- If response structure is invalid and failed to parse.
"""

return await self.geminiclient.generate_content(
prompt=prompt, images=images, chat=self
)
Expand All @@ -547,6 +554,7 @@ def choose_candidate(self, index: int) -> ModelOutput:
`ValueError`
If no previous output data found in this chat session, or if index exceeds the number of candidates in last model output.
"""

if not self.last_output:
raise ValueError("No previous output data found in this chat session.")

Expand Down
2 changes: 2 additions & 0 deletions src/gemini_webapi/types/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ async def save(
`httpx.HTTPError`
If the network request failed.
"""

filename = filename or self.url.split("/")[-1].split("?")[0]
try:
filename = re.search(r"^(.*\.\w+)", filename).group()
Expand Down Expand Up @@ -153,6 +154,7 @@ async def save(self, **kwargs) -> str | None:
`str | None`
Absolute path of the saved image if successfully saved.
"""

return await super().save(
filename=kwargs.pop("filename", None)
or f"{datetime.now().strftime('%Y%m%d%H%M%S')}_{self.url[-10:]}.png",
Expand Down
1 change: 1 addition & 0 deletions src/gemini_webapi/utils/load_browser_cookies.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def load_browser_cookies(domain_name: str = "", verbose=True) -> dict:
`dict`
Dictionary with cookie name as key and cookie value as value.
"""

import browser_cookie3 as bc3

cookies = {}
Expand Down
1 change: 1 addition & 0 deletions src/gemini_webapi/utils/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def set_log_level(level: str):
level : str
The log level to set. Must be one of "DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL".
"""

assert level in ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]

logger.remove()
Expand Down

0 comments on commit eb92274

Please sign in to comment.