Customize refusal response for query mode (#1243)

* Customize refusal response for `query` mode

* remove border for desktop
This commit is contained in:
Timothy Carambat 2024-04-30 16:14:30 -07:00 committed by GitHub
parent 547d4859ef
commit 42e1d8e8ce
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 50 additions and 0 deletions

View File

@ -0,0 +1,29 @@
import { chatQueryRefusalResponse } from "@/utils/chat";
export default function ChatQueryRefusalResponse({ workspace, setHasChanges }) {
return (
<div>
<div className="flex flex-col">
<label htmlFor="name" className="block input-label">
Query mode refusal response
</label>
<p className="text-white text-opacity-60 text-xs font-medium py-1.5">
When in <code className="bg-zinc-900 p-0.5 rounded-sm">query</code>{" "}
mode, you may want to return a custom refusal response when no context
is found.
</p>
</div>
<textarea
name="queryRefusalResponse"
rows={2}
defaultValue={chatQueryRefusalResponse(workspace)}
className="border-none bg-zinc-900 placeholder:text-white/20 text-white text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 mt-2"
placeholder="The text returned in query mode when there is no relevant context found for a response."
required={true}
wrap="soft"
autoComplete="off"
onChange={() => setHasChanges(true)}
/>
</div>
);
}

View File

@ -8,6 +8,7 @@ import ChatPromptSettings from "./ChatPromptSettings";
import ChatTemperatureSettings from "./ChatTemperatureSettings";
import ChatModeSelection from "./ChatModeSelection";
import WorkspaceLLMSelection from "./WorkspaceLLMSelection";
import ChatQueryRefusalResponse from "./ChatQueryRefusalResponse";
export default function ChatSettings({ workspace }) {
const [settings, setSettings] = useState({});
@ -68,6 +69,10 @@ export default function ChatSettings({ workspace }) {
workspace={workspace}
setHasChanges={setHasChanges}
/>
<ChatQueryRefusalResponse
workspace={workspace}
setHasChanges={setHasChanges}
/>
<ChatTemperatureSettings
settings={settings}
workspace={workspace}

View File

@ -140,3 +140,10 @@ export function chatPrompt(workspace) {
"Given the following conversation, relevant context, and a follow up question, reply with an answer to the current question the user is asking. Return only your response to the question given the above information following the users instructions as needed."
);
}
export function chatQueryRefusalResponse(workspace) {
return (
workspace?.queryRefusalResponse ??
"There is no relevant information in this workspace to answer your query."
);
}

View File

@ -26,6 +26,7 @@ const Workspace = {
"pfpFilename",
"agentProvider",
"agentModel",
"queryRefusalResponse",
],
new: async function (name = null, creatorId = null) {

View File

@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "workspaces" ADD COLUMN "queryRefusalResponse" TEXT;

View File

@ -130,6 +130,7 @@ model workspaces {
pfpFilename String?
agentProvider String?
agentModel String?
queryRefusalResponse String?
workspace_users workspace_users[]
documents workspace_documents[]
workspace_suggested_messages workspace_suggested_messages[]

View File

@ -137,6 +137,7 @@ async function streamChatWithForEmbed(
id: uuid,
type: "textResponse",
textResponse:
embed.workspace?.queryRefusalResponse ??
"There is no relevant information in this workspace to answer your query.",
sources: [],
close: true,

View File

@ -70,6 +70,7 @@ async function chatWithWorkspace(
close: true,
error: null,
textResponse:
workspace?.queryRefusalResponse ??
"There is no relevant information in this workspace to answer your query.",
};
}
@ -150,6 +151,7 @@ async function chatWithWorkspace(
close: true,
error: null,
textResponse:
workspace?.queryRefusalResponse ??
"There is no relevant information in this workspace to answer your query.",
};
}

View File

@ -79,6 +79,7 @@ async function streamChatWithWorkspace(
id: uuid,
type: "textResponse",
textResponse:
workspace?.queryRefusalResponse ??
"There is no relevant information in this workspace to answer your query.",
sources: [],
close: true,
@ -162,6 +163,7 @@ async function streamChatWithWorkspace(
id: uuid,
type: "textResponse",
textResponse:
workspace?.queryRefusalResponse ??
"There is no relevant information in this workspace to answer your query.",
sources: [],
close: true,