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

feat: support hide sources #349

Merged
merged 1 commit into from
Oct 29, 2024
Merged
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
1 change: 1 addition & 0 deletions backend/app/rag/chat_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions frontend/app/src/api/chat-engines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -27,6 +29,13 @@ export function ChatEngineOptionsDetails ({
<ChatEngineLLMDetails editable={editable} options={options.llm} />
</section>
<Separator />
<section className="space-y-2">
<div className="text-base font-medium">UI</div>
<div className="space-y-2 text-sm">
<OptionDetail title="Hide Sources" value={options.hide_sources ? 'Enabled' : 'Disabled'} valueClassName={options.hide_sources ? 'text-green-500' : 'text-muted-foreground'} editPanel={editable && <EditOptionBooleanForm chatEngine={editable} property="hide_sources" />} />
</div>
</section>
<Separator />
<section className="space-y-2">
<div className="text-base font-medium">Post Verification</div>
<div className="space-y-2 text-sm">
Expand Down
Original file line number Diff line number Diff line change
@@ -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<T, Value> = keyof { [P in keyof T as T[P] extends Value ? P : never]: any }

export interface EditOptionBooleanFormProps<P extends KeyOfType<ChatEngineOptions, boolean | undefined | null>> {
property: P;
chatEngine: ChatEngine;
}

const booleanSchema = z.boolean();

export function EditOptionBooleanForm<P extends KeyOfType<ChatEngineOptions, boolean | undefined | null>> ({ property, chatEngine }: EditOptionBooleanFormProps<P>) {
const [refreshing, refresh] = useRefresh();

return (
<EditPropertyForm
inline
object={chatEngine.engine_options}
property={property}
schema={booleanSchema}
onSubmit={async (data) => {
const options = { ...chatEngine.engine_options, ...data };
await updateChatEngine(chatEngine.id, { engine_options: options });
refresh();
toast(`ChatEngine's option ${property} successfully updated.`);
}}
disabled={refreshing}
>
<FormSwitch />
</EditPropertyForm>
);
}
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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());

Expand Down Expand Up @@ -107,9 +108,9 @@ function ConversationMessageGroup ({ group, isLastGroup }: { group: ChatMessageG
{group.assistant?.version === 'Legacy' && <MessageAnnotationHistory message={group.assistant} />}
{group.assistant?.version === 'StackVM' && <StackVMMessageAnnotationHistory message={group.assistant} />}

<MessageSection className="!mt-1" message={group.assistant}>
{!engine_options?.hide_sources && <MessageSection className="!mt-1" message={group.assistant}>
<MessageContextSources message={group.assistant} />
</MessageSection>
</MessageSection>}

<MessageSection className="space-y-2" message={group.assistant}>
<MessageAnswer message={group.assistant} showBetaAlert={group.hasFirstAssistantMessage} />
Expand Down
Loading