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-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-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 ) } >
< Radio.Button value = "normal" > Normal < / Radio.Button >
< Radio.Button value = "web" > Web < / Radio.Button >
< / 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
message = "Configuring the system prompt here is deprecated. Please use the Manage Prompts section to add or edit prompts. This section will be removed in a future release"
type = "warning"
showIcon
closable
/ >
< / Form.Item >
2024-02-25 23:45:07 +05:30
< Form.Item label = "System Prompt" name = "prompt" >
< textarea
value = { data . prompt }
rows = { 5 }
id = "ollamaPrompt"
placeholder = "Your System Prompt"
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
label = "Web Search Prompt"
name = "webSearchPrompt"
help = "Do not remove `{search_results}` from the prompt."
rules = { [
{
required : true ,
message : "Please input your Web Search Prompt!"
}
] } >
< textarea
value = { data . webSearchPrompt }
rows = { 5 }
id = "ollamaWebSearchPrompt"
placeholder = "Your Web Search Prompt"
className = "w-full p-2 border border-gray-300 rounded-md dark:bg-[#262626] dark:text-gray-100"
/ >
< / Form.Item >
< Form.Item
label = "Web Search Follow Up Prompt"
name = "webSearchFollowUpPrompt"
help = "Do not remove `{chat_history}` and `{question}` from the prompt."
rules = { [
{
required : true ,
message : "Please input your Web Search Follow Up Prompt!"
}
] } >
< textarea
value = { data . webSearchFollowUpPrompt }
rows = { 5 }
id = "ollamaWebSearchFollowUpPrompt"
placeholder = "Your Web Search Follow Up Prompt"
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 >
)
}