improv: preserve punctuation completions

This commit is contained in:
tomasz-io 2024-10-18 17:35:21 +07:00
parent d213b395c9
commit 50515b7fd8
3 changed files with 25 additions and 6 deletions

View file

@ -28,7 +28,7 @@ import {
constructAutocompletePrompt,
languageForFilepath,
} from "./constructPrompt.js";
import { isOnlyPunctuationAndWhitespace } from "./filter.js";
import { isOnlyWhitespace } from "./filter.js";
import { AutocompleteLanguageInfo } from "./languages.js";
import { postprocessCompletion } from "./postprocessing.js";
import { AutocompleteSnippet } from "./ranking.js";
@ -355,8 +355,12 @@ export class CompletionProvider {
return undefined;
}
// Filter out unwanted results
if (isOnlyPunctuationAndWhitespace(outcome.completion)) {
/**
* This check is most likely not needed because we do trim the LLM output
* elsewhere in the code. That said, I'm not yet confident enough to
* remove this.
*/
if (isOnlyWhitespace(outcome.completion)) {
return undefined;
}

View file

@ -1,4 +1,4 @@
export function isOnlyPunctuationAndWhitespace(completion: string): boolean {
const punctuationAndWhitespaceRegex = /^[^\w\d\}\)\]]+$/;
return punctuationAndWhitespaceRegex.test(completion);
export function isOnlyWhitespace(completion: string): boolean {
const whitespaceRegex = /^[\s]+$/;
return whitespaceRegex.test(completion);
}

View file

@ -0,0 +1,15 @@
import React from "react";
export const Button = ({
onClick,
children,
}: {
children: React.ReactNode;
onClick: () => void;
}) => {
return (
<button className="btn btn-primary" onClick={onClick}>
{children}
</button>
);
};