Skip to content

Commit 954ed4c

Browse files
connor4312sbatten
authored andcommitted
tools: enable replace_string in more models (#711)
1 parent ce4e103 commit 954ed4c

File tree

2 files changed

+39
-10
lines changed

2 files changed

+39
-10
lines changed

src/extension/intents/node/agentIntent.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { BudgetExceededError } from '@vscode/prompt-tsx/dist/base/materialized';
1010
import type * as vscode from 'vscode';
1111
import { ChatLocation, ChatResponse } from '../../../platform/chat/common/commonTypes';
1212
import { ConfigKey, IConfigurationService } from '../../../platform/configuration/common/configurationService';
13-
import { modelCanUseApplyPatchExclusively, modelCanUseReplaceStringExclusively, modelSupportsApplyPatch, modelSupportsMultiReplaceString, modelSupportsReplaceString } from '../../../platform/endpoint/common/chatModelCapabilities';
13+
import { isHiddenModelB, modelCanUseApplyPatchExclusively, modelCanUseReplaceStringExclusively, modelSupportsApplyPatch, modelSupportsMultiReplaceString, modelSupportsReplaceString } from '../../../platform/endpoint/common/chatModelCapabilities';
1414
import { IEndpointProvider } from '../../../platform/endpoint/common/endpointProvider';
1515
import { IEnvService } from '../../../platform/env/common/envService';
1616
import { ILogService } from '../../../platform/log/common/logService';
@@ -68,6 +68,24 @@ const getTools = (instaService: IInstantiationService, request: vscode.ChatReque
6868
allowTools[ToolName.EditFile] = false;
6969
}
7070

71+
if (await isHiddenModelB(model)) {
72+
const treatment = experimentationService.getTreatmentVariable<string>('vscode', 'copilotchat.hiddenModelBEditTool');
73+
switch (treatment) {
74+
case 'with_replace_string':
75+
allowTools[ToolName.ReplaceString] = true;
76+
allowTools[ToolName.EditFile] = true;
77+
break;
78+
case 'only_replace_string':
79+
allowTools[ToolName.ReplaceString] = true;
80+
allowTools[ToolName.EditFile] = false;
81+
break;
82+
case 'control':
83+
default:
84+
allowTools[ToolName.ReplaceString] = false;
85+
allowTools[ToolName.EditFile] = true;
86+
}
87+
}
88+
7189
if (modelCanUseReplaceStringExclusively(model)) {
7290
allowTools[ToolName.ReplaceString] = true;
7391
allowTools[ToolName.EditFile] = false;

src/platform/endpoint/common/chatModelCapabilities.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,30 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import type { LanguageModelChat } from 'vscode';
7+
import { encodeHex, VSBuffer } from '../../../util/vs/base/common/buffer';
78
import type { IChatEndpoint } from '../../networking/common/networking';
89

10+
const _cachedHashes = new Map<string, string>();
11+
12+
async function getSha256Hash(text: string): Promise<string> {
13+
if (_cachedHashes.has(text)) {
14+
return _cachedHashes.get(text)!;
15+
}
916

10-
function getSha256Hash(text: string): Promise<string> {
1117
const encoder = new TextEncoder();
1218
const data = encoder.encode(text);
13-
return crypto.subtle.digest('SHA-256', data).then(hashBuffer => {
14-
const hashArray = Array.from(new Uint8Array(hashBuffer));
15-
return hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
16-
});
19+
const hashBuffer = await crypto.subtle.digest('SHA-256', data);
20+
const hash = encodeHex(VSBuffer.wrap(new Uint8Array(hashBuffer)));
21+
_cachedHashes.set(text, hash);
22+
return hash;
23+
}
24+
25+
export async function isHiddenModelA(model: LanguageModelChat | IChatEndpoint) {
26+
return await getSha256Hash(model.family) === 'a99dd17dfee04155d863268596b7f6dd36d0a6531cd326348dbe7416142a21a3';
27+
}
28+
29+
export async function isHiddenModelB(model: LanguageModelChat | IChatEndpoint) {
30+
return await getSha256Hash(model.family) === '008ed1bfd28fb7f15ff17f6e308c417635da136603b83b32db4719bd1cd64c09';
1731
}
1832

1933
/**
@@ -36,10 +50,7 @@ export function modelPrefersInstructionsAfterHistory(modelFamily: string) {
3650
* Model supports apply_patch as an edit tool.
3751
*/
3852
export async function modelSupportsApplyPatch(model: LanguageModelChat | IChatEndpoint): Promise<boolean> {
39-
if (model.family === 'gpt-4.1' || model.family === 'o4-mini' || model.family.startsWith('gpt-5')) {
40-
return true;
41-
}
42-
return await getSha256Hash(model.family) === 'a99dd17dfee04155d863268596b7f6dd36d0a6531cd326348dbe7416142a21a3';
53+
return model.family === 'gpt-4.1' || model.family === 'o4-mini' || model.family.startsWith('gpt-5') || await isHiddenModelA(model);
4354
}
4455

4556
/**

0 commit comments

Comments
 (0)