From 53a89698391a8da5b7f909489b889d4398039947 Mon Sep 17 00:00:00 2001 From: hitesh-1997 Date: Fri, 31 Jan 2025 20:15:15 +0530 Subject: [PATCH 1/3] fix(auto-edit): fix the false notification for auto-edit non eligibility --- .../autoedits/create-autoedits-provider.ts | 55 ++++++++++++++++++- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/vscode/src/autoedits/create-autoedits-provider.ts b/vscode/src/autoedits/create-autoedits-provider.ts index d78e867a5831..09929fb6936e 100644 --- a/vscode/src/autoedits/create-autoedits-provider.ts +++ b/vscode/src/autoedits/create-autoedits-provider.ts @@ -102,13 +102,28 @@ export function createAutoEditsProvider({ ) } +/** + * Displays an error notification to the user about non-eligibility for auto edits, + * but only if the user is currently in the Settings view (to avoid spamming them). + * + * This is because because of the flaky network issues we could evaluate the default feature flag value to false + * and show the non eligibility notification to the user even if they have access to the feature. + * Generally the users should see the notification only when they manully change the vscode config which could be either + * through the settings UI or `settings.json` file. + * + * @param {string | undefined} nonEligibilityReason - The reason why the user is currently not eligible + * for auto edits. If not provided, no notification occurs. + */ export async function handleAutoeditsNotificationForNonEligibleUser( nonEligibilityReason?: string ): Promise { - const switchToAutocompleteText = 'Switch to autocomplete' + if (!nonEligibilityReason || !isSettingsEditorOpen()) { + return + } + const switchToAutocompleteText = 'Switch to autocomplete' const selection = await vscode.window.showErrorMessage( - `Error: ${nonEligibilityReason ?? AUTOEDITS_NON_ELIGIBILITY_MESSAGES.FEATURE_FLAG_NOT_ELIGIBLE}`, + `Error: ${nonEligibilityReason}`, switchToAutocompleteText ) if (selection === switchToAutocompleteText) { @@ -122,6 +137,42 @@ export async function handleAutoeditsNotificationForNonEligibleUser( } } +/** + * Checks whether the current view in VS Code is the Settings editor (JSON or UI). + * + * This function performs two checks: + * 1. Detect if the active text editor points to a known settings file (e.g., settings.json, settings.jsonc). + * 2. If there's no text editor open, examine the "Tab" label to see if it's the built-in Settings UI. + * + * Note: Using the tab's label is locale-specific; if a user runs VS Code in a non-English locale, + * or if the label changes in future VS Code versions, this heuristic may fail. + * + * @returns {boolean} True if the user is most likely viewing the Settings editor (JSON or UI), false otherwise. + */ +function isSettingsEditorOpen(): boolean { + const activeEditor = vscode.window.activeTextEditor + + // 1) If there's an active text editor, check if the file name matches typical settings files + if (activeEditor) { + const fsPath = activeEditor.document.uri.fsPath + if (fsPath.endsWith('settings.json') || fsPath.endsWith('settings.jsonc')) { + return true + } + return false + } + + // 2) If there's no activeTextEditor, the user might be in the graphical Settings UI or have no editor at all + const activeTab = vscode.window.tabGroups.activeTabGroup?.activeTab + if (!activeTab) { + // No tab at all: definitely not a JSON settings file; + // could be just an empty Editor area, Start page, or something else + return false + } + + // The built-in Settings UI tab typically has the label "Settings" (in English). + return activeTab.label === 'Settings' +} + export function isUserEligibleForAutoeditsFeature( autoeditsFeatureFlagEnabled: boolean, authStatus: AuthStatus, From 76c29211037066b77be2caf1857b5878130a14e6 Mon Sep 17 00:00:00 2001 From: Hitesh Sagtani Date: Fri, 31 Jan 2025 20:43:42 +0530 Subject: [PATCH 2/3] Revert "fix(auto-edit): fix temperature value to be low for output consistency" (#6900) Reverts sourcegraph/cody#6853 ## Test plan CI --- vscode/src/autoedits/adapters/cody-gateway.test.ts | 4 ++-- vscode/src/autoedits/adapters/cody-gateway.ts | 2 +- vscode/src/autoedits/adapters/fireworks.test.ts | 4 ++-- vscode/src/autoedits/adapters/fireworks.ts | 2 +- vscode/src/autoedits/adapters/sourcegraph-chat.test.ts | 2 +- vscode/src/autoedits/adapters/sourcegraph-chat.ts | 2 +- vscode/src/autoedits/adapters/sourcegraph-completions.test.ts | 2 +- vscode/src/autoedits/adapters/sourcegraph-completions.ts | 2 +- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/vscode/src/autoedits/adapters/cody-gateway.test.ts b/vscode/src/autoedits/adapters/cody-gateway.test.ts index 39bd6e79039d..09a2a3f011a9 100644 --- a/vscode/src/autoedits/adapters/cody-gateway.test.ts +++ b/vscode/src/autoedits/adapters/cody-gateway.test.ts @@ -72,7 +72,7 @@ describe('CodyGatewayAdapter', () => { expect.objectContaining({ stream: false, model: options.model, - temperature: 0.001, + temperature: 0.1, response_format: { type: 'text' }, prediction: { type: 'content', @@ -100,7 +100,7 @@ describe('CodyGatewayAdapter', () => { expect.objectContaining({ stream: false, model: options.model, - temperature: 0.001, + temperature: 0.1, response_format: { type: 'text' }, prediction: { type: 'content', diff --git a/vscode/src/autoedits/adapters/cody-gateway.ts b/vscode/src/autoedits/adapters/cody-gateway.ts index 199051ac882c..badc8b584b9d 100644 --- a/vscode/src/autoedits/adapters/cody-gateway.ts +++ b/vscode/src/autoedits/adapters/cody-gateway.ts @@ -46,7 +46,7 @@ export class CodyGatewayAdapter implements AutoeditsModelAdapter { const body: FireworksCompatibleRequestParams = { stream: false, model: options.model, - temperature: 0.001, + temperature: 0.1, max_tokens: maxTokens, response_format: { type: 'text', diff --git a/vscode/src/autoedits/adapters/fireworks.test.ts b/vscode/src/autoedits/adapters/fireworks.test.ts index 49b99d6400ac..0e51c0e5cc58 100644 --- a/vscode/src/autoedits/adapters/fireworks.test.ts +++ b/vscode/src/autoedits/adapters/fireworks.test.ts @@ -64,7 +64,7 @@ describe('FireworksAdapter', () => { expect.objectContaining({ stream: false, model: options.model, - temperature: 0.001, + temperature: 0.1, max_tokens: expect.any(Number), response_format: { type: 'text' }, prediction: { @@ -92,7 +92,7 @@ describe('FireworksAdapter', () => { expect.objectContaining({ stream: false, model: options.model, - temperature: 0.001, + temperature: 0.1, max_tokens: expect.any(Number), response_format: { type: 'text' }, prediction: { diff --git a/vscode/src/autoedits/adapters/fireworks.ts b/vscode/src/autoedits/adapters/fireworks.ts index 5fe74d8bb429..f9da3d07318f 100644 --- a/vscode/src/autoedits/adapters/fireworks.ts +++ b/vscode/src/autoedits/adapters/fireworks.ts @@ -40,7 +40,7 @@ export class FireworksAdapter implements AutoeditsModelAdapter { const body: FireworksCompatibleRequestParams = { stream: false, model: options.model, - temperature: 0.001, + temperature: 0.1, max_tokens: maxTokens, response_format: { type: 'text', diff --git a/vscode/src/autoedits/adapters/sourcegraph-chat.test.ts b/vscode/src/autoedits/adapters/sourcegraph-chat.test.ts index ff220648b127..23a4030b8c88 100644 --- a/vscode/src/autoedits/adapters/sourcegraph-chat.test.ts +++ b/vscode/src/autoedits/adapters/sourcegraph-chat.test.ts @@ -64,7 +64,7 @@ describe('SourcegraphChatAdapter', () => { expect(chatOptions).toMatchObject({ model: 'anthropic/claude-2', maxTokensToSample: getMaxOutputTokensForAutoedits(options.codeToRewrite), - temperature: 0.001, + temperature: 0.1, prediction: { type: 'content', content: 'const x = 1', diff --git a/vscode/src/autoedits/adapters/sourcegraph-chat.ts b/vscode/src/autoedits/adapters/sourcegraph-chat.ts index 106c14682285..2d231aa20ad4 100644 --- a/vscode/src/autoedits/adapters/sourcegraph-chat.ts +++ b/vscode/src/autoedits/adapters/sourcegraph-chat.ts @@ -18,7 +18,7 @@ export class SourcegraphChatAdapter implements AutoeditsModelAdapter { { model: option.model, maxTokensToSample: maxTokens, - temperature: 0.001, + temperature: 0.1, prediction: { type: 'content', content: option.codeToRewrite, diff --git a/vscode/src/autoedits/adapters/sourcegraph-completions.test.ts b/vscode/src/autoedits/adapters/sourcegraph-completions.test.ts index 746d92db7904..1a37a4b7d525 100644 --- a/vscode/src/autoedits/adapters/sourcegraph-completions.test.ts +++ b/vscode/src/autoedits/adapters/sourcegraph-completions.test.ts @@ -57,7 +57,7 @@ describe('SourcegraphCompletionsAdapter', () => { expect(params).toMatchObject({ model: 'anthropic/claude-2', maxTokensToSample: getMaxOutputTokensForAutoedits(options.codeToRewrite), - temperature: 0.001, + temperature: 0.1, messages: [{ speaker: 'human', text: ps`user message` }], prediction: { type: 'content', diff --git a/vscode/src/autoedits/adapters/sourcegraph-completions.ts b/vscode/src/autoedits/adapters/sourcegraph-completions.ts index f2b2fb6a4d20..ffd09d92a978 100644 --- a/vscode/src/autoedits/adapters/sourcegraph-completions.ts +++ b/vscode/src/autoedits/adapters/sourcegraph-completions.ts @@ -28,7 +28,7 @@ export class SourcegraphCompletionsAdapter implements AutoeditsModelAdapter { model: option.model as ModelRefStr, messages, maxTokensToSample: maxTokens, - temperature: 0.001, + temperature: 0.1, prediction: { type: 'content', content: option.codeToRewrite, From 0c1927e483f68caf90adcdee4fa24c549a19df5f Mon Sep 17 00:00:00 2001 From: hitesh-1997 Date: Fri, 31 Jan 2025 20:45:04 +0530 Subject: [PATCH 3/3] address pr comments --- vscode/src/autoedits/create-autoedits-provider.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vscode/src/autoedits/create-autoedits-provider.ts b/vscode/src/autoedits/create-autoedits-provider.ts index 09929fb6936e..fd5754c4676e 100644 --- a/vscode/src/autoedits/create-autoedits-provider.ts +++ b/vscode/src/autoedits/create-autoedits-provider.ts @@ -108,7 +108,7 @@ export function createAutoEditsProvider({ * * This is because because of the flaky network issues we could evaluate the default feature flag value to false * and show the non eligibility notification to the user even if they have access to the feature. - * Generally the users should see the notification only when they manully change the vscode config which could be either + * Generally the users should see the notification only when they manually change the vscode config which could be either * through the settings UI or `settings.json` file. * * @param {string | undefined} nonEligibilityReason - The reason why the user is currently not eligible