From 54b8ed41c5d792afb773f1077c9c149a17369fc3 Mon Sep 17 00:00:00 2001 From: kgricour Date: Wed, 10 Jan 2024 15:54:54 +0100 Subject: [PATCH] improve AutoComplete components to split too long completion --- lib/components/AutoCompleteInput.tsx | 9 ++++++--- lib/components/AutoCompleteTextArea.tsx | 4 +++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/components/AutoCompleteInput.tsx b/lib/components/AutoCompleteInput.tsx index cc10012..fa0a25a 100644 --- a/lib/components/AutoCompleteInput.tsx +++ b/lib/components/AutoCompleteInput.tsx @@ -86,12 +86,15 @@ export function AutoCompleteInput(props: AutoCompleteInputProps): React.ReactEle Only answer with the prediction until the end of the sentence. Don't explain anything about the prediction. Don't repeat what the user said. - Complete from where the user stopped typing. - Just answer only one or two words (never more words).`; + Complete from where the user stopped typing.`; const generation = generate(prompt, { systemPrompt, autoComplete: true }); generationRef.current = generation; - setCompletion(await generation); + + const completion = await generation; + const limitedCompletion = completion.split(" ").slice(0, 5).join(" "); + + setCompletion(limitedCompletion); } catch (error) { console.error("Error generating completion:", error); } diff --git a/lib/components/AutoCompleteTextArea.tsx b/lib/components/AutoCompleteTextArea.tsx index 1fd2c84..6b1c21a 100644 --- a/lib/components/AutoCompleteTextArea.tsx +++ b/lib/components/AutoCompleteTextArea.tsx @@ -64,7 +64,9 @@ export function AutoCompleteTextArea({ }); setPreviousGeneration(generation); generation.then((text) => { - setCompletion({ text, position: caretPosition }); + const limitedCompletion = text.split(" ").slice(0, 15).join(" "); + + setCompletion({ text: limitedCompletion, position: caretPosition }); }); } }, 1000);