2024-02-25 23:45:07 +05:30
|
|
|
import { useQuery, useQueryClient } from "@tanstack/react-query"
|
2024-03-03 19:55:43 +05:30
|
|
|
import { Skeleton, Radio, Form, Alert } from "antd"
|
2024-02-25 23:45:07 +05:30
|
|
|
import React from "react"
|
2024-03-24 12:43:43 +05:30
|
|
|
import { useTranslation } from "react-i18next"
|
2024-03-23 14:44:05 +05:30
|
|
|
import { SaveButton } from "~/components/Common/SaveButton"
|
2024-02-07 21:07:41 +05:30
|
|
|
import {
|
2024-02-25 23:45:07 +05:30
|
|
|
getWebSearchPrompt,
|
2024-02-07 21:07:41 +05:30
|
|
|
setSystemPromptForNonRagOption,
|
2024-02-25 23:45:07 +05:30
|
|
|
systemPromptForNonRagOption,
|
|
|
|
|
geWebSearchFollowUpPrompt,
|
|
|
|
|
setWebPrompts
|
2024-03-23 14:44:05 +05:30
|
|
|
} from "~/services/ollama"
|
2024-02-07 21:07:41 +05:30
|
|
|
|
|
|
|
|
export const SettingPrompt = () => {
|
2024-03-24 21:00:00 +05:30
|
|
|
const { t } = useTranslation("settings")
|
2024-03-24 12:43:43 +05:30
|
|
|
|
2024-02-25 23:45:07 +05:30
|
|
|
const [selectedValue, setSelectedValue] = React.useState<"normal" | "web">(
|
2024-03-03 19:55:43 +05:30
|
|
|
"web"
|
2024-02-25 23:45:07 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const queryClient = useQueryClient()
|
|
|
|
|
|
|
|
|
|
const { status, data } = useQuery({
|
2024-02-07 21:07:41 +05:30
|
|
|
queryKey: ["fetchOllaPrompt"],
|
|
|
|
|
queryFn: async () => {
|
2024-02-25 23:45:07 +05:30
|
|
|
const [prompt, webSearchPrompt, webSearchFollowUpPrompt] =
|
|
|
|
|
await Promise.all([
|
|
|
|
|
systemPromptForNonRagOption(),
|
|
|
|
|
getWebSearchPrompt(),
|
|
|
|
|
geWebSearchFollowUpPrompt()
|
|
|
|
|
])
|
2024-02-07 21:07:41 +05:30
|
|
|
|
|
|
|
|
return {
|
2024-02-25 23:45:07 +05:30
|
|
|
prompt,
|
|
|
|
|
webSearchPrompt,
|
|
|
|
|
webSearchFollowUpPrompt
|
2024-02-07 21:07:41 +05:30
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return (
|
2024-02-25 23:45:07 +05:30
|
|
|
<div className="flex flex-col gap-3">
|
|
|
|
|
{status === "pending" && <Skeleton paragraph={{ rows: 4 }} active />}
|
|
|
|
|
|
|
|
|
|
{status === "success" && (
|
|
|
|
|
<div>
|
|
|
|
|
<div className="my-3 flex justify-end">
|
|
|
|
|
<Radio.Group
|
|
|
|
|
defaultValue={selectedValue}
|
|
|
|
|
onChange={(e) => setSelectedValue(e.target.value)}>
|
2024-03-24 12:43:43 +05:30
|
|
|
<Radio.Button value="normal">
|
|
|
|
|
{t("ollamaSettings.settings.prompt.option1")}
|
|
|
|
|
</Radio.Button>
|
|
|
|
|
<Radio.Button value="web">
|
|
|
|
|
{t("ollamaSettings.settings.prompt.option2")}
|
|
|
|
|
</Radio.Button>
|
2024-02-25 23:45:07 +05:30
|
|
|
</Radio.Group>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{selectedValue === "normal" && (
|
|
|
|
|
<Form
|
|
|
|
|
layout="vertical"
|
|
|
|
|
onFinish={(values) => {
|
|
|
|
|
setSystemPromptForNonRagOption(values?.prompt || "")
|
|
|
|
|
queryClient.invalidateQueries({
|
|
|
|
|
queryKey: ["fetchOllaPrompt"]
|
|
|
|
|
})
|
|
|
|
|
}}
|
|
|
|
|
initialValues={{
|
|
|
|
|
prompt: data.prompt
|
|
|
|
|
}}>
|
2024-03-03 19:55:43 +05:30
|
|
|
<Form.Item>
|
|
|
|
|
<Alert
|
2024-03-24 12:43:43 +05:30
|
|
|
message={t("ollamaSettings.settings.prompt.alert")}
|
2024-03-03 19:55:43 +05:30
|
|
|
type="warning"
|
|
|
|
|
showIcon
|
|
|
|
|
closable
|
|
|
|
|
/>
|
|
|
|
|
</Form.Item>
|
2024-03-24 12:43:43 +05:30
|
|
|
<Form.Item
|
|
|
|
|
label={t("ollamaSettings.settings.prompt.systemPrompt")}
|
|
|
|
|
name="prompt">
|
2024-02-25 23:45:07 +05:30
|
|
|
<textarea
|
|
|
|
|
value={data.prompt}
|
|
|
|
|
rows={5}
|
|
|
|
|
id="ollamaPrompt"
|
2024-03-24 12:43:43 +05:30
|
|
|
placeholder={t(
|
|
|
|
|
"ollamaSettings.settings.prompt.systemPromptPlaceholder"
|
|
|
|
|
)}
|
2024-02-25 23:45:07 +05:30
|
|
|
className="w-full p-2 border border-gray-300 rounded-md dark:bg-[#262626] dark:text-gray-100"
|
|
|
|
|
/>
|
|
|
|
|
</Form.Item>
|
|
|
|
|
<Form.Item>
|
|
|
|
|
<div className="flex justify-end">
|
|
|
|
|
<SaveButton btnType="submit" />
|
|
|
|
|
</div>{" "}
|
|
|
|
|
</Form.Item>
|
|
|
|
|
</Form>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{selectedValue === "web" && (
|
|
|
|
|
<Form
|
|
|
|
|
layout="vertical"
|
|
|
|
|
onFinish={(values) => {
|
|
|
|
|
setWebPrompts(
|
|
|
|
|
values?.webSearchPrompt || "",
|
|
|
|
|
values?.webSearchFollowUpPrompt || ""
|
|
|
|
|
)
|
|
|
|
|
queryClient.invalidateQueries({
|
|
|
|
|
queryKey: ["fetchOllaPrompt"]
|
|
|
|
|
})
|
|
|
|
|
}}
|
|
|
|
|
initialValues={{
|
|
|
|
|
webSearchPrompt: data.webSearchPrompt,
|
|
|
|
|
webSearchFollowUpPrompt: data.webSearchFollowUpPrompt
|
|
|
|
|
}}>
|
|
|
|
|
<Form.Item
|
2024-03-24 12:43:43 +05:30
|
|
|
label={t("ollamaSettings.settings.prompt.webSearchPrompt")}
|
2024-02-25 23:45:07 +05:30
|
|
|
name="webSearchPrompt"
|
2024-03-24 12:43:43 +05:30
|
|
|
help={t("ollamaSettings.settings.prompt.webSearchPromptHelp")}
|
2024-02-25 23:45:07 +05:30
|
|
|
rules={[
|
|
|
|
|
{
|
|
|
|
|
required: true,
|
2024-03-24 12:43:43 +05:30
|
|
|
message: t(
|
|
|
|
|
"ollamaSettings.settings.prompt.webSearchPromptError"
|
|
|
|
|
)
|
2024-02-25 23:45:07 +05:30
|
|
|
}
|
|
|
|
|
]}>
|
|
|
|
|
<textarea
|
|
|
|
|
value={data.webSearchPrompt}
|
|
|
|
|
rows={5}
|
|
|
|
|
id="ollamaWebSearchPrompt"
|
2024-03-24 12:43:43 +05:30
|
|
|
placeholder={t(
|
|
|
|
|
"ollamaSettings.settings.prompt.webSearchPromptPlaceholder"
|
|
|
|
|
)}
|
2024-02-25 23:45:07 +05:30
|
|
|
className="w-full p-2 border border-gray-300 rounded-md dark:bg-[#262626] dark:text-gray-100"
|
|
|
|
|
/>
|
|
|
|
|
</Form.Item>
|
|
|
|
|
<Form.Item
|
2024-03-24 12:43:43 +05:30
|
|
|
label={t("ollamaSettings.settings.prompt.webSearchFollowUpPrompt")}
|
2024-02-25 23:45:07 +05:30
|
|
|
name="webSearchFollowUpPrompt"
|
2024-03-24 12:43:43 +05:30
|
|
|
help={t("ollamaSettings.settings.prompt.webSearchFollowUpPromptHelp")}
|
2024-02-25 23:45:07 +05:30
|
|
|
rules={[
|
|
|
|
|
{
|
|
|
|
|
required: true,
|
2024-03-24 12:43:43 +05:30
|
|
|
message: t("ollamaSettings.settings.prompt.webSearchFollowUpPromptError")
|
2024-02-25 23:45:07 +05:30
|
|
|
}
|
|
|
|
|
]}>
|
|
|
|
|
<textarea
|
|
|
|
|
value={data.webSearchFollowUpPrompt}
|
|
|
|
|
rows={5}
|
|
|
|
|
id="ollamaWebSearchFollowUpPrompt"
|
2024-03-24 12:43:43 +05:30
|
|
|
placeholder={t("ollamaSettings.settings.prompt.webSearchFollowUpPromptPlaceholder")}
|
2024-02-25 23:45:07 +05:30
|
|
|
className="w-full p-2 border border-gray-300 rounded-md dark:bg-[#262626] dark:text-gray-100"
|
|
|
|
|
/>
|
|
|
|
|
</Form.Item>
|
|
|
|
|
<Form.Item>
|
|
|
|
|
<div className="flex justify-end">
|
|
|
|
|
<SaveButton btnType="submit" />
|
|
|
|
|
</div>{" "}
|
|
|
|
|
</Form.Item>
|
|
|
|
|
</Form>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2024-02-07 21:07:41 +05:30
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|