Update Ollama system prompt in ollama.ts
This commit is contained in:
parent
0e59aa77cf
commit
b86332f9ec
@ -1,5 +1,5 @@
|
|||||||
import { useQuery, useQueryClient } from "@tanstack/react-query"
|
import { useQuery, useQueryClient } from "@tanstack/react-query"
|
||||||
import { Skeleton, Radio, Form, Alert } from "antd"
|
import { Skeleton, Radio, Form, Input } from "antd"
|
||||||
import React from "react"
|
import React from "react"
|
||||||
import { useTranslation } from "react-i18next"
|
import { useTranslation } from "react-i18next"
|
||||||
import { SaveButton } from "~/components/Common/SaveButton"
|
import { SaveButton } from "~/components/Common/SaveButton"
|
||||||
@ -8,15 +8,15 @@ import {
|
|||||||
setSystemPromptForNonRagOption,
|
setSystemPromptForNonRagOption,
|
||||||
systemPromptForNonRagOption,
|
systemPromptForNonRagOption,
|
||||||
geWebSearchFollowUpPrompt,
|
geWebSearchFollowUpPrompt,
|
||||||
setWebPrompts
|
setWebPrompts,
|
||||||
|
promptForRag,
|
||||||
|
setPromptForRag
|
||||||
} from "~/services/ollama"
|
} from "~/services/ollama"
|
||||||
|
|
||||||
export const SettingPrompt = () => {
|
export const SettingPrompt = () => {
|
||||||
const { t } = useTranslation("settings")
|
const { t } = useTranslation("settings")
|
||||||
|
|
||||||
const [selectedValue, setSelectedValue] = React.useState<"normal" | "web">(
|
const [selectedValue, setSelectedValue] = React.useState<"web" | "rag">("rag")
|
||||||
"web"
|
|
||||||
)
|
|
||||||
|
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
|
|
||||||
@ -25,7 +25,7 @@ export const SettingPrompt = () => {
|
|||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const [prompt, webSearchPrompt, webSearchFollowUpPrompt] =
|
const [prompt, webSearchPrompt, webSearchFollowUpPrompt] =
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
systemPromptForNonRagOption(),
|
promptForRag(),
|
||||||
getWebSearchPrompt(),
|
getWebSearchPrompt(),
|
||||||
geWebSearchFollowUpPrompt()
|
geWebSearchFollowUpPrompt()
|
||||||
])
|
])
|
||||||
@ -48,46 +48,60 @@ export const SettingPrompt = () => {
|
|||||||
<Radio.Group
|
<Radio.Group
|
||||||
defaultValue={selectedValue}
|
defaultValue={selectedValue}
|
||||||
onChange={(e) => setSelectedValue(e.target.value)}>
|
onChange={(e) => setSelectedValue(e.target.value)}>
|
||||||
<Radio.Button value="normal">
|
<Radio.Button value="rag">RAG</Radio.Button>
|
||||||
{t("ollamaSettings.settings.prompt.option1")}
|
|
||||||
</Radio.Button>
|
|
||||||
<Radio.Button value="web">
|
<Radio.Button value="web">
|
||||||
{t("ollamaSettings.settings.prompt.option2")}
|
{t("ollamaSettings.settings.prompt.option2")}
|
||||||
</Radio.Button>
|
</Radio.Button>
|
||||||
</Radio.Group>
|
</Radio.Group>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{selectedValue === "normal" && (
|
{selectedValue === "rag" && (
|
||||||
<Form
|
<Form
|
||||||
layout="vertical"
|
layout="vertical"
|
||||||
onFinish={(values) => {
|
onFinish={(values) => {
|
||||||
setSystemPromptForNonRagOption(values?.prompt || "")
|
// setSystemPromptForNonRagOption(values?.prompt || "")
|
||||||
|
setPromptForRag(
|
||||||
|
values?.systemPrompt || "",
|
||||||
|
values?.questionPrompt || ""
|
||||||
|
)
|
||||||
queryClient.invalidateQueries({
|
queryClient.invalidateQueries({
|
||||||
queryKey: ["fetchOllaPrompt"]
|
queryKey: ["fetchOllaPrompt"]
|
||||||
})
|
})
|
||||||
}}
|
}}
|
||||||
initialValues={{
|
initialValues={{
|
||||||
prompt: data.prompt
|
systemPrompt: data.prompt.ragPrompt,
|
||||||
|
questionPrompt: data.prompt.ragQuestionPrompt
|
||||||
}}>
|
}}>
|
||||||
<Form.Item>
|
<Form.Item
|
||||||
<Alert
|
label={t("managePrompts.systemPrompt")}
|
||||||
message={t("ollamaSettings.settings.prompt.alert")}
|
name="systemPrompt"
|
||||||
type="warning"
|
rules={[
|
||||||
showIcon
|
{
|
||||||
closable
|
required: true,
|
||||||
|
message: "Enter a prompt."
|
||||||
|
}
|
||||||
|
]}>
|
||||||
|
<Input.TextArea
|
||||||
|
value={data.webSearchPrompt}
|
||||||
|
rows={5}
|
||||||
|
placeholder="Enter a prompt."
|
||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item
|
<Form.Item
|
||||||
label={t("ollamaSettings.settings.prompt.systemPrompt")}
|
label={t("managePrompts.questionPrompt")}
|
||||||
name="prompt">
|
name="questionPrompt"
|
||||||
<textarea
|
rules={[
|
||||||
value={data.prompt}
|
{
|
||||||
|
required: true,
|
||||||
|
message: "Enter a follow up prompt."
|
||||||
|
}
|
||||||
|
]}>
|
||||||
|
<Input.TextArea
|
||||||
|
value={data.webSearchFollowUpPrompt}
|
||||||
rows={5}
|
rows={5}
|
||||||
id="ollamaPrompt"
|
|
||||||
placeholder={t(
|
placeholder={t(
|
||||||
"ollamaSettings.settings.prompt.systemPromptPlaceholder"
|
"ollamaSettings.settings.prompt.webSearchFollowUpPromptPlaceholder"
|
||||||
)}
|
)}
|
||||||
className="w-full p-2 border border-gray-300 rounded-md dark:bg-[#262626] dark:text-gray-100"
|
|
||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item>
|
<Form.Item>
|
||||||
@ -126,32 +140,36 @@ export const SettingPrompt = () => {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
]}>
|
]}>
|
||||||
<textarea
|
<Input.TextArea
|
||||||
value={data.webSearchPrompt}
|
value={data.webSearchPrompt}
|
||||||
rows={5}
|
rows={5}
|
||||||
id="ollamaWebSearchPrompt"
|
|
||||||
placeholder={t(
|
placeholder={t(
|
||||||
"ollamaSettings.settings.prompt.webSearchPromptPlaceholder"
|
"ollamaSettings.settings.prompt.webSearchPromptPlaceholder"
|
||||||
)}
|
)}
|
||||||
className="w-full p-2 border border-gray-300 rounded-md dark:bg-[#262626] dark:text-gray-100"
|
|
||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item
|
<Form.Item
|
||||||
label={t("ollamaSettings.settings.prompt.webSearchFollowUpPrompt")}
|
label={t(
|
||||||
|
"ollamaSettings.settings.prompt.webSearchFollowUpPrompt"
|
||||||
|
)}
|
||||||
name="webSearchFollowUpPrompt"
|
name="webSearchFollowUpPrompt"
|
||||||
help={t("ollamaSettings.settings.prompt.webSearchFollowUpPromptHelp")}
|
help={t(
|
||||||
|
"ollamaSettings.settings.prompt.webSearchFollowUpPromptHelp"
|
||||||
|
)}
|
||||||
rules={[
|
rules={[
|
||||||
{
|
{
|
||||||
required: true,
|
required: true,
|
||||||
message: t("ollamaSettings.settings.prompt.webSearchFollowUpPromptError")
|
message: t(
|
||||||
|
"ollamaSettings.settings.prompt.webSearchFollowUpPromptError"
|
||||||
|
)
|
||||||
}
|
}
|
||||||
]}>
|
]}>
|
||||||
<textarea
|
<Input.TextArea
|
||||||
value={data.webSearchFollowUpPrompt}
|
value={data.webSearchFollowUpPrompt}
|
||||||
rows={5}
|
rows={5}
|
||||||
id="ollamaWebSearchFollowUpPrompt"
|
placeholder={t(
|
||||||
placeholder={t("ollamaSettings.settings.prompt.webSearchFollowUpPromptPlaceholder")}
|
"ollamaSettings.settings.prompt.webSearchFollowUpPromptPlaceholder"
|
||||||
className="w-full p-2 border border-gray-300 rounded-md dark:bg-[#262626] dark:text-gray-100"
|
)}
|
||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item>
|
<Form.Item>
|
||||||
|
@ -11,8 +11,7 @@ const DEFAULT_PAGE_SHARE_URL = "https://pageassist.xyz"
|
|||||||
const DEFAULT_RAG_QUESTION_PROMPT =
|
const DEFAULT_RAG_QUESTION_PROMPT =
|
||||||
"Given the following conversation and a follow up question, rephrase the follow up question to be a standalone question. Chat History: {chat_history} Follow Up Input: {question} Standalone question:"
|
"Given the following conversation and a follow up question, rephrase the follow up question to be a standalone question. Chat History: {chat_history} Follow Up Input: {question} Standalone question:"
|
||||||
|
|
||||||
const DEFAUTL_RAG_SYSTEM_PROMPT = `You are a helpful AI assistant. Use the following pieces of context to answer the question at the end. If you don't know the answer, just say you don't know. DO NOT try to make up an answer. If the question is not related to the context, politely respond that you are tuned to only answer questions that are related to the context. {context} Question: {question} Helpful answer in markdown:`
|
const DEFAUTL_RAG_SYSTEM_PROMPT = `You are a helpful AI assistant. Use the following pieces of context to answer the question at the end. If you don't know the answer, just say you don't know. DO NOT try to make up an answer. If the question is not related to the context, politely respond that you are tuned to only answer questions that are related to the context. {context} Question: {question} Helpful answer:`
|
||||||
|
|
||||||
|
|
||||||
const DEFAULT_WEBSEARCH_PROMP = `You are a helpful assistant that can answer any questions. You can use the following search results in case you want to answer questions about anything in real-time. The current date and time are {current_date_time}.
|
const DEFAULT_WEBSEARCH_PROMP = `You are a helpful assistant that can answer any questions. You can use the following search results in case you want to answer questions about anything in real-time. The current date and time are {current_date_time}.
|
||||||
|
|
||||||
@ -61,7 +60,11 @@ export const isOllamaRunning = async () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getAllModels = async ({ returnEmpty = false }: { returnEmpty?: boolean }) => {
|
export const getAllModels = async ({
|
||||||
|
returnEmpty = false
|
||||||
|
}: {
|
||||||
|
returnEmpty?: boolean
|
||||||
|
}) => {
|
||||||
try {
|
try {
|
||||||
const baseUrl = await getOllamaURL()
|
const baseUrl = await getOllamaURL()
|
||||||
const response = await fetch(`${cleanUrl(baseUrl)}/api/tags`)
|
const response = await fetch(`${cleanUrl(baseUrl)}/api/tags`)
|
||||||
@ -264,7 +267,6 @@ export const saveForRag = async (
|
|||||||
await setDefaultEmbeddingChunkOverlap(overlap)
|
await setDefaultEmbeddingChunkOverlap(overlap)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export const getWebSearchPrompt = async () => {
|
export const getWebSearchPrompt = async () => {
|
||||||
const prompt = await storage.get("webSearchPrompt")
|
const prompt = await storage.get("webSearchPrompt")
|
||||||
if (!prompt || prompt.length === 0) {
|
if (!prompt || prompt.length === 0) {
|
||||||
@ -280,23 +282,20 @@ export const setWebSearchPrompt = async (prompt: string) => {
|
|||||||
export const geWebSearchFollowUpPrompt = async () => {
|
export const geWebSearchFollowUpPrompt = async () => {
|
||||||
const prompt = await storage.get("webSearchFollowUpPrompt")
|
const prompt = await storage.get("webSearchFollowUpPrompt")
|
||||||
if (!prompt || prompt.length === 0) {
|
if (!prompt || prompt.length === 0) {
|
||||||
return DEFAULT_RAG_QUESTION_PROMPT;
|
return DEFAULT_RAG_QUESTION_PROMPT
|
||||||
}
|
}
|
||||||
return prompt
|
return prompt
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export const setWebSearchFollowUpPrompt = async (prompt: string) => {
|
export const setWebSearchFollowUpPrompt = async (prompt: string) => {
|
||||||
await storage.set("webSearchFollowUpPrompt", prompt)
|
await storage.set("webSearchFollowUpPrompt", prompt)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export const setWebPrompts = async (prompt: string, followUpPrompt: string) => {
|
export const setWebPrompts = async (prompt: string, followUpPrompt: string) => {
|
||||||
await setWebSearchPrompt(prompt)
|
await setWebSearchPrompt(prompt)
|
||||||
await setWebSearchFollowUpPrompt(followUpPrompt)
|
await setWebSearchFollowUpPrompt(followUpPrompt)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export const getPageShareUrl = async () => {
|
export const getPageShareUrl = async () => {
|
||||||
const pageShareUrl = await storage.get("pageShareUrl")
|
const pageShareUrl = await storage.get("pageShareUrl")
|
||||||
if (!pageShareUrl || pageShareUrl.length === 0) {
|
if (!pageShareUrl || pageShareUrl.length === 0) {
|
||||||
@ -305,7 +304,6 @@ export const getPageShareUrl = async () => {
|
|||||||
return pageShareUrl
|
return pageShareUrl
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export const setPageShareUrl = async (pageShareUrl: string) => {
|
export const setPageShareUrl = async (pageShareUrl: string) => {
|
||||||
await storage.set("pageShareUrl", pageShareUrl)
|
await storage.set("pageShareUrl", pageShareUrl)
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user