mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-19 09:33:53 +00:00
Prevent console.warn's for tool calls.
- Added helper for extracting text content from responses without warning. See fixed issue for more detail: https://b.corp.google.com/issues/414005146
This commit is contained in:
committed by
N. Taylor Mullen
parent
d051c0fd0f
commit
aa65a4a1fc
@@ -20,6 +20,7 @@ import { Turn, ServerGeminiStreamEvent } from './turn.js';
|
|||||||
import { Config } from '../config/config.js';
|
import { Config } from '../config/config.js';
|
||||||
import { getCoreSystemPrompt } from './prompts.js';
|
import { getCoreSystemPrompt } from './prompts.js';
|
||||||
import { ReadManyFilesTool } from '../tools/read-many-files.js'; // Import ReadManyFilesTool
|
import { ReadManyFilesTool } from '../tools/read-many-files.js'; // Import ReadManyFilesTool
|
||||||
|
import { getResponseText } from '../utils/generateContentResponseUtilities.js';
|
||||||
|
|
||||||
export class GeminiClient {
|
export class GeminiClient {
|
||||||
private config: Config;
|
private config: Config;
|
||||||
@@ -185,13 +186,14 @@ export class GeminiClient {
|
|||||||
},
|
},
|
||||||
contents,
|
contents,
|
||||||
});
|
});
|
||||||
if (!result || !result.text) {
|
const text = getResponseText(result);
|
||||||
|
if (!text) {
|
||||||
throw new Error('API returned an empty response.');
|
throw new Error('API returned an empty response.');
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
return JSON.parse(result.text);
|
return JSON.parse(text);
|
||||||
} catch (parseError) {
|
} catch (parseError) {
|
||||||
console.error('Failed to parse JSON response:', result.text);
|
console.error('Failed to parse JSON response:', text);
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Failed to parse API response as JSON: ${parseError instanceof Error ? parseError.message : String(parseError)}`,
|
`Failed to parse API response as JSON: ${parseError instanceof Error ? parseError.message : String(parseError)}`,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import {
|
|||||||
ToolResult,
|
ToolResult,
|
||||||
ToolResultDisplay,
|
ToolResultDisplay,
|
||||||
} from '../tools/tools.js'; // Keep ToolResult for now
|
} from '../tools/tools.js'; // Keep ToolResult for now
|
||||||
|
import { getResponseText } from '../utils/generateContentResponseUtilities.js';
|
||||||
// Removed gemini-stream import (types defined locally)
|
// Removed gemini-stream import (types defined locally)
|
||||||
|
|
||||||
// --- Types for Server Logic ---
|
// --- Types for Server Logic ---
|
||||||
@@ -102,7 +103,6 @@ export class Turn {
|
|||||||
this.confirmationDetails = [];
|
this.confirmationDetails = [];
|
||||||
this.debugResponses = [];
|
this.debugResponses = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
// The run method yields simpler events suitable for server logic
|
// The run method yields simpler events suitable for server logic
|
||||||
async *run(
|
async *run(
|
||||||
req: PartListUnion,
|
req: PartListUnion,
|
||||||
@@ -115,10 +115,12 @@ export class Turn {
|
|||||||
if (signal?.aborted) {
|
if (signal?.aborted) {
|
||||||
throw this.abortError();
|
throw this.abortError();
|
||||||
}
|
}
|
||||||
if (resp.text) {
|
|
||||||
yield { type: GeminiEventType.Content, value: resp.text };
|
const text = getResponseText(resp);
|
||||||
continue;
|
if (text) {
|
||||||
|
yield { type: GeminiEventType.Content, value: text };
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!resp.functionCalls) {
|
if (!resp.functionCalls) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
/**
|
||||||
|
* @license
|
||||||
|
* Copyright 2025 Google LLC
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { GenerateContentResponse } from '@google/genai';
|
||||||
|
|
||||||
|
export function getResponseText(
|
||||||
|
response: GenerateContentResponse,
|
||||||
|
): string | undefined {
|
||||||
|
return (
|
||||||
|
response.candidates?.[0]?.content?.parts
|
||||||
|
?.map((part) => part.text)
|
||||||
|
.join('') || undefined
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user