Skip to content

Commit

Permalink
tweak prompt and save input to localstorage
Browse files Browse the repository at this point in the history
Signed-off-by: Yulong Ruan <[email protected]>
  • Loading branch information
ruanyl committed May 20, 2024
1 parent 5ffaf3c commit e1df0ed
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
1 change: 0 additions & 1 deletion src/plugins/vis_type_vega/public/text_to_vega.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ ${ppl}
The user's instruction is: ${input}
You seem not quite understand how to set y-scales of the different layers, the correct syntax is {"resolve": {"scale": {"y": "independent"}}} please use it when appropriate.
Just return the chart specification json based on Vega-Lite format.
Just reply with the json based Vega-Lite object, do not include any other content in the reply.
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,18 @@ const TopNav = ({
const [isPopoverOpen, setIsPopoverOpen] = useState(false);
const inputRef = useRef<HTMLInputElement>(null);

const onValueChange = useCallback((value: string) => {
setValue(value);
localStorage.setItem('text_to_vega_input', value);
}, []);

useEffect(() => {
const input = localStorage.getItem('text_to_vega_input');
if (input) {
setValue(input);
}
}, []);

useEffect(() => {
window['llmRunning$'].subscribe((running) => {
setGenerating(!!running);
Expand Down Expand Up @@ -265,7 +277,7 @@ const TopNav = ({
value={value}
prepend={<EuiIcon type={chatLogo} />}
fullWidth
onChange={(event) => setValue(event.target.value)}
onChange={(event) => onValueChange(event.target.value)}
onKeyDown={(e) => {
if (e.key === 'Enter') onGenerate();
}}
Expand All @@ -282,7 +294,7 @@ const TopNav = ({
{HARDCODED_SUGGESTIONS?.map((question) => (
<EuiListGroupItem
onClick={() => {
setValue(question);
onValueChange(question);
inputRef.current?.focus();
setIsPopoverOpen(false);
}}
Expand Down

0 comments on commit e1df0ed

Please sign in to comment.