Skip to content

Commit 82da180

Browse files
committed
🔧(backend) make frontend ai bot configurable
We make the AI bot configurable with settings. We will be able to have different AI bot name per instance.
1 parent e24dcc3 commit 82da180

File tree

7 files changed

+30
-13
lines changed

7 files changed

+30
-13
lines changed

docs/env.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ These are the environment variables you can set for the `impress-backend` contai
8282
| ALLOW_LOGOUT_GET_METHOD | Allow get logout method | true |
8383
| AI_API_KEY | AI key to be used for AI Base url | |
8484
| AI_BASE_URL | OpenAI compatible AI base url | |
85+
| AI_BOT | Information to give to the frontend about the AI bot | { "name": "Docs AI", "color": "#8bc6ff" } |
8586
| AI_MODEL | AI Model to use | |
8687
| AI_ALLOW_REACH_FROM | Users that can use AI must be this level. options are "public", "authenticated", "restricted" | authenticated |
8788
| AI_FEATURE_ENABLED | Enable AI options | false |

src/backend/core/api/viewsets.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1805,6 +1805,7 @@ def get(self, request):
18051805
Return a dictionary of public settings.
18061806
"""
18071807
array_settings = [
1808+
"AI_BOT",
18081809
"AI_FEATURE_ENABLED",
18091810
"COLLABORATION_WS_URL",
18101811
"COLLABORATION_WS_NOT_CONNECTED_READY_ONLY",

src/backend/core/tests/test_api_config.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919

2020
@override_settings(
21+
AI_BOT={"name": "Test Bot", "color": "#000000"},
2122
AI_FEATURE_ENABLED=False,
2223
COLLABORATION_WS_URL="http://testcollab/",
2324
COLLABORATION_WS_NOT_CONNECTED_READY_ONLY=True,
@@ -41,6 +42,8 @@ def test_api_config(is_authenticated):
4142
response = client.get("/api/v1.0/config/")
4243
assert response.status_code == HTTP_200_OK
4344
assert response.json() == {
45+
"AI_BOT": {"name": "Test Bot", "color": "#000000"},
46+
"AI_FEATURE_ENABLED": False,
4447
"COLLABORATION_WS_URL": "http://testcollab/",
4548
"COLLABORATION_WS_NOT_CONNECTED_READY_ONLY": True,
4649
"CRISP_WEBSITE_ID": "123",
@@ -59,7 +62,6 @@ def test_api_config(is_authenticated):
5962
"MEDIA_BASE_URL": "http://testserver/",
6063
"POSTHOG_KEY": {"id": "132456", "host": "https://eu.i.posthog-test.com"},
6164
"SENTRY_DSN": "https://sentry.test/123",
62-
"AI_FEATURE_ENABLED": False,
6365
"theme_customization": {},
6466
}
6567

src/backend/impress/settings.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -593,24 +593,32 @@ class Base(Configuration):
593593
default=True, environ_name="ALLOW_LOGOUT_GET_METHOD", environ_prefix=None
594594
)
595595

596-
# AI service
597-
AI_FEATURE_ENABLED = values.BooleanValue(
598-
default=False, environ_name="AI_FEATURE_ENABLED", environ_prefix=None
599-
)
600-
AI_API_KEY = values.Value(None, environ_name="AI_API_KEY", environ_prefix=None)
601-
AI_BASE_URL = values.Value(None, environ_name="AI_BASE_URL", environ_prefix=None)
602-
AI_MODEL = values.Value(None, environ_name="AI_MODEL", environ_prefix=None)
596+
# AI settings
603597
AI_ALLOW_REACH_FROM = values.Value(
604598
choices=("public", "authenticated", "restricted"),
605599
default="authenticated",
606600
environ_name="AI_ALLOW_REACH_FROM",
607601
environ_prefix=None,
608602
)
603+
AI_API_KEY = values.Value(None, environ_name="AI_API_KEY", environ_prefix=None)
604+
AI_BASE_URL = values.Value(None, environ_name="AI_BASE_URL", environ_prefix=None)
605+
AI_BOT = values.DictValue(
606+
default={
607+
"name": _("Docs AI"),
608+
"color": "#8bc6ff",
609+
},
610+
environ_name="AI_BOT",
611+
environ_prefix=None,
612+
)
609613
AI_DOCUMENT_RATE_THROTTLE_RATES = {
610614
"minute": 5,
611615
"hour": 100,
612616
"day": 500,
613617
}
618+
AI_FEATURE_ENABLED = values.BooleanValue(
619+
default=False, environ_name="AI_FEATURE_ENABLED", environ_prefix=None
620+
)
621+
AI_MODEL = values.Value(None, environ_name="AI_MODEL", environ_prefix=None)
614622
AI_USER_RATE_THROTTLE_RATES = {
615623
"minute": 3,
616624
"hour": 50,

src/frontend/apps/e2e/__tests__/app-impress/common.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { Page, expect } from '@playwright/test';
22

33
export const CONFIG = {
4+
AI_BOT: {
5+
name: 'Docs AI',
6+
color: '#8bc6ff',
7+
},
48
AI_FEATURE_ENABLED: true,
59
CRISP_WEBSITE_ID: null,
610
COLLABORATION_WS_URL: 'ws://localhost:4444/collaboration/ws/',

src/frontend/apps/impress/src/core/config/api/useConfig.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ interface ThemeCustomization {
1212
}
1313

1414
export interface ConfigResponse {
15+
AI_BOT: { name: string; color: string };
1516
AI_FEATURE_ENABLED?: boolean;
1617
COLLABORATION_WS_URL?: string;
1718
COLLABORATION_WS_NOT_CONNECTED_READY_ONLY?: boolean;

src/frontend/apps/impress/src/features/docs/doc-editor/components/AI/useAI.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { CoreMessage } from 'ai';
88
import { useMemo } from 'react';
99

1010
import { fetchAPI } from '@/api';
11+
import { useConfig } from '@/core';
1112
import { Doc } from '@/docs/doc-management';
1213

1314
const systemPrompts: Record<
@@ -47,6 +48,8 @@ const client = createBlockNoteAIClient({
4748
* Custom prompts can be invoked using the pattern !promptName in the AI input field.
4849
*/
4950
export const useAI = (docId: Doc['id']) => {
51+
const agentCursor = useConfig().data?.AI_BOT;
52+
5053
return useMemo(() => {
5154
const openai = createOpenAI({
5255
...client.getProviderSettings('openai'),
@@ -66,10 +69,7 @@ export const useAI = (docId: Doc['id']) => {
6669
const extension = createAIExtension({
6770
stream: false,
6871
model,
69-
agentCursor: {
70-
name: 'Albert',
71-
color: '#8bc6ff',
72-
},
72+
agentCursor,
7373
// Create a custom promptBuilder that extends the default one
7474
promptBuilder: async (editor, opts): Promise<Array<CoreMessage>> => {
7575
const defaultPromptBuilder = llmFormats.html.defaultPromptBuilder;
@@ -107,5 +107,5 @@ export const useAI = (docId: Doc['id']) => {
107107
});
108108

109109
return extension;
110-
}, [docId]);
110+
}, [agentCursor, docId]);
111111
};

0 commit comments

Comments
 (0)