-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Started to collapse prompt management to single tab * Restructure for single prompts tab * Rework flex into prompt structure * Remove old tabbed options * Remove crufty error message, bring in templates for 0.14.17 / 0.15.1, fixes a prompt override problem
- Loading branch information
1 parent
b170ec4
commit aa6d575
Showing
18 changed files
with
446 additions
and
466 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,257 @@ | ||
|
||
import React from 'react'; | ||
|
||
import { Typography, Box, Stack, Button } from '@mui/material'; | ||
import { TextField } from '@mui/material'; | ||
import { List, ListItemButton, ListItemText } from '@mui/material'; | ||
import { ListItemIcon } from '@mui/material'; | ||
import { ChatBubble, Add, Delete } from '@mui/icons-material'; | ||
|
||
import Prompt from '../options/Prompt'; | ||
import { usePromptsStore } from '../state/Prompts'; | ||
|
||
import SystemPromptHelp from './help/SystemPrompt'; | ||
import ExtractDefinitionsPromptHelp from './help/ExtractDefinitionsPrompt'; | ||
import ExtractRelationshipsPromptHelp from './help/ExtractRelationshipsPrompt'; | ||
import ExtractTopicsPromptHelp from './help/ExtractTopicsPrompt'; | ||
import ExtractRowsPromptHelp from './help/ExtractRowsPrompt'; | ||
import KnowledgeQueryPromptHelp from './help/KnowledgeQueryPrompt'; | ||
import DocumentQueryPromptHelp from './help/DocumentQueryPrompt'; | ||
|
||
const ConfigurePrompts = ({ | ||
}) => { | ||
|
||
const prompts = usePromptsStore((state) => state.prompts); | ||
|
||
const setPrompts | ||
= usePromptsStore((state) => state.setPrompts); | ||
|
||
const helps : { [key : string] : React.ReactNode } = { | ||
"system-template": <SystemPromptHelp/>, | ||
"extract-definitions": <ExtractDefinitionsPromptHelp/>, | ||
"extract-relationships": <ExtractRelationshipsPromptHelp/>, | ||
"extract-topics": <ExtractTopicsPromptHelp/>, | ||
"extract-rows": <ExtractRowsPromptHelp/>, | ||
"kg-prompt": <KnowledgeQueryPromptHelp/>, | ||
"document-prompt": <DocumentQueryPromptHelp/>, | ||
}; | ||
|
||
const [selected, setSelected] = React.useState(prompts[0].id); | ||
|
||
let prompt : any = null; | ||
for (let p of prompts) { | ||
if (p.id == selected) prompt = p; | ||
} | ||
|
||
const handleSelect = ( | ||
_event: React.MouseEvent<HTMLDivElement, MouseEvent>, | ||
id: string, | ||
) => { | ||
setSelected(id); | ||
}; | ||
|
||
const addPrompt = () => { | ||
|
||
const count = prompts.length; | ||
const newId = "custom-prompt-" + (count + 1).toString(); | ||
|
||
const newPrompt = { | ||
id: newId, | ||
name: "Custom prompt " + (count + 1).toString(), | ||
prompt: "", | ||
custom: true, | ||
}; | ||
|
||
setPrompts([...prompts, newPrompt]); | ||
setSelected(newId); | ||
|
||
}; | ||
|
||
const deletePrompt = () => { | ||
|
||
const newPrompts = prompts.filter(p => (p.id != selected)); | ||
|
||
setPrompts(newPrompts); | ||
setSelected(newPrompts[0].id); | ||
|
||
}; | ||
|
||
const onChange = (newVal : string) => { | ||
const newPrompts = prompts.map( | ||
p => { | ||
if (p.id == selected) { | ||
const newP = { | ||
...p, | ||
prompt: newVal, | ||
}; | ||
return newP; | ||
} else { | ||
return p; | ||
} | ||
} | ||
); | ||
setPrompts(newPrompts); | ||
}; | ||
|
||
const setId = (newVal : string) => { | ||
const newPrompts = prompts.map( | ||
p => { | ||
if (p.id == selected) { | ||
const newP = { | ||
...p, | ||
id: newVal, | ||
}; | ||
return newP; | ||
} else { | ||
return p; | ||
} | ||
} | ||
); | ||
setPrompts(newPrompts); | ||
|
||
// Have to change ID to point to the new changed ID | ||
setSelected(newVal); | ||
}; | ||
|
||
const setName = (newVal : string) => { | ||
const newPrompts = prompts.map( | ||
p => { | ||
if (p.id == selected) { | ||
const newP = { | ||
...p, | ||
name: newVal, | ||
}; | ||
return newP; | ||
} else { | ||
return p; | ||
} | ||
} | ||
); | ||
setPrompts(newPrompts); | ||
}; | ||
|
||
return (<> | ||
|
||
<Stack direction="row" spacing={2}> | ||
|
||
<Box> | ||
|
||
<Typography variant="h5" component="h2" gutterBottom> | ||
Configure Prompts | ||
</Typography> | ||
|
||
<List component="nav" aria-label="prompts"> | ||
|
||
{ | ||
prompts.map( | ||
p => { | ||
return ( | ||
<ListItemButton | ||
key={p.id} | ||
selected={selected == p.id} | ||
onClick={(event) => | ||
handleSelect(event, p.id) | ||
} | ||
> | ||
<ListItemIcon> | ||
<ChatBubble/> | ||
</ListItemIcon> | ||
<ListItemText primary={p.name}/> | ||
</ListItemButton> | ||
); | ||
} | ||
) | ||
} | ||
</List> | ||
|
||
<Box> | ||
|
||
<Button | ||
startIcon={<Add/>} | ||
variant="contained" | ||
onClick={ addPrompt } | ||
> | ||
Add prompt | ||
</Button> | ||
|
||
</Box> | ||
|
||
</Box> | ||
|
||
<Stack | ||
direction="column" spacing={2} | ||
> | ||
|
||
<Typography | ||
variant="h5" component="h2" gutterBottom | ||
> | ||
{ prompt.name } | ||
</Typography> | ||
|
||
{ | ||
(helps[selected]) && | ||
<Box> | ||
{ helps[selected] } | ||
</Box> | ||
} | ||
|
||
{ | ||
prompt.custom && ( | ||
<Box> | ||
<TextField | ||
fullWidth | ||
label="ID" | ||
value={prompt.id} | ||
onChange={ | ||
(event: React.ChangeEvent<HTMLInputElement>) => { | ||
setId(event.target.value); | ||
} | ||
} | ||
margin="normal" | ||
/> | ||
<TextField | ||
fullWidth | ||
label="Name" | ||
value={prompt.name} | ||
onChange={ | ||
(event: React.ChangeEvent<HTMLInputElement>) => { | ||
setName(event.target.value); | ||
} | ||
} | ||
margin="normal" | ||
/> | ||
</Box> | ||
) | ||
} | ||
|
||
<Box> | ||
<Prompt | ||
value={prompt.prompt} | ||
onChange={onChange} | ||
/> | ||
</Box> | ||
|
||
<Box> | ||
|
||
{ | ||
prompt.custom && | ||
<Button | ||
startIcon={<Delete/>} | ||
variant="contained" | ||
onClick={ deletePrompt } | ||
> | ||
Delete this prompt | ||
</Button> | ||
} | ||
|
||
</Box> | ||
|
||
</Stack> | ||
|
||
</Stack> | ||
|
||
</>); | ||
}; | ||
|
||
export default ConfigurePrompts; | ||
|
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.