From 92428b6f341ac1367f607f9480cdf9b540852a4e Mon Sep 17 00:00:00 2001 From: Jagger <634750802@qq.com> Date: Tue, 29 Oct 2024 14:02:25 +0800 Subject: [PATCH] feat: support hide sources --- backend/app/rag/chat_config.py | 1 + frontend/app/src/api/chat-engines.ts | 1 + .../chat-engine-options-details.tsx | 9 +++++ .../chat-engine/edit-option-boolean-form.tsx | 39 +++++++++++++++++++ .../chat/conversation-message-groups.tsx | 7 ++-- 5 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 frontend/app/src/components/chat-engine/edit-option-boolean-form.tsx diff --git a/backend/app/rag/chat_config.py b/backend/app/rag/chat_config.py index 3d193fd2..44657dd3 100644 --- a/backend/app/rag/chat_config.py +++ b/backend/app/rag/chat_config.py @@ -84,6 +84,7 @@ class ChatEngineConfig(BaseModel): post_verification_url: Optional[str] = None post_verification_token: Optional[str] = None external_engine_config: Optional[ExternalChatEngine] = None + hide_sources: bool = False _db_chat_engine: Optional[DBChatEngine] = None _db_llm: Optional[DBLLM] = None diff --git a/frontend/app/src/api/chat-engines.ts b/frontend/app/src/api/chat-engines.ts index 7d6e06fb..659192ee 100644 --- a/frontend/app/src/api/chat-engines.ts +++ b/frontend/app/src/api/chat-engines.ts @@ -21,6 +21,7 @@ export interface ChatEngineOptions { llm: ChatEngineLLMOptions; post_verification_url?: string | null; post_verification_token?: string | null; + hide_sources?: boolean | null; } export interface ChatEngineKnowledgeGraphOptions { diff --git a/frontend/app/src/components/chat-engine/chat-engine-options-details.tsx b/frontend/app/src/components/chat-engine/chat-engine-options-details.tsx index 3e8ed16e..66304d09 100644 --- a/frontend/app/src/components/chat-engine/chat-engine-options-details.tsx +++ b/frontend/app/src/components/chat-engine/chat-engine-options-details.tsx @@ -1,4 +1,6 @@ import type { ChatEngine, ChatEngineOptions } from '@/api/chat-engines'; +import { EditBooleanForm } from '@/components/chat-engine/edit-boolean-form'; +import { EditOptionBooleanForm } from '@/components/chat-engine/edit-option-boolean-form'; import { EditTokenForm } from '@/components/chat-engine/edit-token-form'; import { EditUrlForm } from '@/components/chat-engine/edit-url-form'; import { ChatEngineKnowledgeGraphDetails } from '@/components/chat-engine/knowledge-graph-details'; @@ -27,6 +29,13 @@ export function ChatEngineOptionsDetails ({ +
+
UI
+
+ } /> +
+
+
Post Verification
diff --git a/frontend/app/src/components/chat-engine/edit-option-boolean-form.tsx b/frontend/app/src/components/chat-engine/edit-option-boolean-form.tsx new file mode 100644 index 00000000..0af4839c --- /dev/null +++ b/frontend/app/src/components/chat-engine/edit-option-boolean-form.tsx @@ -0,0 +1,39 @@ +'use client'; + +import { type ChatEngine, type ChatEngineOptions, updateChatEngine } from '@/api/chat-engines'; +import { EditPropertyForm } from '@/components/chat-engine/edit-property-form'; +import { FormSwitch } from '@/components/form/control-widget'; +import { useRefresh } from '@/components/nextjs/app-router-hooks'; +import { toast } from 'sonner'; +import { z } from 'zod'; + +type KeyOfType = keyof { [P in keyof T as T[P] extends Value ? P : never]: any } + +export interface EditOptionBooleanFormProps

> { + property: P; + chatEngine: ChatEngine; +} + +const booleanSchema = z.boolean(); + +export function EditOptionBooleanForm

> ({ property, chatEngine }: EditOptionBooleanFormProps

) { + const [refreshing, refresh] = useRefresh(); + + return ( + { + const options = { ...chatEngine.engine_options, ...data }; + await updateChatEngine(chatEngine.id, { engine_options: options }); + refresh(); + toast(`ChatEngine's option ${property} successfully updated.`); + }} + disabled={refreshing} + > + + + ); +} diff --git a/frontend/app/src/components/chat/conversation-message-groups.tsx b/frontend/app/src/components/chat/conversation-message-groups.tsx index 82f65417..38b40a48 100644 --- a/frontend/app/src/components/chat/conversation-message-groups.tsx +++ b/frontend/app/src/components/chat/conversation-message-groups.tsx @@ -1,4 +1,4 @@ -import { type ChatMessageGroup, useChatPostState, useCurrentChatController } from '@/components/chat/chat-hooks'; +import { type ChatMessageGroup, useChatInfo, useChatPostState, useCurrentChatController } from '@/components/chat/chat-hooks'; import { DebugInfo } from '@/components/chat/debug-info'; import { MessageAnnotationHistory } from '@/components/chat/message-annotation-history'; import { StackVMMessageAnnotationHistory } from '@/components/chat/message-annotation-history-stackvm'; @@ -71,6 +71,7 @@ export function ConversationMessageGroups ({ groups }: { groups: ChatMessageGrou function ConversationMessageGroup ({ group, isLastGroup }: { group: ChatMessageGroup, isLastGroup: boolean }) { const enableDebug = /* !!me && */ !process.env.NEXT_PUBLIC_DISABLE_DEBUG_PANEL; + const { engine_options } = useChatInfo(useCurrentChatController()) ?? {}; const { params } = useChatPostState(useCurrentChatController()); @@ -107,9 +108,9 @@ function ConversationMessageGroup ({ group, isLastGroup }: { group: ChatMessageG {group.assistant?.version === 'Legacy' && } {group.assistant?.version === 'StackVM' && } - + {!engine_options?.hide_sources && - + }