-
Notifications
You must be signed in to change notification settings - Fork 877
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. |
||
| 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, | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a known issue where windows have to be closed to equip items?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't seem to be a known issue in either the "issues" tab in this repo, nor in mineflayer. There are many other issues related to the window state that are already known, but this one is not stated anywhere that I could find. I simply hit this issue while testing the agent myself.