From c68f9b25d6b760fa5acc8f00adb2068690d5f144 Mon Sep 17 00:00:00 2001 From: Amit Joshi Date: Wed, 16 Apr 2025 15:56:17 +0530 Subject: [PATCH] Refactor token size handling in PowerPagesCopilot and copilot.js --- src/common/copilot/PowerPagesCopilot.ts | 8 ++------ src/common/copilot/assets/scripts/copilot.js | 5 ----- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/src/common/copilot/PowerPagesCopilot.ts b/src/common/copilot/PowerPagesCopilot.ts index 351a8ce08..e511a2fe1 100644 --- a/src/common/copilot/PowerPagesCopilot.ts +++ b/src/common/copilot/PowerPagesCopilot.ts @@ -17,7 +17,7 @@ import { ActiveOrgOutput } from "../../client/pac/PacTypes"; import { CopilotWalkthroughEvent, CopilotCopyCodeToClipboardEvent, CopilotInsertCodeToEditorEvent, CopilotLoadedEvent, CopilotOrgChangedEvent, CopilotUserFeedbackThumbsDownEvent, CopilotUserFeedbackThumbsUpEvent, CopilotUserPromptedEvent, CopilotCodeLineCountEvent, CopilotClearChatEvent, CopilotExplainCode, CopilotExplainCodeSize, CopilotNotAvailableECSConfig, CopilotPanelTryGitHubCopilotClicked, VSCodeExtensionGitHubChatPanelOpened, VSCodeExtensionGitHubChatNotFound } from "./telemetry/telemetryConstants"; import { sendTelemetryEvent } from "./telemetry/copilotTelemetry"; import { getEntityColumns, getEntityName, getFormXml } from "./dataverseMetadata"; -import { isWithinTokenLimit, encode } from "gpt-tokenizer"; +import { encode } from "gpt-tokenizer"; import { orgChangeErrorEvent, orgChangeEvent } from "../../client/OrgChangeNotifier"; import { getDisabledOrgList, getDisabledTenantList } from "./utils/copilotUtil"; import { INTELLIGENCE_SCOPE_DEFAULT, PROVIDER_ID } from "../services/Constants"; @@ -84,15 +84,11 @@ export class PowerPagesCopilot implements vscode.WebviewViewProvider { vscode.window.showInformationMessage(vscode.l10n.t('Selection is empty.')); return; } - const withinTokenLimit = isWithinTokenLimit(selectedCode, 1000); if (commandType === EXPLAIN_CODE) { const tokenSize = encode(selectedCode).length; sendTelemetryEvent({ eventName: CopilotExplainCodeSize, copilotSessionId: sessionID, orgId: orgID, userId: userID, codeLineCount: String(selectedCodeLineRange.end - selectedCodeLineRange.start), tokenSize: String(tokenSize) }); - if (withinTokenLimit === false) { - return; - } } - this.sendMessageToWebview({ type: commandType, value: { start: selectedCodeLineRange.start, end: selectedCodeLineRange.end, selectedCode: selectedCode, tokenSize: withinTokenLimit } }); + this.sendMessageToWebview({ type: commandType, value: { start: selectedCodeLineRange.start, end: selectedCodeLineRange.end, selectedCode: selectedCode} }); }; this._disposables.push( diff --git a/src/common/copilot/assets/scripts/copilot.js b/src/common/copilot/assets/scripts/copilot.js index 89e923bf6..f06f18508 100644 --- a/src/common/copilot/assets/scripts/copilot.js +++ b/src/common/copilot/assets/scripts/copilot.js @@ -551,11 +551,6 @@ break; } chatInputLabel.classList.remove("hide"); - if (message.value.tokenSize === false) { - chatInputLabel.innerText = copilotStrings.LARGE_SELECTION; - selectedCode = ""; - break; - } chatInputLabel.innerText = `Lines ${message.value.start + 1} - ${message.value.end + 1} selected`; break; }