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 ChatTemperatureSettings from "./ChatTemperatureSettings";
import ChatModeSelection from "./ChatModeSelection"; import ChatModeSelection from "./ChatModeSelection";
import WorkspaceLLMSelection from "./WorkspaceLLMSelection"; import WorkspaceLLMSelection from "./WorkspaceLLMSelection";
import ChatQueryRefusalResponse from "./ChatQueryRefusalResponse";
export default function ChatSettings({ workspace }) { export default function ChatSettings({ workspace }) {
const [settings, setSettings] = useState({}); const [settings, setSettings] = useState({});
@ -68,6 +69,10 @@ export default function ChatSettings({ workspace }) {
workspace={workspace} workspace={workspace}
setHasChanges={setHasChanges} setHasChanges={setHasChanges}
/> />
<ChatQueryRefusalResponse
workspace={workspace}
setHasChanges={setHasChanges}
/>
<ChatTemperatureSettings <ChatTemperatureSettings
settings={settings} settings={settings}
workspace={workspace} 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." "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", "pfpFilename",
"agentProvider", "agentProvider",
"agentModel", "agentModel",
"queryRefusalResponse",
], ],
new: async function (name = null, creatorId = null) { 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? pfpFilename String?
agentProvider String? agentProvider String?
agentModel String? agentModel String?
queryRefusalResponse String?
workspace_users workspace_users[] workspace_users workspace_users[]
documents workspace_documents[] documents workspace_documents[]
workspace_suggested_messages workspace_suggested_messages[] workspace_suggested_messages workspace_suggested_messages[]

View File

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

View File

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

View File

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