[PR #220] [MERGED] Add streaming responses, enhance parsing efficiency, and implement a better retry solution. #221

Closed
opened 2026-02-13 17:28:08 -06:00 by mirrors · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/HanaokaYuzu/Gemini-API/pull/220
Author: @luuquangvu
Created: 1/28/2026
Status: Merged
Merged: 2/3/2026
Merged by: @HanaokaYuzu

Base: masterHead: improve-parsing-efficiency


📝 Commits (10+)

  • 1b5ad5d Refactor: improve nested value retrieval and enhance JSON parsing functions
  • 01e1007 Refactor: remove unnecessary verification flag from AsyncClient initialization
  • f9a8581 Refactor: enhance cookie rotation logic and add verbose logging option
  • d477ca0 Refactor: enhance cookie refresh handling and enable concurrent file uploads
  • 76f3327 Refactor: improve cookie and access token refresh logic with enhanced locking mechanism
  • 0d963da Refactor: improve JSON response handling and enhance nested value extraction in GemMixin
  • 117fd4e Refactor: enhance cookie refresh logic with improved error handling and concurrency
  • 731b199 Refactor: update model headers
  • eb85ec9 Revert "Refactor: update model headers"
  • 3f3cf9a Refactor: enable HTTP/2 support in AsyncClient across multiple modules

📊 Changes

15 files changed (+1148 additions, -504 deletions)

View changed files

📝 README.md (+5 -5)
📝 pyproject.toml (+3 -3)
📝 src/gemini_webapi/client.py (+644 -306)
📝 src/gemini_webapi/components/gem_mixin.py (+35 -20)
📝 src/gemini_webapi/constants.py (+11 -8)
📝 src/gemini_webapi/types/candidate.py (+2 -0)
📝 src/gemini_webapi/types/image.py (+8 -7)
📝 src/gemini_webapi/types/modeloutput.py (+8 -0)
📝 src/gemini_webapi/utils/__init__.py (+1 -6)
📝 src/gemini_webapi/utils/decorators.py (+75 -30)
📝 src/gemini_webapi/utils/get_access_token.py (+55 -34)
📝 src/gemini_webapi/utils/parsing.py (+207 -37)
📝 src/gemini_webapi/utils/rotate_1psidts.py (+40 -21)
📝 src/gemini_webapi/utils/upload_file.py (+51 -24)
📝 tests/test_client_features.py (+3 -3)

📄 Description

Here's a quick summary of the changes, sorry if this PR turned out a bit larger than expected.

  • Added streaming responses, inspired by the idea from #170. Big thanks to @faithleysath ! Now supports both streaming and non-streaming modes.
  • Rewrote the JSON parsing logic, inspired by the idea from #213. Huge thanks to @ww2283 ! The parsing logic is now working very reliably.
  • Implement logic to wait for a response and follow up with the question whenever the model is in a thinking or waiting state, or when the token is invalidated, without initiating a new request.
  • Refactor get_nested_value to reduce usage overhead.
  • Refactor the running decorator to use a backoff strategy and support both regular async functions and async generators.
  • Modify upload_file to handle a wider variety of file types.
  • Update get_access_token to include additional required parameters in its return value.
  • Update start_auto_refresh to renew the access_token whenever cookies are renewed.
  • Adjust the request parameters to align with the actual request.
  • Separate the file upload process from the retry logic.
  • Switch to HTTP/2 for a more realistic web client simulation.
  • Remove the AsyncClient option verify=False to prevent MITM attacks.
  • Update gem_mixin to make use of the parsing utility.
  • Update the model header and user-agent to the latest version.

I tested it and it worked fine for me, but I'd really appreciate it if someone else could try it out to catch any potential issues.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/HanaokaYuzu/Gemini-API/pull/220 **Author:** [@luuquangvu](https://github.com/luuquangvu) **Created:** 1/28/2026 **Status:** ✅ Merged **Merged:** 2/3/2026 **Merged by:** [@HanaokaYuzu](https://github.com/HanaokaYuzu) **Base:** `master` ← **Head:** `improve-parsing-efficiency` --- ### 📝 Commits (10+) - [`1b5ad5d`](https://github.com/HanaokaYuzu/Gemini-API/commit/1b5ad5d8628f1e813d76c972d6795a20168ed25b) Refactor: improve nested value retrieval and enhance JSON parsing functions - [`01e1007`](https://github.com/HanaokaYuzu/Gemini-API/commit/01e1007b5b430ea239d234b6f506c29d32211877) Refactor: remove unnecessary verification flag from AsyncClient initialization - [`f9a8581`](https://github.com/HanaokaYuzu/Gemini-API/commit/f9a8581064785dd20fe9d4d3045c90677bd5dbfc) Refactor: enhance cookie rotation logic and add verbose logging option - [`d477ca0`](https://github.com/HanaokaYuzu/Gemini-API/commit/d477ca05db558038002306e1de78eef809949c4a) Refactor: enhance cookie refresh handling and enable concurrent file uploads - [`76f3327`](https://github.com/HanaokaYuzu/Gemini-API/commit/76f3327ef239b839887fa127f93e6c56d3937d24) Refactor: improve cookie and access token refresh logic with enhanced locking mechanism - [`0d963da`](https://github.com/HanaokaYuzu/Gemini-API/commit/0d963da817875876c8dd7eeaa30360f0236d7c4c) Refactor: improve JSON response handling and enhance nested value extraction in GemMixin - [`117fd4e`](https://github.com/HanaokaYuzu/Gemini-API/commit/117fd4ef3d420d172e623e27b809d729edcee359) Refactor: enhance cookie refresh logic with improved error handling and concurrency - [`731b199`](https://github.com/HanaokaYuzu/Gemini-API/commit/731b19995829c3daa5e93949bce3e17c7bff460f) Refactor: update model headers - [`eb85ec9`](https://github.com/HanaokaYuzu/Gemini-API/commit/eb85ec9c2f70c1a3931c28ea39855bd9f24ff1d0) Revert "Refactor: update model headers" - [`3f3cf9a`](https://github.com/HanaokaYuzu/Gemini-API/commit/3f3cf9a3a94fdf152bf1cc739ab83cde9698b68a) Refactor: enable HTTP/2 support in AsyncClient across multiple modules ### 📊 Changes **15 files changed** (+1148 additions, -504 deletions) <details> <summary>View changed files</summary> 📝 `README.md` (+5 -5) 📝 `pyproject.toml` (+3 -3) 📝 `src/gemini_webapi/client.py` (+644 -306) 📝 `src/gemini_webapi/components/gem_mixin.py` (+35 -20) 📝 `src/gemini_webapi/constants.py` (+11 -8) 📝 `src/gemini_webapi/types/candidate.py` (+2 -0) 📝 `src/gemini_webapi/types/image.py` (+8 -7) 📝 `src/gemini_webapi/types/modeloutput.py` (+8 -0) 📝 `src/gemini_webapi/utils/__init__.py` (+1 -6) 📝 `src/gemini_webapi/utils/decorators.py` (+75 -30) 📝 `src/gemini_webapi/utils/get_access_token.py` (+55 -34) 📝 `src/gemini_webapi/utils/parsing.py` (+207 -37) 📝 `src/gemini_webapi/utils/rotate_1psidts.py` (+40 -21) 📝 `src/gemini_webapi/utils/upload_file.py` (+51 -24) 📝 `tests/test_client_features.py` (+3 -3) </details> ### 📄 Description Here's a quick summary of the changes, sorry if this PR turned out a bit larger than expected. - Added streaming responses, inspired by the idea from #170. Big thanks to @faithleysath ! Now supports both streaming and non-streaming modes. - Rewrote the JSON parsing logic, inspired by the idea from #213. Huge thanks to @ww2283 ! The parsing logic is now working very reliably. - Implement logic to wait for a response and follow up with the question whenever the model is in a thinking or waiting state, or when the token is invalidated, without initiating a new request. - Refactor get_nested_value to reduce usage overhead. - Refactor the running decorator to use a backoff strategy and support both regular async functions and async generators. - Modify upload_file to handle a wider variety of file types. - Update get_access_token to include additional required parameters in its return value. - Update start_auto_refresh to renew the access_token whenever cookies are renewed. - Adjust the request parameters to align with the actual request. - Separate the file upload process from the retry logic. - Switch to HTTP/2 for a more realistic web client simulation. - Remove the AsyncClient option verify=False to prevent MITM attacks. - Update gem_mixin to make use of the parsing utility. - Update the model header and user-agent to the latest version. I tested it and it worked fine for me, but I'd really appreciate it if someone else could try it out to catch any potential issues. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
mirrors 2026-02-13 17:28:08 -06:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
mirrors/Gemini-API#221
No description provided.