Configurable message limit for embed chat widget (#4114)
* configurable message limit for embed widget * remove console log * make field optional + add fallback * rework validation logic * lint * remove field specific guard, it cannot be lte 0 like all other fields --------- Co-authored-by: Timothy Carambat <rambat1010@gmail.com>
This commit is contained in:
parent
5d60047dc7
commit
49293e7dd7
@ -101,7 +101,7 @@ const ScriptTag = ({ embed }) => {
|
||||
<button
|
||||
disabled={copied}
|
||||
onClick={handleClick}
|
||||
className={`disabled:border disabled:border-green-300 disabled:light:border-green-600 border border-transparent relative w-full font-mono flex hljs ${theme} light:border light:border-gray-700 text-white placeholder:text-theme-settings-input-placeholder text-sm rounded-lg focus:outline-primary-button active:outline-primary-button outline-none p-2.5`}
|
||||
className={`disabled:border disabled:border-green-300 disabled:light:border-green-600 border border-transparent relative w-full font-mono flex hljs ${theme} light:border light:border-gray-700 text-white placeholder:text-theme-settings-input-placeholder text-sm rounded-lg focus:outline-primary-button active:outline-primary-button outline-none p-2.5 m-1`}
|
||||
>
|
||||
<div
|
||||
className="flex w-full text-left flex-col gap-y-1 pr-6 pl-4 whitespace-pre-line"
|
||||
|
||||
@ -70,6 +70,12 @@ export default function EditEmbedModal({ embed, closeModal }) {
|
||||
hint="Limit the amount of chats a session user can send with this embed in a 24 hour period. Zero is unlimited."
|
||||
defaultValue={embed.max_chats_per_session}
|
||||
/>
|
||||
<NumberInput
|
||||
name="message_limit"
|
||||
title="Message History Limit"
|
||||
hint="The number of previous messages to include in the chat context. Default is 20."
|
||||
defaultValue={embed.message_limit}
|
||||
/>
|
||||
<BooleanInput
|
||||
name="allow_model_override"
|
||||
title="Enable dynamic model use"
|
||||
|
||||
@ -20,6 +20,7 @@ export function enforceSubmissionSchema(form) {
|
||||
data.allow_temperature_override = false;
|
||||
if (!data.hasOwnProperty("allow_prompt_override"))
|
||||
data.allow_prompt_override = false;
|
||||
if (!data.hasOwnProperty("message_limit")) data.message_limit = 20;
|
||||
return data;
|
||||
}
|
||||
|
||||
@ -69,6 +70,12 @@ export default function NewEmbedModal({ closeModal }) {
|
||||
title="Max chats per session"
|
||||
hint="Limit the amount of chats a session user can send with this embed in a 24 hour period. Zero is unlimited."
|
||||
/>
|
||||
<NumberInput
|
||||
name="message_limit"
|
||||
title="Message History Limit"
|
||||
hint="The number of previous messages to include in the chat context. Default is 20."
|
||||
defaultValue={20}
|
||||
/>
|
||||
<BooleanInput
|
||||
name="allow_model_override"
|
||||
title="Enable dynamic model use"
|
||||
@ -150,6 +157,7 @@ export const WorkspaceSelection = ({ defaultValue = null }) => {
|
||||
{workspaces.map((workspace) => {
|
||||
return (
|
||||
<option
|
||||
key={workspace.id}
|
||||
selected={defaultValue === workspace.id}
|
||||
value={workspace.id}
|
||||
>
|
||||
|
||||
@ -14,6 +14,7 @@ const EmbedConfig = {
|
||||
"max_chats_per_session",
|
||||
"chat_mode",
|
||||
"workspace_id",
|
||||
"message_limit",
|
||||
],
|
||||
|
||||
new: async function (data, creatorId = null) {
|
||||
@ -47,6 +48,10 @@ const EmbedConfig = {
|
||||
data?.max_chats_per_session,
|
||||
"max_chats_per_session"
|
||||
),
|
||||
message_limit: validatedCreationData(
|
||||
data?.message_limit,
|
||||
"message_limit"
|
||||
),
|
||||
createdBy: Number(creatorId) ?? null,
|
||||
workspace: {
|
||||
connect: { id: Number(data.workspace_id) },
|
||||
@ -190,6 +195,7 @@ const NUMBER_KEYS = [
|
||||
"max_chats_per_day",
|
||||
"max_chats_per_session",
|
||||
"workspace_id",
|
||||
"message_limit",
|
||||
];
|
||||
|
||||
// Helper to validate a data object strictly into the proper format
|
||||
|
||||
@ -0,0 +1,2 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "embed_configs" ADD COLUMN "message_limit" INTEGER DEFAULT 20;
|
||||
@ -240,6 +240,7 @@ model embed_configs {
|
||||
allow_prompt_override Boolean @default(false)
|
||||
max_chats_per_day Int?
|
||||
max_chats_per_session Int?
|
||||
message_limit Int? @default(20)
|
||||
workspace_id Int
|
||||
createdBy Int?
|
||||
usersId Int?
|
||||
|
||||
@ -34,7 +34,7 @@ async function streamChatWithForEmbed(
|
||||
});
|
||||
const VectorDb = getVectorDbClass();
|
||||
|
||||
const messageLimit = 20;
|
||||
const messageLimit = embed.message_limit ?? 20;
|
||||
const hasVectorizedSpace = await VectorDb.hasNamespace(embed.workspace.slug);
|
||||
const embeddingsCount = await VectorDb.namespaceCount(embed.workspace.slug);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user