Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add thoughts option to embed chat widget + UI improvements #3448

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion frontend/public/embed/anythingllm-chat-widget.min.css

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions frontend/public/embed/anythingllm-chat-widget.min.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ https://github.com/Mintplex-Labs/anything-llm/tree/master/embed/README.md
<script
data-embed-id="${embed.uuid}"
data-base-api-url="${serverHost}/api/embed"
data-show-thoughts="${embed.show_thoughts}"
src="${scriptHost}/embed/anythingllm-chat-widget.min.js">
</script>
<!-- AnythingLLM (https://anythingllm.com) -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ export default function EditEmbedModal({ embed, closeModal }) {
hint="Allow setting of the system prompt to override the workspace default."
defaultValue={embed.allow_prompt_override}
/>
<BooleanInput
name="show_thoughts"
title="Show AI Thoughts"
hint="Allow users to see the AI's thought process in responses. If disabled, users will only see the thinking state."
defaultValue={embed.show_thoughts}
/>

{error && <p className="text-red-400 text-sm">Error: {error}</p>}
<p className="text-white text-opacity-60 text-xs md:text-sm">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ export function enforceSubmissionSchema(form) {
}

// Always set value on nullable keys since empty or off will not send anything from form element.
if (!data.hasOwnProperty("allowlist_domains")) data.allowlist_domains = null;
if (!data.hasOwnProperty("allow_model_override"))
if (!Object.prototype.hasOwnProperty.call(data, "allowlist_domains"))
data.allowlist_domains = null;
if (!Object.prototype.hasOwnProperty.call(data, "allow_model_override"))
data.allow_model_override = false;
if (!data.hasOwnProperty("allow_temperature_override"))
if (!Object.prototype.hasOwnProperty.call(data, "allow_temperature_override"))
data.allow_temperature_override = false;
if (!data.hasOwnProperty("allow_prompt_override"))
if (!Object.prototype.hasOwnProperty.call(data, "allow_prompt_override"))
data.allow_prompt_override = false;
if (!Object.prototype.hasOwnProperty.call(data, "show_thoughts"))
data.show_thoughts = false;
return data;
}

Expand Down Expand Up @@ -84,6 +87,12 @@ export default function NewEmbedModal({ closeModal }) {
title="Enable Prompt Override"
hint="Allow setting of the system prompt to override the workspace default."
/>
<BooleanInput
name="show_thoughts"
title="Show AI Thoughts"
hint="Allow users to see the AI's thought process in responses. If disabled, users will only see the thinking state. Re-copy the embed code after changing this option."
defaultValue={true}
/>

{error && <p className="text-red-400 text-sm">Error: {error}</p>}
<p className="text-white text-opacity-60 text-xs md:text-sm">
Expand Down Expand Up @@ -150,6 +159,7 @@ export const WorkspaceSelection = ({ defaultValue = null }) => {
{workspaces.map((workspace) => {
return (
<option
key={workspace.id}
selected={defaultValue === workspace.id}
value={workspace.id}
>
Expand Down
6 changes: 6 additions & 0 deletions server/models/embedConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const EmbedConfig = {
"allow_model_override",
"allow_temperature_override",
"allow_prompt_override",
"show_thoughts",
"max_chats_per_day",
"max_chats_per_session",
"chat_mode",
Expand Down Expand Up @@ -39,6 +40,10 @@ const EmbedConfig = {
data?.allow_prompt_override,
"allow_prompt_override"
),
show_thoughts: validatedCreationData(
data?.show_thoughts,
"show_thoughts"
),
max_chats_per_day: validatedCreationData(
data?.max_chats_per_day,
"max_chats_per_day"
Expand Down Expand Up @@ -183,6 +188,7 @@ const BOOLEAN_KEYS = [
"allow_model_override",
"allow_temperature_override",
"allow_prompt_override",
"show_thoughts",
"enabled",
];

Expand Down
27 changes: 27 additions & 0 deletions server/prisma/migrations/20250312225228_init/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-- RedefineTables
PRAGMA foreign_keys=OFF;
CREATE TABLE "new_embed_configs" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"uuid" TEXT NOT NULL,
"enabled" BOOLEAN NOT NULL DEFAULT false,
"chat_mode" TEXT NOT NULL DEFAULT 'query',
"allowlist_domains" TEXT,
"allow_model_override" BOOLEAN NOT NULL DEFAULT false,
"allow_temperature_override" BOOLEAN NOT NULL DEFAULT false,
"allow_prompt_override" BOOLEAN NOT NULL DEFAULT false,
"show_thoughts" BOOLEAN NOT NULL DEFAULT true,
"max_chats_per_day" INTEGER,
"max_chats_per_session" INTEGER,
"workspace_id" INTEGER NOT NULL,
"createdBy" INTEGER,
"usersId" INTEGER,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "embed_configs_workspace_id_fkey" FOREIGN KEY ("workspace_id") REFERENCES "workspaces" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT "embed_configs_usersId_fkey" FOREIGN KEY ("usersId") REFERENCES "users" ("id") ON DELETE SET NULL ON UPDATE CASCADE
);
INSERT INTO "new_embed_configs" ("allow_model_override", "allow_prompt_override", "allow_temperature_override", "allowlist_domains", "chat_mode", "createdAt", "createdBy", "enabled", "id", "max_chats_per_day", "max_chats_per_session", "usersId", "uuid", "workspace_id") SELECT "allow_model_override", "allow_prompt_override", "allow_temperature_override", "allowlist_domains", "chat_mode", "createdAt", "createdBy", "enabled", "id", "max_chats_per_day", "max_chats_per_session", "usersId", "uuid", "workspace_id" FROM "embed_configs";
DROP TABLE "embed_configs";
ALTER TABLE "new_embed_configs" RENAME TO "embed_configs";
CREATE UNIQUE INDEX "embed_configs_uuid_key" ON "embed_configs"("uuid");
PRAGMA foreign_key_check;
PRAGMA foreign_keys=ON;
1 change: 1 addition & 0 deletions server/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ model embed_configs {
allow_model_override Boolean @default(false)
allow_temperature_override Boolean @default(false)
allow_prompt_override Boolean @default(false)
show_thoughts Boolean @default(true)
max_chats_per_day Int?
max_chats_per_session Int?
workspace_id Int
Expand Down