feat: Add support for saving and restoring last used system prompt
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { saveHistory, saveMessage } from "@/db"
|
||||
import { setLastUsedChatModel } from "@/services/model-settings"
|
||||
import { setLastUsedChatModel, setLastUsedChatSystemPrompt } from "@/services/model-settings"
|
||||
import { generateTitle } from "@/services/title"
|
||||
import { ChatHistory } from "@/store/option"
|
||||
|
||||
@@ -15,7 +15,9 @@ export const saveMessageOnError = async ({
|
||||
setHistoryId,
|
||||
isRegenerating,
|
||||
message_source = "web-ui",
|
||||
message_type
|
||||
message_type,
|
||||
prompt_content,
|
||||
prompt_id
|
||||
}: {
|
||||
e: any
|
||||
setHistory: (history: ChatHistory) => void
|
||||
@@ -29,6 +31,8 @@ export const saveMessageOnError = async ({
|
||||
isRegenerating: boolean
|
||||
message_source?: "copilot" | "web-ui"
|
||||
message_type?: string
|
||||
prompt_id?: string
|
||||
prompt_content?: string
|
||||
}) => {
|
||||
if (
|
||||
e?.name === "AbortError" ||
|
||||
@@ -73,6 +77,9 @@ export const saveMessageOnError = async ({
|
||||
message_type
|
||||
)
|
||||
await setLastUsedChatModel(historyId, selectedModel)
|
||||
if (prompt_id || prompt_content) {
|
||||
await setLastUsedChatSystemPrompt(historyId, { prompt_content, prompt_id })
|
||||
}
|
||||
} else {
|
||||
const title = await generateTitle(selectedModel, userMessage, userMessage)
|
||||
const newHistoryId = await saveHistory(title, false, message_source)
|
||||
@@ -100,6 +107,9 @@ export const saveMessageOnError = async ({
|
||||
)
|
||||
setHistoryId(newHistoryId.id)
|
||||
await setLastUsedChatModel(newHistoryId.id, selectedModel)
|
||||
if (prompt_id || prompt_content) {
|
||||
await setLastUsedChatSystemPrompt(historyId, { prompt_content, prompt_id })
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
@@ -118,7 +128,9 @@ export const saveMessageOnSuccess = async ({
|
||||
fullText,
|
||||
source,
|
||||
message_source = "web-ui",
|
||||
message_type, generationInfo
|
||||
message_type, generationInfo,
|
||||
prompt_id,
|
||||
prompt_content
|
||||
}: {
|
||||
historyId: string | null
|
||||
setHistoryId: (historyId: string) => void
|
||||
@@ -131,6 +143,8 @@ export const saveMessageOnSuccess = async ({
|
||||
message_source?: "copilot" | "web-ui",
|
||||
message_type?: string
|
||||
generationInfo?: any
|
||||
prompt_id?: string
|
||||
prompt_content?: string
|
||||
}) => {
|
||||
if (historyId) {
|
||||
if (!isRegenerate) {
|
||||
@@ -158,6 +172,9 @@ export const saveMessageOnSuccess = async ({
|
||||
generationInfo
|
||||
)
|
||||
await setLastUsedChatModel(historyId, selectedModel!)
|
||||
if (prompt_id || prompt_content) {
|
||||
await setLastUsedChatSystemPrompt(historyId, { prompt_content, prompt_id })
|
||||
}
|
||||
} else {
|
||||
const title = await generateTitle(selectedModel, message, message)
|
||||
const newHistoryId = await saveHistory(title, false, message_source)
|
||||
@@ -185,5 +202,8 @@ export const saveMessageOnSuccess = async ({
|
||||
)
|
||||
setHistoryId(newHistoryId.id)
|
||||
await setLastUsedChatModel(newHistoryId.id, selectedModel!)
|
||||
if (prompt_id || prompt_content) {
|
||||
await setLastUsedChatSystemPrompt(historyId, { prompt_content, prompt_id })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -411,6 +411,8 @@ export const useMessageOption = () => {
|
||||
) => {
|
||||
const url = await getOllamaURL()
|
||||
const userDefaultModelSettings = await getAllDefaultModelSettings()
|
||||
let promptId: string | undefined = selectedSystemPrompt
|
||||
let promptContent: string | undefined = undefined
|
||||
|
||||
if (image.length > 0) {
|
||||
image = `data:image/jpeg;base64,${image.split(",")[1]}`
|
||||
@@ -525,6 +527,7 @@ export const useMessageOption = () => {
|
||||
content: selectedPrompt.content
|
||||
})
|
||||
)
|
||||
promptContent = selectedPrompt.content
|
||||
}
|
||||
|
||||
if (isTempSystemprompt) {
|
||||
@@ -533,6 +536,7 @@ export const useMessageOption = () => {
|
||||
content: currentChatModelSettings.systemPrompt
|
||||
})
|
||||
)
|
||||
promptContent = currentChatModelSettings.systemPrompt
|
||||
}
|
||||
|
||||
let generationInfo: any | undefined = undefined
|
||||
@@ -611,7 +615,9 @@ export const useMessageOption = () => {
|
||||
image,
|
||||
fullText,
|
||||
source: [],
|
||||
generationInfo
|
||||
generationInfo,
|
||||
prompt_content: promptContent,
|
||||
prompt_id: promptId
|
||||
})
|
||||
|
||||
setIsProcessing(false)
|
||||
@@ -629,7 +635,9 @@ export const useMessageOption = () => {
|
||||
setHistory,
|
||||
setHistoryId,
|
||||
userMessage: message,
|
||||
isRegenerating: isRegenerate
|
||||
isRegenerating: isRegenerate,
|
||||
prompt_content: promptContent,
|
||||
prompt_id: promptId
|
||||
})
|
||||
|
||||
if (!errorSave) {
|
||||
|
||||
Reference in New Issue
Block a user