-
Notifications
You must be signed in to change notification settings - Fork 892
fix: retry on Gemini API errors and handle equip error while a window is open #794
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,20 +46,38 @@ export class Gemini { | |
| }); | ||
| } | ||
|
|
||
| const result = await this.genAI.models.generateContent({ | ||
| model: this.model_name || "gemini-2.5-flash", | ||
| contents: contents, | ||
| safetySettings: this.safetySettings, | ||
| config: { | ||
| systemInstruction: systemMessage, | ||
| ...(this.params || {}) | ||
|
|
||
| const MAX_RETRIES = 5; | ||
| const RETRY_DELAY = 5000; | ||
|
|
||
| for (let attempt = 0; attempt < MAX_RETRIES; attempt++) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IIRC no other providers have a built-in retry system. Does this need to be implemented specifically for Gemini? Or should there be a separate retry system at another layer for all providers?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm sorry, but I only tested this with Gemini, and thus I can't really tell you whether or not this should be at another layer for all providers.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hello, just following up on this, but does this answer your question?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mm yea but i feel like we probably don't need a retry system or we could make it for example if an error is 404/401/403/400 then don't retry, only retry on 529/502/server errors and it probably best to have retry system across all providers |
||
| try { | ||
| const result = await this.genAI.models.generateContent({ | ||
| model: this.model_name || "gemini-2.5-flash", | ||
| contents: contents, | ||
| safetySettings: this.safetySettings, | ||
| config: { | ||
| systemInstruction: systemMessage, | ||
| ...(this.params || {}) | ||
| } | ||
| }); | ||
| const response = await result.text; | ||
| if (!response) { | ||
| console.warn(`Gemini returned empty response, retrying in ${RETRY_DELAY/1000}s... (attempt ${attempt + 1}/${MAX_RETRIES})`); | ||
| await new Promise(r => setTimeout(r, RETRY_DELAY)); | ||
| continue; | ||
| } | ||
| console.log('Received.'); | ||
| return response; | ||
| } catch (err) { | ||
| if (attempt < MAX_RETRIES - 1 && (err.status === 503 || err.status === 429)) { | ||
| console.warn(`Google API error ${err.status}, retrying in ${RETRY_DELAY/1000}s... (attempt ${attempt + 1}/${MAX_RETRIES})`); | ||
| await new Promise(r => setTimeout(r, RETRY_DELAY)); | ||
| } else { | ||
| throw err; | ||
| } | ||
| } | ||
| }); | ||
| const response = await result.text; | ||
|
|
||
| console.log('Received.'); | ||
|
|
||
| return response; | ||
| } | ||
| } | ||
|
|
||
| async sendVisionRequest(turns, systemMessage, imageBuffer) { | ||
|
|
@@ -173,4 +191,4 @@ function createWavHeader(dataLength, sampleRate, channels, bitsPerSample) { | |
|
|
||
| export const TTSConfig = { | ||
| sendAudioRequest: sendAudioRequest, | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.