Skip to content

Commit e6c5d10

Browse files
committed
frontend: support chat engine's is_public field
1 parent d304352 commit e6c5d10

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

frontend/app/src/api/chat-engines.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export interface ChatEngine {
1313
fast_llm_id: number | null;
1414
reranker_id: number | null;
1515
is_default: boolean;
16+
is_public: boolean;
1617
}
1718

1819
export interface CreateChatEngineParams {
@@ -134,6 +135,7 @@ const chatEngineSchema = z.object({
134135
fast_llm_id: z.number().nullable(),
135136
reranker_id: z.number().nullable(),
136137
is_default: z.boolean(),
138+
is_public: z.boolean(),
137139
}) satisfies ZodType<ChatEngine, any, any>;
138140

139141
export async function getDefaultChatEngineOptions (): Promise<ChatEngineOptions> {

frontend/app/src/components/chat-engine/create-chat-engine-form.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { z } from 'zod';
2323

2424
const schema = z.object({
2525
name: z.string().min(1),
26+
is_public: z.boolean().optional(),
2627
llm_id: z.number().optional(),
2728
fast_llm_id: z.number().optional(),
2829
reranker_id: z.number().optional(),
@@ -42,6 +43,7 @@ const schema = z.object({
4243
const field = formFieldLayout<typeof schema>();
4344

4445
const nameSchema = z.string().min(1);
46+
const isPublicSchema = z.boolean();
4547
const kbSchema = z.object({ id: z.number() }).array().min(1);
4648
const kgGraphDepthSchema = z.number().min(1).optional();
4749

@@ -53,6 +55,9 @@ export function CreateChatEngineForm ({ defaultChatEngineOptions }: { defaultCha
5355

5456
const form = useForm({
5557
onSubmit: onSubmitHelper(schema, async data => {
58+
if (data.is_public == null) {
59+
data.is_public = true;
60+
}
5661
const ce = await createChatEngine(data);
5762
startTransition(() => {
5863
router.push(`/chat-engines/${ce.id}`);
@@ -85,6 +90,9 @@ export function CreateChatEngineForm ({ defaultChatEngineOptions }: { defaultCha
8590
<field.Basic required name="name" label="Name" defaultValue="" validators={{ onSubmit: nameSchema, onBlur: nameSchema }}>
8691
<FormInput placeholder="Enter chat engine name" />
8792
</field.Basic>
93+
<field.Contained name='is_public' label="Is Public" defaultValue={true}>
94+
<FormSwitch />
95+
</field.Contained>
8896
<SubSection title="Models">
8997
<field.Basic name="llm_id" label="LLM">
9098
<LLMSelect />
@@ -279,4 +287,4 @@ const llmPromptDescriptions: { [P in typeof llmPromptFields[number]]: string } =
279287
'clarifying_question_prompt': 'Prompt template for generating clarifying questions when the user\'s input needs more context or specificity',
280288
'generate_goal_prompt': 'Prompt template for generating conversation goals and objectives based on user input',
281289
'further_questions_prompt': 'Prompt template for generating follow-up questions to continue the conversation',
282-
};
290+
};

frontend/app/src/components/chat-engine/update-chat-engine-form.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ export function UpdateChatEngineForm ({ chatEngine, defaultChatEngineOptions }:
7474
<FormSwitch />
7575
</field.Contained>
7676
</GeneralSettingsField>
77+
<GeneralSettingsField accessor={isPublicAccessor} schema={isPublicSchema}>
78+
<field.Contained unimportant name="value" label="Is Public" fallbackValue={chatEngine.is_public}>
79+
<FormSwitch />
80+
</field.Contained>
81+
</GeneralSettingsField>
7782
<SubSection title="Models">
7883
<GeneralSettingsField accessor={llmIdAccessor} schema={idSchema}>
7984
<field.Basic name="value" label="LLM">
@@ -311,6 +316,9 @@ const clarifyAccessorSchema = z.boolean().nullable().optional();
311316
const isDefaultAccessor = fieldAccessor<ChatEngine, 'is_default'>('is_default');
312317
const isDefaultSchema = z.boolean();
313318

319+
const isPublicAccessor = fieldAccessor<ChatEngine, 'is_public'>('is_public');
320+
const isPublicSchema = z.boolean();
321+
314322
const getIdAccessor = (id: KeyOfType<ChatEngine, number | null>) => fieldAccessor<ChatEngine, KeyOfType<ChatEngine, number | null>>(id);
315323
const idSchema = z.number().nullable();
316324
const llmIdAccessor = getIdAccessor('llm_id');

frontend/app/src/components/chat/message-input.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ export function MessageInput ({
4141
onChangeRef.current?.(ev);
4242
}, []);
4343

44-
const showShowSelectChatEngine = !!auth.me?.is_superuser && !!onEngineChange;
4544
const { data, isLoading } = useAllChatEngines();
45+
const showShowSelectChatEngine = !!data?.length && !!onEngineChange;
4646

4747
return (
4848
<div className={cn('bg-background border p-2 rounded-lg', className)}>

0 commit comments

Comments
 (0)