| 1 | import { CompletionOptions } from "../.."; |
| 2 | import { AutocompleteLanguageInfo } from "../constants/AutocompleteLanguageInfo"; |
| 3 | |
| 4 | const DOUBLE_NEWLINE = "\n\n"; |
| 5 | const WINDOWS_DOUBLE_NEWLINE = "\r\n\r\n"; |
| 6 | // TODO: Do we want to stop completions when reaching a `/src/` string? |
| 7 | const SRC_DIRECTORY = "/src/"; |
| 8 | // Starcoder2 tends to output artifacts starting with the letter "t" |
| 9 | const STARCODER2_T_ARTIFACTS = ["t.", "\nt", "<file_sep>"]; |
| 10 | const PYTHON_ENCODING = "#- coding: utf-8"; |
| 11 | const CODE_BLOCK_END = "```"; |
| 12 | |
| 13 | // const multilineStops: string[] = [DOUBLE_NEWLINE, WINDOWS_DOUBLE_NEWLINE]; |
| 14 | const commonStops = [SRC_DIRECTORY, PYTHON_ENCODING, CODE_BLOCK_END]; |
| 15 | |
| 16 | export function getStopTokens( |
| 17 | completionOptions: Partial<CompletionOptions> | undefined, |
| 18 | lang: AutocompleteLanguageInfo, |
| 19 | model: string, |
| 20 | ): string[] { |
| 21 | const stopTokens = [ |
| 22 | ...(completionOptions?.stop || []), |
| 23 | // ...multilineStops, |
| 24 | ...commonStops, |
| 25 | ...(model.toLowerCase().includes("starcoder2") |
| 26 | ? STARCODER2_T_ARTIFACTS |
| 27 | : []), |
| 28 | // ...lang.topLevelKeywords.map((word) => `\n${word}`), |
| 29 | ]; |
| 30 | |
| 31 | return stopTokens; |
| 32 | } |