From 59d8442d0dddf70d2ec8bf9e701184f2181e7e12 Mon Sep 17 00:00:00 2001 From: balibabu Date: Tue, 5 Mar 2024 12:01:48 +0800 Subject: [PATCH] feat: fixed the issue where chat greetings could not appear (#95) --- .../components/similarity-slider/index.tsx | 12 ++++-- .../components/knowledge-chunk/hooks.ts | 3 +- .../chat/chat-configuration-modal/index.tsx | 4 +- .../prompt-engine.tsx | 9 ++++- web/src/pages/chat/chat-container/index.less | 3 +- web/src/pages/chat/chat-container/index.tsx | 2 +- web/src/pages/chat/hooks.ts | 40 +++++++++++++++---- web/src/pages/chat/index.less | 1 + 8 files changed, 56 insertions(+), 18 deletions(-) diff --git a/web/src/components/similarity-slider/index.tsx b/web/src/components/similarity-slider/index.tsx index 966ed212e5..1c5d49be6e 100644 --- a/web/src/components/similarity-slider/index.tsx +++ b/web/src/components/similarity-slider/index.tsx @@ -5,20 +5,26 @@ type FieldType = { vector_similarity_weight?: number; }; -const SimilaritySlider = () => { +interface IProps { + isTooltipShown?: boolean; +} + +const SimilaritySlider = ({ isTooltipShown = false }: IProps) => { return ( <> label="Similarity threshold" name={'similarity_threshold'} - initialValue={0} + tooltip={isTooltipShown && 'xxx'} + initialValue={0.2} > label="Vector similarity weight" name={'vector_similarity_weight'} - initialValue={0} + initialValue={0.3} + tooltip={isTooltipShown && 'xxx'} > diff --git a/web/src/pages/add-knowledge/components/knowledge-chunk/hooks.ts b/web/src/pages/add-knowledge/components/knowledge-chunk/hooks.ts index 64a130cc80..aad1dd083b 100644 --- a/web/src/pages/add-knowledge/components/knowledge-chunk/hooks.ts +++ b/web/src/pages/add-knowledge/components/knowledge-chunk/hooks.ts @@ -41,7 +41,8 @@ export const useGetChunkHighlights = ( const selectedChunk: IChunk = useGetSelectedChunk(selectedChunkId); const highlights: IHighlight[] = useMemo(() => { - return Array.isArray(selectedChunk?.positions) + return Array.isArray(selectedChunk?.positions) && + selectedChunk.positions.every((x) => Array.isArray(x)) ? selectedChunk?.positions?.map((x) => { const actualPositions = x.map((y, index) => index !== 0 ? y / 0.7 : y, diff --git a/web/src/pages/chat/chat-configuration-modal/index.tsx b/web/src/pages/chat/chat-configuration-modal/index.tsx index 546e39dad8..fcc38e220c 100644 --- a/web/src/pages/chat/chat-configuration-modal/index.tsx +++ b/web/src/pages/chat/chat-configuration-modal/index.tsx @@ -28,8 +28,8 @@ const segmentedMap = { }; const layout = { - labelCol: { span: 6 }, - wrapperCol: { span: 18 }, + labelCol: { span: 7 }, + wrapperCol: { span: 17 }, }; const validateMessages = { diff --git a/web/src/pages/chat/chat-configuration-modal/prompt-engine.tsx b/web/src/pages/chat/chat-configuration-modal/prompt-engine.tsx index f6bd1c5375..b8e46d32bb 100644 --- a/web/src/pages/chat/chat-configuration-modal/prompt-engine.tsx +++ b/web/src/pages/chat/chat-configuration-modal/prompt-engine.tsx @@ -162,8 +162,13 @@ const PromptEngine = ( - - label="Top n" name={'top_n'} initialValue={0}> + + + label="Top n" + name={'top_n'} + initialValue={8} + tooltip={'xxx'} + >
diff --git a/web/src/pages/chat/chat-container/index.less b/web/src/pages/chat/chat-container/index.less index ac42b3ef3d..db2a86030c 100644 --- a/web/src/pages/chat/chat-container/index.less +++ b/web/src/pages/chat/chat-container/index.less @@ -1,7 +1,8 @@ .chatContainer { - padding: 0 24px 24px; + padding: 0 0 24px 24px; .messageContainer { overflow-y: auto; + padding-right: 24px; } } diff --git a/web/src/pages/chat/chat-container/index.tsx b/web/src/pages/chat/chat-container/index.tsx index a0713032cf..1019e648ff 100644 --- a/web/src/pages/chat/chat-container/index.tsx +++ b/web/src/pages/chat/chat-container/index.tsx @@ -145,7 +145,7 @@ const MessageItem = ({ )} - {isAssistant ? 'Resume Assistant' : 'You'} + {isAssistant ? '' : userInfo.nickname}
{ return finalParameters; }; +export const useSelectCurrentDialog = () => { + const currentDialog: IDialog = useSelector( + (state: any) => state.chatModel.currentDialog, + ); + + return currentDialog; +}; + export const useRemoveDialog = () => { const dispatch = useDispatch(); @@ -404,6 +412,8 @@ export const useSelectCurrentConversation = () => { const conversation: IClientConversation = useSelector( (state: any) => state.chatModel.currentConversation, ); + const dialog = useSelectCurrentDialog(); + const { conversationId } = useGetChatSearchParams(); const addNewestConversation = useCallback((message: string) => { setCurrentConversation((pre) => { @@ -421,13 +431,30 @@ export const useSelectCurrentConversation = () => { }); }, []); - useEffect(() => { - console.info('useSelectCurrentConversation: 1', currentConversation); - }, [currentConversation]); + const addPrologue = useCallback(() => { + if (conversationId === '') { + const prologue = dialog.prompt_config?.prologue; + + const nextMessage = { + role: MessageType.Assistant, + content: prologue, + id: uuid(), + } as IMessage; + + setCurrentConversation({ + id: '', + dialog_id: dialog.id, + reference: [], + message: [nextMessage], + } as any); + } + }, [conversationId, dialog]); useEffect(() => { - console.info('useSelectCurrentConversation: 2', conversation); + addPrologue(); + }, [addPrologue]); + useEffect(() => { setCurrentConversation(conversation); }, [conversation]); @@ -472,7 +499,6 @@ export const useScrollToBottom = (currentConversation: IClientConversation) => { export const useFetchConversationOnMount = () => { const { conversationId } = useGetChatSearchParams(); - const setCurrentConversation = useSetCurrentConversation(); const fetchConversation = useFetchConversation(); const { currentConversation, addNewestConversation } = useSelectCurrentConversation(); @@ -481,10 +507,8 @@ export const useFetchConversationOnMount = () => { const fetchConversationOnMount = useCallback(() => { if (isConversationIdExist(conversationId)) { fetchConversation(conversationId); - } else { - setCurrentConversation({} as IClientConversation); } - }, [fetchConversation, setCurrentConversation, conversationId]); + }, [fetchConversation, conversationId]); useEffect(() => { fetchConversationOnMount(); diff --git a/web/src/pages/chat/index.less b/web/src/pages/chat/index.less index e3b5f89949..cb1546f203 100644 --- a/web/src/pages/chat/index.less +++ b/web/src/pages/chat/index.less @@ -1,5 +1,6 @@ .chatWrapper { height: 100%; + width: 100%; .chatAppWrapper { width: 288px;