Skip to content

Commit 68b615c

Browse files
committed
allow editing a chat in the list of chats
1 parent 49b57ad commit 68b615c

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

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

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -309,19 +309,30 @@ export default function NewBatchModal({ open, setOpen, addQuery }) {
309309

310310
function ListOfChats({}) {
311311
const [chats, setChats] = useState([]);
312-
const [createNewChat, setCreateNewChat] = useState(false);
312+
// set editChat to -1 if you want to create a new chat, set it a specific index in the chats
313+
// array if you want to edit that chat. Set it to null if you are not editing
314+
const [editChat, setEditChat] = useState<number | null>(null);
313315
return (
314316
<>
315317
<DialogTitle>
316-
{createNewChat ? 'New Chat' : 'Create Batch of Chat Formatted Prompts'}
318+
{editChat !== null
319+
? 'New Chat'
320+
: 'Create Batch of Chat Formatted Prompts'}
317321
</DialogTitle>
318322
<Divider sx={{ my: 1 }} />
319-
{createNewChat ? (
323+
{editChat !== null ? (
320324
<NewChatForm
325+
defaultChats={editChat === -1 ? [] : chats[editChat]}
321326
submitChat={(chat) => {
322-
console.log(chat);
323-
setChats([...chats, chat]);
324-
setCreateNewChat(false);
327+
// If editChat is -1, then we are creating a new chat
328+
if (editChat === -1) {
329+
setChats([...chats, chat]);
330+
} else {
331+
const newChats = [...chats];
332+
newChats[editChat] = chat;
333+
setChats(newChats);
334+
}
335+
setEditChat(null);
325336
}}
326337
/>
327338
) : (
@@ -342,9 +353,10 @@ function ListOfChats({}) {
342353
</ListItemContent>
343354
<ButtonGroup>
344355
<Button
345-
disabled
346356
variant="plain"
347-
onClick={() => alert('net yet implemented')}
357+
onClick={() => {
358+
setEditChat(index);
359+
}}
348360
>
349361
<PencilIcon size="18px" />
350362
</Button>
@@ -362,7 +374,7 @@ function ListOfChats({}) {
362374
</ListItem>
363375
))}
364376
</List>
365-
<Button variant="soft" onClick={() => setCreateNewChat(true)}>
377+
<Button variant="soft" onClick={() => setEditChat(-1)}>
366378
Add New
367379
</Button>
368380
{/* <Button onClick={() => setChats([])}>Clear</Button> */}

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import {
1111
ButtonGroup,
1212
} from '@mui/joy';
1313
import { CheckIcon, PencilIcon, Trash2Icon } from 'lucide-react';
14-
import { useState } from 'react';
14+
import { useEffect, useState } from 'react';
1515

16-
export default function NewChatForm({ submitChat }) {
16+
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' },
@@ -35,6 +35,12 @@ export default function NewChatForm({ submitChat }) {
3535
setChats(newChats);
3636
}
3737

38+
useEffect(() => {
39+
if (defaultChats.length > 0) {
40+
setChats(defaultChats);
41+
}
42+
}, []);
43+
3844
return (
3945
<Box
4046
sx={{

0 commit comments

Comments
 (0)