diff --git a/api/__pycache__/index.cpython-311.pyc b/api/__pycache__/index.cpython-311.pyc index 3f0a288..4b67a91 100644 Binary files a/api/__pycache__/index.cpython-311.pyc and b/api/__pycache__/index.cpython-311.pyc differ diff --git a/api/index.py b/api/index.py index 161418c..c8fa0ab 100644 --- a/api/index.py +++ b/api/index.py @@ -1,3 +1,5 @@ +#api/index.py + from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from starlette.middleware.sessions import SessionMiddleware diff --git a/api/models/__pycache__/conversation.cpython-311.pyc b/api/models/__pycache__/conversation.cpython-311.pyc index 0f72260..94ed9dc 100644 Binary files a/api/models/__pycache__/conversation.cpython-311.pyc and b/api/models/__pycache__/conversation.cpython-311.pyc differ diff --git a/api/models/__pycache__/user.cpython-311.pyc b/api/models/__pycache__/user.cpython-311.pyc index 1eee7db..d66d344 100644 Binary files a/api/models/__pycache__/user.cpython-311.pyc and b/api/models/__pycache__/user.cpython-311.pyc differ diff --git a/api/models/conversation.py b/api/models/conversation.py index 5068716..365c05d 100644 --- a/api/models/conversation.py +++ b/api/models/conversation.py @@ -1,3 +1,5 @@ +# api/models/conversation.py + from datetime import datetime from typing import List from pydantic import BaseModel, Field diff --git a/api/models/user.py b/api/models/user.py index 8ea692f..47e8dcd 100644 --- a/api/models/user.py +++ b/api/models/user.py @@ -1,3 +1,4 @@ +#api/models/user.py from pydantic import BaseModel class User(BaseModel): diff --git a/api/routes/__pycache__/conversation_routes.cpython-311.pyc b/api/routes/__pycache__/conversation_routes.cpython-311.pyc index 94c2905..248b361 100644 Binary files a/api/routes/__pycache__/conversation_routes.cpython-311.pyc and b/api/routes/__pycache__/conversation_routes.cpython-311.pyc differ diff --git a/api/routes/conversation_routes.py b/api/routes/conversation_routes.py index 95783c0..58caab0 100644 --- a/api/routes/conversation_routes.py +++ b/api/routes/conversation_routes.py @@ -1,3 +1,5 @@ +#api/routes/conversation_routes.py + from typing import List from fastapi import APIRouter, Depends, HTTPException from fastapi.responses import StreamingResponse diff --git a/api/utils/__pycache__/conversation_utils.cpython-311.pyc b/api/utils/__pycache__/conversation_utils.cpython-311.pyc index 8b4eaa8..ea54324 100644 Binary files a/api/utils/__pycache__/conversation_utils.cpython-311.pyc and b/api/utils/__pycache__/conversation_utils.cpython-311.pyc differ diff --git a/api/utils/conversation_utils.py b/api/utils/conversation_utils.py index 6e8f06d..e5f3245 100644 --- a/api/utils/conversation_utils.py +++ b/api/utils/conversation_utils.py @@ -1,3 +1,5 @@ +# api/utils/conversation_utils.py + from datetime import datetime, timezone from typing import List diff --git a/app/components/AutoResizeTextArea.tsx b/app/components/AutoResizeTextArea.tsx index 7b66701..97cd026 100644 --- a/app/components/AutoResizeTextArea.tsx +++ b/app/components/AutoResizeTextArea.tsx @@ -1,4 +1,4 @@ -// components/AutoResizeTextarea.tsx +// app/components/AutoResizeTextarea.tsx import React, { useEffect, useRef } from "react"; import { Textarea, TextareaProps } from "@chakra-ui/react"; diff --git a/app/components/ConversationMessages.tsx b/app/components/ConversationMessages.tsx index f4653a5..39890f2 100644 --- a/app/components/ConversationMessages.tsx +++ b/app/components/ConversationMessages.tsx @@ -1,3 +1,5 @@ +//app/components/ConversationMessages.tsx + import React, { useEffect, useRef } from "react"; import { Box, Text, VStack, Button, Center, Heading } from "@chakra-ui/react"; import ReactMarkdown from "react-markdown"; @@ -19,6 +21,7 @@ interface ConversationMessagesProps { messages: Message[]; handleHideMessage: (index: number) => Promise; handleDeleteMessage: (index: number) => Promise; + handleEditMessage: (index: number) => Promise; userName?: string; } @@ -32,6 +35,7 @@ const ConversationMessages: React.FC = ({ messages, handleHideMessage, handleDeleteMessage, + handleEditMessage, userName = "User", }) => { const messagesEndRef = useRef(null); @@ -157,6 +161,18 @@ const ConversationMessages: React.FC = ({ > delete + {message.role === "user" && ( + + )} )) )} diff --git a/app/components/Sidebar.tsx b/app/components/Sidebar.tsx index 3ab0f77..96029a7 100644 --- a/app/components/Sidebar.tsx +++ b/app/components/Sidebar.tsx @@ -1,3 +1,5 @@ +//app/components/Sidebar.tsx + import { useState } from "react"; import { Box, diff --git a/app/page.tsx b/app/page.tsx index 14bc3ef..35147cc 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -1,4 +1,6 @@ "use client"; + +// app/page.tsx import { useEffect, useState } from "react"; import { useRouter } from "next/navigation"; import { useSearchParams } from "next/navigation"; @@ -26,6 +28,7 @@ import { fetchConversationById, handleHideMessage, handleDeleteMessage, + handleEditMessage, } from "./utils"; import Link from "next/link"; import { jwtDecode, JwtPayload } from "jwt-decode"; @@ -82,6 +85,19 @@ export default function Home() { } }; + const handleEditMessageWrapper = async (index: number) => { + if (conversationId) { + await handleEditMessage( + index, + messages, + conversationId, + setMessages, + setTextValue, + cookies + ); + } + }; + useEffect(() => { const token = searchParams.get("token"); @@ -199,6 +215,7 @@ export default function Home() { messages={messages} handleHideMessage={handleHideMessageWrapper} handleDeleteMessage={handleDeleteMessageWrapper} + handleEditMessage={handleEditMessageWrapper} userName={clientUserName} /> diff --git a/app/utils.ts b/app/utils.ts index a9991e7..2f9a3bb 100644 --- a/app/utils.ts +++ b/app/utils.ts @@ -1,3 +1,5 @@ +//app/utils.ts + import { Message } from "./components/ConversationMessages"; import { LLMProviders } from "./llm_providers"; @@ -267,4 +269,35 @@ export const handleDeleteMessage = async ( } catch (error) { console.error("Error deleting message:", error); } +}; + + +export const handleEditMessage = async ( + index: number, + messages: Message[], + conversationId: string, + setMessages: React.Dispatch>, + setTextValue: React.Dispatch>, + cookies: { [key: string]: string } +) => { + try { + const updatedMessages = messages.slice(0, index); + await fetch( + `${process.env.BACKEND_URL}/conversations/${conversationId}/messages`, + { + method: "PUT", + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${cookies.token}`, + }, + body: JSON.stringify(updatedMessages), + mode: "cors", + credentials: "include", + } + ); + setMessages(updatedMessages); + setTextValue(messages[index].content); + } catch (error) { + console.error("Error editing message:", error); + } }; \ No newline at end of file