chore: migrate from responseSchema to use responseJsonSchema. (#4814)

This commit is contained in:
Wanlin Du 2025-08-11 16:04:58 -07:00 committed by GitHub
parent c7fd4c4a96
commit f52d073dfb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 28 additions and 36 deletions

View File

@ -22,7 +22,6 @@ import {
Part, Part,
SafetySetting, SafetySetting,
PartUnion, PartUnion,
SchemaUnion,
SpeechConfigUnion, SpeechConfigUnion,
ThinkingConfig, ThinkingConfig,
ToolListUnion, ToolListUnion,
@ -61,7 +60,7 @@ interface VertexGenerationConfig {
frequencyPenalty?: number; frequencyPenalty?: number;
seed?: number; seed?: number;
responseMimeType?: string; responseMimeType?: string;
responseSchema?: SchemaUnion; responseJsonSchema?: unknown;
routingConfig?: GenerationConfigRoutingConfig; routingConfig?: GenerationConfigRoutingConfig;
modelSelectionConfig?: ModelSelectionConfig; modelSelectionConfig?: ModelSelectionConfig;
responseModalities?: string[]; responseModalities?: string[];
@ -230,7 +229,7 @@ function toVertexGenerationConfig(
frequencyPenalty: config.frequencyPenalty, frequencyPenalty: config.frequencyPenalty,
seed: config.seed, seed: config.seed,
responseMimeType: config.responseMimeType, responseMimeType: config.responseMimeType,
responseSchema: config.responseSchema, responseJsonSchema: config.responseJsonSchema,
routingConfig: config.routingConfig, routingConfig: config.routingConfig,
modelSelectionConfig: config.modelSelectionConfig, modelSelectionConfig: config.modelSelectionConfig,
responseModalities: config.responseModalities, responseModalities: config.responseModalities,

View File

@ -396,7 +396,7 @@ describe('Gemini Client (client.ts)', () => {
systemInstruction: getCoreSystemPrompt(''), systemInstruction: getCoreSystemPrompt(''),
temperature: 0, temperature: 0,
topP: 1, topP: 1,
responseSchema: schema, responseJsonSchema: schema,
responseMimeType: 'application/json', responseMimeType: 'application/json',
}, },
contents, contents,
@ -435,7 +435,7 @@ describe('Gemini Client (client.ts)', () => {
temperature: 0.9, temperature: 0.9,
topP: 1, // from default topP: 1, // from default
topK: 20, topK: 20,
responseSchema: schema, responseJsonSchema: schema,
responseMimeType: 'application/json', responseMimeType: 'application/json',
}, },
contents, contents,

View File

@ -7,7 +7,6 @@
import { import {
EmbedContentParameters, EmbedContentParameters,
GenerateContentConfig, GenerateContentConfig,
SchemaUnion,
PartListUnion, PartListUnion,
Content, Content,
Tool, Tool,
@ -515,7 +514,7 @@ export class GeminiClient {
async generateJson( async generateJson(
contents: Content[], contents: Content[],
schema: SchemaUnion, schema: Record<string, unknown>,
abortSignal: AbortSignal, abortSignal: AbortSignal,
model?: string, model?: string,
config: GenerateContentConfig = {}, config: GenerateContentConfig = {},
@ -539,7 +538,7 @@ export class GeminiClient {
config: { config: {
...requestConfig, ...requestConfig,
systemInstruction, systemInstruction,
responseSchema: schema, responseJsonSchema: schema,
responseMimeType: 'application/json', responseMimeType: 'application/json',
}, },
contents, contents,

View File

@ -9,7 +9,6 @@ import { GeminiEventType, ServerGeminiStreamEvent } from '../core/turn.js';
import { logLoopDetected } from '../telemetry/loggers.js'; import { logLoopDetected } from '../telemetry/loggers.js';
import { LoopDetectedEvent, LoopType } from '../telemetry/types.js'; import { LoopDetectedEvent, LoopType } from '../telemetry/types.js';
import { Config, DEFAULT_GEMINI_FLASH_MODEL } from '../config/config.js'; import { Config, DEFAULT_GEMINI_FLASH_MODEL } from '../config/config.js';
import { SchemaUnion, Type } from '@google/genai';
const TOOL_CALL_LOOP_THRESHOLD = 5; const TOOL_CALL_LOOP_THRESHOLD = 5;
const CONTENT_LOOP_THRESHOLD = 10; const CONTENT_LOOP_THRESHOLD = 10;
@ -341,16 +340,16 @@ Please analyze the conversation history to determine the possibility that the co
...recentHistory, ...recentHistory,
{ role: 'user', parts: [{ text: prompt }] }, { role: 'user', parts: [{ text: prompt }] },
]; ];
const schema: SchemaUnion = { const schema: Record<string, unknown> = {
type: Type.OBJECT, type: 'object',
properties: { properties: {
reasoning: { reasoning: {
type: Type.STRING, type: 'string',
description: description:
'Your reasoning on if the conversation is looping without forward progress.', 'Your reasoning on if the conversation is looping without forward progress.',
}, },
confidence: { confidence: {
type: Type.NUMBER, type: 'number',
description: description:
'A number between 0.0 and 1.0 representing your confidence that the conversation is in an unproductive state.', 'A number between 0.0 and 1.0 representing your confidence that the conversation is in an unproductive state.',
}, },

View File

@ -4,12 +4,7 @@
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
import { import { Content, GenerateContentConfig } from '@google/genai';
Content,
GenerateContentConfig,
SchemaUnion,
Type,
} from '@google/genai';
import { GeminiClient } from '../core/client.js'; import { GeminiClient } from '../core/client.js';
import { EditToolParams, EditTool } from '../tools/edit.js'; import { EditToolParams, EditTool } from '../tools/edit.js';
import { WriteFileTool } from '../tools/write-file.js'; import { WriteFileTool } from '../tools/write-file.js';
@ -364,11 +359,11 @@ export async function ensureCorrectFileContent(
} }
// Define the expected JSON schema for the LLM response for old_string correction // Define the expected JSON schema for the LLM response for old_string correction
const OLD_STRING_CORRECTION_SCHEMA: SchemaUnion = { const OLD_STRING_CORRECTION_SCHEMA: Record<string, unknown> = {
type: Type.OBJECT, type: 'object',
properties: { properties: {
corrected_target_snippet: { corrected_target_snippet: {
type: Type.STRING, type: 'string',
description: description:
'The corrected version of the target snippet that exactly and uniquely matches a segment within the provided file content.', 'The corrected version of the target snippet that exactly and uniquely matches a segment within the provided file content.',
}, },
@ -438,11 +433,11 @@ Return ONLY the corrected target snippet in the specified JSON format with the k
} }
// Define the expected JSON schema for the new_string correction LLM response // Define the expected JSON schema for the new_string correction LLM response
const NEW_STRING_CORRECTION_SCHEMA: SchemaUnion = { const NEW_STRING_CORRECTION_SCHEMA: Record<string, unknown> = {
type: Type.OBJECT, type: 'object',
properties: { properties: {
corrected_new_string: { corrected_new_string: {
type: Type.STRING, type: 'string',
description: description:
'The original_new_string adjusted to be a suitable replacement for the corrected_old_string, while maintaining the original intent of the change.', 'The original_new_string adjusted to be a suitable replacement for the corrected_old_string, while maintaining the original intent of the change.',
}, },
@ -521,11 +516,11 @@ Return ONLY the corrected string in the specified JSON format with the key 'corr
} }
} }
const CORRECT_NEW_STRING_ESCAPING_SCHEMA: SchemaUnion = { const CORRECT_NEW_STRING_ESCAPING_SCHEMA: Record<string, unknown> = {
type: Type.OBJECT, type: 'object',
properties: { properties: {
corrected_new_string_escaping: { corrected_new_string_escaping: {
type: Type.STRING, type: 'string',
description: description:
'The new_string with corrected escaping, ensuring it is a proper replacement for the old_string, especially considering potential over-escaping issues from previous LLM generations.', 'The new_string with corrected escaping, ensuring it is a proper replacement for the old_string, especially considering potential over-escaping issues from previous LLM generations.',
}, },
@ -593,11 +588,11 @@ Return ONLY the corrected string in the specified JSON format with the key 'corr
} }
} }
const CORRECT_STRING_ESCAPING_SCHEMA: SchemaUnion = { const CORRECT_STRING_ESCAPING_SCHEMA: Record<string, unknown> = {
type: Type.OBJECT, type: 'object',
properties: { properties: {
corrected_string_escaping: { corrected_string_escaping: {
type: Type.STRING, type: 'string',
description: description:
'The string with corrected escaping, ensuring it is valid, specially considering potential over-escaping issues from previous LLM generations.', 'The string with corrected escaping, ensuring it is valid, specially considering potential over-escaping issues from previous LLM generations.',
}, },

View File

@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
import { Content, SchemaUnion, Type } from '@google/genai'; import { Content } from '@google/genai';
import { DEFAULT_GEMINI_FLASH_MODEL } from '../config/models.js'; import { DEFAULT_GEMINI_FLASH_MODEL } from '../config/models.js';
import { GeminiClient } from '../core/client.js'; import { GeminiClient } from '../core/client.js';
import { GeminiChat } from '../core/geminiChat.js'; import { GeminiChat } from '../core/geminiChat.js';
@ -16,16 +16,16 @@ const CHECK_PROMPT = `Analyze *only* the content and structure of your immediate
2. **Question to User:** If your last response ends with a direct question specifically addressed *to the user*, then the **'user'** should speak next. 2. **Question to User:** If your last response ends with a direct question specifically addressed *to the user*, then the **'user'** should speak next.
3. **Waiting for User:** If your last response completed a thought, statement, or task *and* does not meet the criteria for Rule 1 (Model Continues) or Rule 2 (Question to User), it implies a pause expecting user input or reaction. In this case, the **'user'** should speak next.`; 3. **Waiting for User:** If your last response completed a thought, statement, or task *and* does not meet the criteria for Rule 1 (Model Continues) or Rule 2 (Question to User), it implies a pause expecting user input or reaction. In this case, the **'user'** should speak next.`;
const RESPONSE_SCHEMA: SchemaUnion = { const RESPONSE_SCHEMA: Record<string, unknown> = {
type: Type.OBJECT, type: 'object',
properties: { properties: {
reasoning: { reasoning: {
type: Type.STRING, type: 'string',
description: description:
"Brief explanation justifying the 'next_speaker' choice based *strictly* on the applicable rule and the content/structure of the preceding turn.", "Brief explanation justifying the 'next_speaker' choice based *strictly* on the applicable rule and the content/structure of the preceding turn.",
}, },
next_speaker: { next_speaker: {
type: Type.STRING, type: 'string',
enum: ['user', 'model'], enum: ['user', 'model'],
description: description:
'Who should speak next based *only* on the preceding turn and the decision rules', 'Who should speak next based *only* on the preceding turn and the decision rules',