summaryrefslogtreecommitdiff
path: root/packages/server/src/core/client.ts
diff options
context:
space:
mode:
authorTaylor Mullen <[email protected]>2025-05-12 23:23:24 -0700
committerN. Taylor Mullen <[email protected]>2025-05-12 23:33:12 -0700
commit3217576743bac0ebde0574170f110672de647819 (patch)
tree7d8ccf384df77cda96f0b849b297e463fec82af8 /packages/server/src/core/client.ts
parent5ec254253f1b7f4a74b8f107ac7a1f7e5c8cbb6f (diff)
feat: Enhance `replace` tool reliability with multi-stage edit correction
This commit significantly improves the `replace` tool's robustness by introducing a multi-stage correction mechanism. This directly addresses challenges with LLM-generated tool inputs, particularly the over-escaping of strings sometimes observed with Gemini models, and other minor discrepancies that previously led to failed edits. The correction process is as follows: 1. **Targeted Unescaping:** The system first applies a specialized unescaping function to the `old_string` and `new_string` to counteract common LLM-induced escaping patterns. 2. **LLM-Powered Discrepancy Resolution:** If a unique match for the `old_string` is still not found, the system leverages a Gemini model (`gemini-2.5-flash-preview-04-17`) to: * Identify the most probable intended `old_string` in the file by intelligently correcting minor formatting or escaping differences. * Adjust the `new_string` to correspond with any corrections made to the `old_string`, maintaining the original edit's intent. This enhancement makes the `replace` tool more resilient and effective, leading to a higher success rate for automated code modifications. The `expected_replacements` parameter has been removed as the tool now focuses on finding a single, unique, and correctable match. The tool's description and error reporting have been updated to reflect these new capabilities. Fixes https://b.corp.google.com/issues/416933027
Diffstat (limited to 'packages/server/src/core/client.ts')
-rw-r--r--packages/server/src/core/client.ts10
1 files changed, 8 insertions, 2 deletions
diff --git a/packages/server/src/core/client.ts b/packages/server/src/core/client.ts
index fc6080ab..3b5f7a99 100644
--- a/packages/server/src/core/client.ts
+++ b/packages/server/src/core/client.ts
@@ -193,12 +193,18 @@ export class GeminiClient {
async generateJson(
contents: Content[],
schema: SchemaUnion,
+ model: string = 'gemini-2.0-flash',
+ config: GenerateContentConfig = {},
): Promise<Record<string, unknown>> {
try {
+ const requestConfig = {
+ ...this.generateContentConfig,
+ ...config,
+ };
const result = await this.client.models.generateContent({
- model: 'gemini-2.0-flash',
+ model,
config: {
- ...this.generateContentConfig,
+ ...requestConfig,
systemInstruction: getCoreSystemPrompt(),
responseSchema: schema,
responseMimeType: 'application/json',