mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-30 23:14:32 -07:00
feat: Implement retry with backoff for API calls (#613)
This commit is contained in:
@@ -10,6 +10,7 @@ import { BaseTool, ToolResult } from './tools.js';
|
||||
import { getErrorMessage } from '../utils/errors.js';
|
||||
import { Config } from '../config/config.js';
|
||||
import { getResponseText } from '../utils/generateContentResponseUtilities.js';
|
||||
import { retryWithBackoff } from '../utils/retry.js';
|
||||
|
||||
// Interfaces for grounding metadata (similar to web-search.ts)
|
||||
interface GroundingChunkWeb {
|
||||
@@ -121,18 +122,21 @@ export class WebFetchTool extends BaseTool<WebFetchToolParams, ToolResult> {
|
||||
const userPrompt = params.prompt;
|
||||
|
||||
try {
|
||||
const response = await this.ai.models.generateContent({
|
||||
model: this.modelName,
|
||||
contents: [
|
||||
{
|
||||
role: 'user',
|
||||
parts: [{ text: userPrompt }],
|
||||
const apiCall = () =>
|
||||
this.ai.models.generateContent({
|
||||
model: this.modelName,
|
||||
contents: [
|
||||
{
|
||||
role: 'user',
|
||||
parts: [{ text: userPrompt }],
|
||||
},
|
||||
],
|
||||
config: {
|
||||
tools: [{ urlContext: {} }],
|
||||
},
|
||||
],
|
||||
config: {
|
||||
tools: [{ urlContext: {} }],
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
const response = await retryWithBackoff(apiCall);
|
||||
|
||||
console.debug(
|
||||
`[WebFetchTool] Full response for prompt "${userPrompt.substring(0, 50)}...":`,
|
||||
|
||||
@@ -11,6 +11,7 @@ import { SchemaValidator } from '../utils/schemaValidator.js';
|
||||
import { getErrorMessage } from '../utils/errors.js';
|
||||
import { Config } from '../config/config.js';
|
||||
import { getResponseText } from '../utils/generateContentResponseUtilities.js';
|
||||
import { retryWithBackoff } from '../utils/retry.js';
|
||||
|
||||
interface GroundingChunkWeb {
|
||||
uri?: string;
|
||||
@@ -121,13 +122,16 @@ export class WebSearchTool extends BaseTool<
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await this.ai.models.generateContent({
|
||||
model: this.modelName,
|
||||
contents: [{ role: 'user', parts: [{ text: params.query }] }],
|
||||
config: {
|
||||
tools: [{ googleSearch: {} }],
|
||||
},
|
||||
});
|
||||
const apiCall = () =>
|
||||
this.ai.models.generateContent({
|
||||
model: this.modelName,
|
||||
contents: [{ role: 'user', parts: [{ text: params.query }] }],
|
||||
config: {
|
||||
tools: [{ googleSearch: {} }],
|
||||
},
|
||||
});
|
||||
|
||||
const response = await retryWithBackoff(apiCall);
|
||||
|
||||
const responseText = getResponseText(response);
|
||||
const groundingMetadata = response.candidates?.[0]?.groundingMetadata;
|
||||
|
||||
Reference in New Issue
Block a user