Skip to content

Commit 20cac7d

Browse files
committed
allow creation of chat formatted prompts -- not handled by inference layer yet
1 parent 68b615c commit 20cac7d

File tree

3 files changed

+89
-53
lines changed

3 files changed

+89
-53
lines changed

src/renderer/components/Experiment/Interact/Batched/Batched.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ function ListOfBatchedQueries({ sendBatchOfQueries }) {
231231
<IconButton onClick={() => sendBatchOfQueries(query?.prompts)}>
232232
<PlayIcon size="20px" />
233233
</IconButton>{' '}
234-
<IconButton onClick={() => alert('not implemented')}>
234+
<IconButton disabled onClick={() => alert('not implemented')}>
235235
<PencilIcon size="20px" />{' '}
236236
</IconButton>
237237
<IconButton

src/renderer/components/Experiment/Interact/Batched/NewBatchPromptModal.tsx

Lines changed: 86 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import NewChatForm from './NewChatForm';
3737

3838
import * as chatAPI from '../../../../lib/transformerlab-api-sdk';
3939
import { IoCloudUploadOutline } from 'react-icons/io5';
40+
import { Form } from 'react-router-dom';
4041

4142
export default function NewBatchModal({ open, setOpen, addQuery }) {
4243
const [prompts, setPrompts] = useState<string[]>(['']);
@@ -75,12 +76,17 @@ export default function NewBatchModal({ open, setOpen, addQuery }) {
7576
setUploading(false);
7677
};
7778

79+
function closeWindow() {
80+
setOpen(false);
81+
setTypeOfBatch('');
82+
setPrompts(['']);
83+
}
84+
7885
return (
7986
<Modal
8087
open={open}
8188
onClose={() => {
82-
setOpen(false);
83-
setTypeOfBatch('');
89+
closeWindow();
8490
}}
8591
>
8692
<>
@@ -144,8 +150,7 @@ export default function NewBatchModal({ open, setOpen, addQuery }) {
144150
prompts,
145151
};
146152
await addQuery(newQuery);
147-
setPrompts(['']);
148-
setOpen(false);
153+
closeWindow();
149154
}}
150155
>
151156
<FormControl>
@@ -212,7 +217,17 @@ export default function NewBatchModal({ open, setOpen, addQuery }) {
212217
)}
213218
{typeOfBatch === 'chat' && (
214219
<ModalDialog sx={{}}>
215-
<ListOfChats />
220+
<ListOfChats
221+
save={(chatName, chats) => {
222+
// convert chats from a list of objects, to a list of strings:
223+
const newChats = chats.map((chat) => JSON.stringify(chat));
224+
addQuery({
225+
name: chatName,
226+
prompts: newChats,
227+
});
228+
closeWindow();
229+
}}
230+
/>
216231
</ModalDialog>
217232
)}
218233
{typeOfBatch === 'file' && (
@@ -307,11 +322,12 @@ export default function NewBatchModal({ open, setOpen, addQuery }) {
307322
);
308323
}
309324

310-
function ListOfChats({}) {
325+
function ListOfChats({ save }) {
311326
const [chats, setChats] = useState([]);
312327
// set editChat to -1 if you want to create a new chat, set it a specific index in the chats
313328
// array if you want to edit that chat. Set it to null if you are not editing
314329
const [editChat, setEditChat] = useState<number | null>(null);
330+
const [chatName, setChatName] = useState('');
315331
return (
316332
<>
317333
<DialogTitle>
@@ -337,48 +353,70 @@ function ListOfChats({}) {
337353
/>
338354
) : (
339355
<>
340-
{chats.length === 0 && (
341-
<Typography level="body-md" color="neutral">
342-
List of Chats is Empty
343-
</Typography>
344-
)}
345-
<List>
346-
{chats.map((chat, index) => (
347-
<ListItem key={index}>
348-
<ListItemDecorator>
349-
<MessageSquareTextIcon />
350-
</ListItemDecorator>
351-
<ListItemContent sx={{ overflow: 'clip' }}>
352-
{JSON.stringify(chat)}
353-
</ListItemContent>
354-
<ButtonGroup>
355-
<Button
356-
variant="plain"
357-
onClick={() => {
358-
setEditChat(index);
359-
}}
360-
>
361-
<PencilIcon size="18px" />
362-
</Button>
363-
<Button
364-
variant="plain"
365-
onClick={() => {
366-
const newChats = [...chats];
367-
newChats.splice(index, 1);
368-
setChats(newChats);
369-
}}
370-
>
371-
<Trash2Icon size="18px" />
372-
</Button>
373-
</ButtonGroup>
374-
</ListItem>
375-
))}
376-
</List>
377-
<Button variant="soft" onClick={() => setEditChat(-1)}>
378-
Add New
379-
</Button>
380-
{/* <Button onClick={() => setChats([])}>Clear</Button> */}
381-
<Button onClick={() => console.log(chats)}>Save</Button>
356+
<form
357+
onSubmit={(event: React.FormEvent<HTMLFormElement>) => {
358+
event.preventDefault();
359+
save(chatName, chats);
360+
}}
361+
style={{ display: 'flex', flexDirection: 'column', gap: 2 }}
362+
>
363+
<FormControl>
364+
<FormLabel>Chat Name</FormLabel>
365+
<Input
366+
required
367+
value={chatName}
368+
onChange={(event) => setChatName(event.target.value)}
369+
size="lg"
370+
placeholder="e.g. Common Knowledge Prompts"
371+
/>
372+
</FormControl>
373+
<FormControl>
374+
<FormLabel>Chats:</FormLabel>
375+
{chats.length === 0 && (
376+
<Typography level="body-md" color="neutral">
377+
List of Chats is Empty
378+
</Typography>
379+
)}
380+
<List>
381+
{chats.map((chat, index) => (
382+
<ListItem key={index}>
383+
<ListItemDecorator>
384+
<MessageSquareTextIcon />
385+
</ListItemDecorator>
386+
<ListItemContent sx={{ overflow: 'clip' }}>
387+
{JSON.stringify(chat)}
388+
</ListItemContent>
389+
<ButtonGroup>
390+
<Button
391+
variant="plain"
392+
onClick={() => {
393+
setEditChat(index);
394+
}}
395+
>
396+
<PencilIcon size="18px" />
397+
</Button>
398+
<Button
399+
variant="plain"
400+
onClick={() => {
401+
const newChats = [...chats];
402+
newChats.splice(index, 1);
403+
setChats(newChats);
404+
}}
405+
>
406+
<Trash2Icon size="18px" />
407+
</Button>
408+
</ButtonGroup>
409+
</ListItem>
410+
))}
411+
</List>
412+
</FormControl>
413+
414+
<Button variant="soft" onClick={() => setEditChat(-1)}>
415+
Add New
416+
</Button>
417+
{/* <Button onClick={() => setChats([])}>Clear</Button> */}
418+
<Button type="submit">Save Chats</Button>
419+
</form>
382420
</>
383421
)}
384422
</>

src/renderer/components/Experiment/Interact/Batched/NewChatForm.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@ export default function NewChatForm({ submitChat, defaultChats = [] }) {
1717
const [chats, setChats] = useState([
1818
{ role: 'system', content: 'You are a helpful assistant.' },
1919
{ role: 'human', content: 'Hello' },
20-
{ role: 'assistant', content: 'Hi there!' },
2120
]);
2221

23-
const [nextChat, setNextChat] = useState({ role: 'human', content: '' });
22+
const [nextChat, setNextChat] = useState({ role: 'assistant', content: '' });
2423

2524
function systemMessageValue() {
2625
return chats.find((chat) => chat.role === 'system')?.content;
@@ -48,8 +47,7 @@ export default function NewChatForm({ submitChat, defaultChats = [] }) {
4847
flexDirection: 'column',
4948
gap: 2,
5049
overflowY: 'auto',
51-
maxHeight: '50vh',
52-
padding: 2,
50+
padding: 1,
5351
minWidth: '50vw',
5452
}}
5553
>

0 commit comments

Comments
 (0)