Skip to content

Commit

Permalink
Simplify prompts (#46)
Browse files Browse the repository at this point in the history
* 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
cybermaggedon authored Nov 10, 2024
1 parent b170ec4 commit aa6d575
Show file tree
Hide file tree
Showing 18 changed files with 446 additions and 466 deletions.
68 changes: 8 additions & 60 deletions src/simple-editor/configuration/Configuration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,11 @@ import { Box, Tabs, Tab } from '@mui/material';

import { usePromptsStore } from '../state/Prompts';
import {
useOptionsStore, SYSTEM_PROMPT, DEFINITIONS_PROMPT, RELATIONSHIPS_PROMPT,
TOPICS_PROMPT, KNOWLEDGE_QUERY_PROMPT, DOCUMENT_QUERY_PROMPT,
ROWS_PROMPT,
useOptionsStore, CONFIGURE_PROMPTS,
} from '../state/Options';
import { useDeploymentStore } from '../state/Deployment';

import SystemPrompt from './SystemPrompt';
import DefinitionsPrompt from './DefinitionsPrompt';
import RelationshipsPrompt from './RelationshipsPrompt';
import TopicsPrompt from './TopicsPrompt';
import KnowledgeQueryPrompt from './KnowledgeQueryPrompt';
import DocumentQueryPrompt from './DocumentQueryPrompt';
import RowsPrompt from './RowsPrompt';
import ConfigurePrompts from './ConfigurePrompts';
import Additional from './Additional';
import GenerateDeployment from './GenerateDeployment';
import Parameters from './Parameters';
Expand Down Expand Up @@ -51,30 +43,10 @@ const tabs = (opts : Set<string>) => {
<Tab key="more" value="more" label="Customization 🧰"/>
];

if (opts.has(SYSTEM_PROMPT))
tabs.push(<Tab key="sys" value="sys" label="System Prompt"/>);

if (opts.has(DEFINITIONS_PROMPT))
tabs.push(<Tab key="defs" value="defs" label="Entity Definitions Prompt"/>);

if (opts.has(RELATIONSHIPS_PROMPT))
tabs.push(<Tab key="rels" value="rels" label="Relationships Prompt"/>);

if (opts.has(TOPICS_PROMPT))
tabs.push(<Tab key="topics" value="topics" label="Topic Prompt"/>);

if (opts.has(KNOWLEDGE_QUERY_PROMPT))
tabs.push(<Tab key="kgq" value="kgq" label="Knowledge Graph Prompt"/>);

if (opts.has(DOCUMENT_QUERY_PROMPT))
tabs.push(<Tab key="docq" value="docq"
label="Document Query Prompt"
/>);

if (opts.has(ROWS_PROMPT))
tabs.push(<Tab key="rows" value="rows"
label="Rows Prompt"
/>);
if (opts.has(CONFIGURE_PROMPTS))
tabs.push(
<Tab key="prompts" value="prompts" label="Configure Prompts"/>
);

tabs.push(<Tab key="depl" value="depl" label="Finish Deployment 🚀"/>);

Expand Down Expand Up @@ -123,32 +95,8 @@ const Configuration: React.FC = () => {
<Additional/>
</CustomTabPanel>

<CustomTabPanel value={value} tabId="sys">
<SystemPrompt/>
</CustomTabPanel>

<CustomTabPanel value={value} tabId="defs">
<DefinitionsPrompt/>
</CustomTabPanel>

<CustomTabPanel value={value} tabId="rels">
<RelationshipsPrompt/>
</CustomTabPanel>

<CustomTabPanel value={value} tabId="topics">
<TopicsPrompt/>
</CustomTabPanel>

<CustomTabPanel value={value} tabId="kgq">
<KnowledgeQueryPrompt/>
</CustomTabPanel>

<CustomTabPanel value={value} tabId="docq">
<DocumentQueryPrompt/>
</CustomTabPanel>

<CustomTabPanel value={value} tabId="rows">
<RowsPrompt/>
<CustomTabPanel value={value} tabId="prompts">
<ConfigurePrompts/>
</CustomTabPanel>

<CustomTabPanel value={value} tabId="depl">
Expand Down
257 changes: 257 additions & 0 deletions src/simple-editor/configuration/ConfigurePrompts.tsx
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;

32 changes: 0 additions & 32 deletions src/simple-editor/configuration/DocumentQueryPrompt.tsx

This file was deleted.

Loading

0 comments on commit aa6d575

Please sign in to comment.