feat: Add system and quick prompts on side panel

This commit is contained in:
n4ze3m
2024-09-14 12:07:54 +05:30
parent 5602714ee2
commit 53d999a596
9 changed files with 115 additions and 31 deletions

View File

@@ -17,6 +17,7 @@ import { ChatHistory } from "@/store/option"
import {
deleteChatForEdit,
generateID,
getPromptById,
removeMessageUsingHistoryId,
updateMessageByIndex
} from "@/db"
@@ -75,9 +76,18 @@ export const useMessage = () => {
setIsEmbedding,
isEmbedding,
currentURL,
setCurrentURL
setCurrentURL,
selectedQuickPrompt,
setSelectedQuickPrompt,
selectedSystemPrompt,
setSelectedSystemPrompt
} = useStoreMessage()
const [speechToTextLanguage, setSpeechToTextLanguage] = useStorage(
"speechToTextLanguage",
"en-US"
)
const [keepTrackOfEmbedding, setKeepTrackOfEmbedding] = React.useState<{
[key: string]: MemoryVectorStore
}>({})
@@ -488,6 +498,7 @@ export const useMessage = () => {
try {
const prompt = await systemPromptForNonRag()
const selectedPrompt = await getPromptById(selectedSystemPrompt)
let humanMessage = new HumanMessage({
content: [
@@ -514,7 +525,7 @@ export const useMessage = () => {
const applicationChatHistory = generateHistory(history)
if (prompt) {
if (prompt && !selectedPrompt) {
applicationChatHistory.unshift(
new SystemMessage({
content: [
@@ -526,6 +537,18 @@ export const useMessage = () => {
})
)
}
if (selectedPrompt) {
applicationChatHistory.unshift(
new SystemMessage({
content: [
{
text: selectedPrompt.content,
type: "text"
}
]
})
)
}
const chunks = await ollama.stream(
[...applicationChatHistory, humanMessage],
@@ -1231,6 +1254,12 @@ export const useMessage = () => {
regenerateLastMessage,
webSearch,
setWebSearch,
isSearchingInternet
isSearchingInternet,
selectedQuickPrompt,
setSelectedQuickPrompt,
selectedSystemPrompt,
setSelectedSystemPrompt,
speechToTextLanguage,
setSpeechToTextLanguage
}
}

View File

@@ -55,8 +55,6 @@ export const useMessageOption = () => {
setIsProcessing,
chatMode,
setChatMode,
speechToTextLanguage,
setSpeechToTextLanguage,
webSearch,
setWebSearch,
isSearchingInternet,
@@ -70,7 +68,10 @@ export const useMessageOption = () => {
} = useStoreMessageOption()
const currentChatModelSettings = useStoreChatModelSettings()
const [selectedModel, setSelectedModel] = useStorage("selectedModel")
const [ speechToTextLanguage, setSpeechToTextLanguage ] = useStorage(
"speechToTextLanguage",
"en-US"
)
const { ttsEnabled } = useWebUI()
const { t } = useTranslation("option")
@@ -411,8 +412,6 @@ export const useMessageOption = () => {
const prompt = await systemPromptForNonRagOption()
const selectedPrompt = await getPromptById(selectedSystemPrompt)
// message = message.trim().replaceAll("\n", " ")
let humanMessage = new HumanMessage({
content: [
{