Skip to content

Commit

Permalink
feat: set max retries to 2 on APIError
Browse files Browse the repository at this point in the history
ref #21
  • Loading branch information
HanaokaYuzu committed Jun 18, 2024
1 parent 44fc762 commit e9b3f7c
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/gemini_webapi/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ async def start_auto_refresh(self) -> None:
self.cookies["__Secure-1PSIDTS"] = new_1psidts
await asyncio.sleep(self.refresh_interval)

@running(retry=1)
@running(retry=2)
async def generate_content(
self,
prompt: str,
Expand Down Expand Up @@ -344,13 +344,11 @@ async def generate_content(
body = json.loads(json.loads(response.text.split("\n")[2])[0][2])

if not body[4]:
# Request with extensions as middleware
# Request with Gemini extensions enabled
body = json.loads(json.loads(response.text.split("\n")[2])[4][2])

if not body[4]:
raise APIError(
"Failed to parse response body. Data structure is invalid. To report this error, please submit an issue at https://github.com/HanaokaYuzu/Gemini-API/issues"
)
raise Exception
except Exception:
await self.close()
raise APIError(
Expand Down Expand Up @@ -412,9 +410,9 @@ async def generate_content(
)

output = ModelOutput(metadata=body[1], candidates=candidates)
except IndexError:
except (TypeError, IndexError):
raise APIError(
"Failed to parse response body. Data structure is invalid. To report this error, please submit an issue at https://github.com/HanaokaYuzu/Gemini-API/issues"
"Failed to parse response body. Data structure is invalid."
)

if isinstance(chat, ChatSession):
Expand Down

0 comments on commit e9b3f7c

Please sign in to comment.