Skip to content

Commit

Permalink
feat(agent): add experimental option: strip auto-closing chars in pro…
Browse files Browse the repository at this point in the history
…mpt suffix.
  • Loading branch information
icycodes committed Oct 27, 2023
1 parent d6c1324 commit 58372bd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 2 additions & 0 deletions clients/tabby-agent/src/AgentConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export type AgentConfig = {
};
completion: {
prompt: {
stripAutoClosingCharacters: boolean;
maxPrefixLines: number;
maxSuffixLines: number;
};
Expand Down Expand Up @@ -46,6 +47,7 @@ export const defaultAgentConfig: AgentConfig = {
},
completion: {
prompt: {
stripAutoClosingCharacters: false,
maxPrefixLines: 20,
maxSuffixLines: 20,
},
Expand Down
12 changes: 8 additions & 4 deletions clients/tabby-agent/src/TabbyAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 58372bd

Please sign in to comment.