From 1d1e1f90b60f0116c0219923e0c1dcbea7f4f86d Mon Sep 17 00:00:00 2001 From: Jaswanth Karani Date: Fri, 6 Sep 2024 11:07:45 +0530 Subject: [PATCH] Add Settings and Update system Prompt option (#746) * Added settings and system prompt option Signed-off-by: jaswanth8888 --- .../components/Conversation/Conversation.tsx | 89 +++++++++++++------ .../Conversation/ConversationSideBar.tsx | 12 +-- .../Conversation/conversation.module.scss | 17 ++-- .../src/components/Conversation/settings.tsx | 48 ++++++++++ .../src/redux/Conversation/Conversation.ts | 10 +++ .../redux/Conversation/ConversationSlice.ts | 33 ++++++- .../src/styles/components/context.module.scss | 30 +++++-- 7 files changed, 190 insertions(+), 49 deletions(-) create mode 100644 ProductivitySuite/docker/ui/react/src/components/Conversation/settings.tsx diff --git a/ProductivitySuite/docker/ui/react/src/components/Conversation/Conversation.tsx b/ProductivitySuite/docker/ui/react/src/components/Conversation/Conversation.tsx index d4a65bbfd..e772248f3 100644 --- a/ProductivitySuite/docker/ui/react/src/components/Conversation/Conversation.tsx +++ b/ProductivitySuite/docker/ui/react/src/components/Conversation/Conversation.tsx @@ -3,14 +3,13 @@ import { KeyboardEventHandler, SyntheticEvent, useEffect, useRef, useState } from 'react' import styleClasses from "./conversation.module.scss" -import { ActionIcon, Group, Textarea, Title, rem } from '@mantine/core' -import { IconArrowRight, IconMessagePlus } from '@tabler/icons-react' -import { conversationSelector, doConversation, getAllConversations, newConversation } from '../../redux/Conversation/ConversationSlice' +import { ActionIcon, Group, Textarea, Title, Tooltip, rem } from '@mantine/core' +import { IconArrowDown, IconArrowRight, IconArrowUp, IconMessagePlus } from '@tabler/icons-react' +import { conversationSelector, doConversation, getAllConversations, newConversation, setSystemPrompt } from '../../redux/Conversation/ConversationSlice' import { ConversationMessage } from '../Message/conversationMessage' import { useAppDispatch, useAppSelector } from '../../redux/store' import { Message, MessageRole } from '../../redux/Conversation/Conversation' import { getCurrentTimeStamp } from '../../common/util' - import { ConversationSideBar } from './ConversationSideBar' import { getPrompts } from '../../redux/Prompt/PromptSlice' import { userSelector } from '../../redux/User/userSlice' @@ -22,11 +21,12 @@ type ConversationProps = { const Conversation = ({ title }: ConversationProps) => { const [prompt, setPrompt] = useState("") + const [updateSystemPrompt, setUpdateSystemPrompt] = useState(false) const dispatch = useAppDispatch(); const promptInputRef = useRef(null) - const { conversations, onGoingResult, selectedConversationId,selectedConversationHistory } = useAppSelector(conversationSelector) + const { conversations, onGoingResult, selectedConversationId, selectedConversationHistory, temperature, token, model, systemPrompt } = useAppSelector(conversationSelector) const { name } = useAppSelector(userSelector) const selectedConversation = conversations.find(x => x.id === selectedConversationId) @@ -34,9 +34,9 @@ const Conversation = ({ title }: ConversationProps) => { const toSend = "Enter" - const systemPrompt: Message = { + const systemPromptObject: Message = { role: MessageRole.System, - content: "You are helpful assistant", + content: systemPrompt, }; @@ -54,13 +54,15 @@ const Conversation = ({ title }: ConversationProps) => { // }) // } - messages = [systemPrompt, ...(selectedConversationHistory) ] + messages = [systemPromptObject, ...(selectedConversationHistory)] doConversation({ conversationId: selectedConversationId, userPrompt, messages, - model: "Intel/neural-chat-7b-v3-3", + model, + temperature, + token }) setPrompt("") } @@ -70,7 +72,7 @@ const Conversation = ({ title }: ConversationProps) => { } useEffect(() => { - if(name && name!=""){ + if (name && name != "") { dispatch(getPrompts({ promptText: "" })) dispatch(getAllConversations({ user: name })) } @@ -81,6 +83,7 @@ const Conversation = ({ title }: ConversationProps) => { }, [onGoingResult, selectedConversationHistory]) const handleKeyDown: KeyboardEventHandler = (event) => { + setUpdateSystemPrompt(false) if (!event.shiftKey && event.key === toSend) { handleSubmit() setTimeout(() => { @@ -99,18 +102,23 @@ const Conversation = ({ title }: ConversationProps) => { event.preventDefault() setPrompt((event.target as HTMLTextAreaElement).value) } + + const handleSystemPromptChange = (event: SyntheticEvent) => { + event.preventDefault() + dispatch(setSystemPrompt((event.target as HTMLTextAreaElement).value)) + } return (
-
+
- {selectedConversation?.first_query || ""} + {selectedConversation?.first_query || ""} {(selectedConversation || selectedConversationHistory.length > 0) && ( - + )} @@ -123,15 +131,16 @@ const Conversation = ({ title }: ConversationProps) => {
Start by asking a question
-
You can also upload your Document by clicking on Document icon on top right corner
+
You can update the system prompt by clicking on up arrow beside prompt field
+
You can also upload your Documents in the Data Management Tab
)} - {selectedConversationHistory.map((message,index) => { - return (message.role!== MessageRole.System && ()) + {selectedConversationHistory.map((message, index) => { + return (message.role !== MessageRole.System && ()) }) } @@ -142,21 +151,43 @@ const Conversation = ({ title }: ConversationProps) => {