Skip to content

Commit

Permalink
improve AutoComplete components to split too long completion
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-btc committed Jan 10, 2024
1 parent d76dd8a commit 54b8ed4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 6 additions & 3 deletions lib/components/AutoCompleteInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 3 additions & 1 deletion lib/components/AutoCompleteTextArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 54b8ed4

Please sign in to comment.