From 58372bd8beb7c721ef1d5823a84a87e32b4cf723 Mon Sep 17 00:00:00 2001 From: Zhiming Ma Date: Fri, 27 Oct 2023 18:51:44 +0800 Subject: [PATCH] feat(agent): add experimental option: strip auto-closing chars in prompt suffix. --- clients/tabby-agent/src/AgentConfig.ts | 2 ++ clients/tabby-agent/src/TabbyAgent.ts | 12 ++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/clients/tabby-agent/src/AgentConfig.ts b/clients/tabby-agent/src/AgentConfig.ts index b227b75e90a0..d92f7015a9a7 100644 --- a/clients/tabby-agent/src/AgentConfig.ts +++ b/clients/tabby-agent/src/AgentConfig.ts @@ -8,6 +8,7 @@ export type AgentConfig = { }; completion: { prompt: { + stripAutoClosingCharacters: boolean; maxPrefixLines: number; maxSuffixLines: number; }; @@ -46,6 +47,7 @@ export const defaultAgentConfig: AgentConfig = { }, completion: { prompt: { + stripAutoClosingCharacters: false, maxPrefixLines: 20, maxSuffixLines: 20, }, diff --git a/clients/tabby-agent/src/TabbyAgent.ts b/clients/tabby-agent/src/TabbyAgent.ts index 081a7847cfd3..6bb96e872928 100644 --- a/clients/tabby-agent/src/TabbyAgent.ts +++ b/clients/tabby-agent/src/TabbyAgent.ts @@ -264,10 +264,14 @@ export class TabbyAgent extends EventEmitter implements Agent { const maxPrefixLines = this.config.completion.prompt.maxPrefixLines; const maxSuffixLines = this.config.completion.prompt.maxSuffixLines; const { prefixLines, suffixLines } = context; - return { - prefix: prefixLines.slice(Math.max(prefixLines.length - maxPrefixLines, 0)).join(""), - suffix: suffixLines.slice(0, maxSuffixLines).join(""), - }; + const prefix = prefixLines.slice(Math.max(prefixLines.length - maxPrefixLines, 0)).join(""); + let suffix; + if (this.config.completion.prompt.stripAutoClosingCharacters && context.mode !== "fill-in-line") { + suffix = "\n" + suffixLines.slice(1, maxSuffixLines).join(""); + } else { + suffix = suffixLines.slice(0, maxSuffixLines).join(""); + } + return { prefix, suffix }; } private calculateReplaceRange(response: CompletionResponse, context: CompletionContext): CompletionResponse {