balibabu
commited on
Commit
·
830bf29
1
Parent(s):
a9e3dcb
feat: fixed the issue where chat greetings could not appear (#95)
Browse files- web/src/components/similarity-slider/index.tsx +9 -3
- web/src/pages/add-knowledge/components/knowledge-chunk/hooks.ts +2 -1
- web/src/pages/chat/chat-configuration-modal/index.tsx +2 -2
- web/src/pages/chat/chat-configuration-modal/prompt-engine.tsx +7 -2
- web/src/pages/chat/chat-container/index.less +2 -1
- web/src/pages/chat/chat-container/index.tsx +1 -1
- web/src/pages/chat/hooks.ts +32 -8
- web/src/pages/chat/index.less +1 -0
web/src/components/similarity-slider/index.tsx
CHANGED
|
@@ -5,20 +5,26 @@ type FieldType = {
|
|
| 5 |
vector_similarity_weight?: number;
|
| 6 |
};
|
| 7 |
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
return (
|
| 10 |
<>
|
| 11 |
<Form.Item<FieldType>
|
| 12 |
label="Similarity threshold"
|
| 13 |
name={'similarity_threshold'}
|
| 14 |
-
|
|
|
|
| 15 |
>
|
| 16 |
<Slider max={1} step={0.01} />
|
| 17 |
</Form.Item>
|
| 18 |
<Form.Item<FieldType>
|
| 19 |
label="Vector similarity weight"
|
| 20 |
name={'vector_similarity_weight'}
|
| 21 |
-
initialValue={0}
|
|
|
|
| 22 |
>
|
| 23 |
<Slider max={1} step={0.01} />
|
| 24 |
</Form.Item>
|
|
|
|
| 5 |
vector_similarity_weight?: number;
|
| 6 |
};
|
| 7 |
|
| 8 |
+
interface IProps {
|
| 9 |
+
isTooltipShown?: boolean;
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
const SimilaritySlider = ({ isTooltipShown = false }: IProps) => {
|
| 13 |
return (
|
| 14 |
<>
|
| 15 |
<Form.Item<FieldType>
|
| 16 |
label="Similarity threshold"
|
| 17 |
name={'similarity_threshold'}
|
| 18 |
+
tooltip={isTooltipShown && 'xxx'}
|
| 19 |
+
initialValue={0.2}
|
| 20 |
>
|
| 21 |
<Slider max={1} step={0.01} />
|
| 22 |
</Form.Item>
|
| 23 |
<Form.Item<FieldType>
|
| 24 |
label="Vector similarity weight"
|
| 25 |
name={'vector_similarity_weight'}
|
| 26 |
+
initialValue={0.3}
|
| 27 |
+
tooltip={isTooltipShown && 'xxx'}
|
| 28 |
>
|
| 29 |
<Slider max={1} step={0.01} />
|
| 30 |
</Form.Item>
|
web/src/pages/add-knowledge/components/knowledge-chunk/hooks.ts
CHANGED
|
@@ -41,7 +41,8 @@ export const useGetChunkHighlights = (
|
|
| 41 |
const selectedChunk: IChunk = useGetSelectedChunk(selectedChunkId);
|
| 42 |
|
| 43 |
const highlights: IHighlight[] = useMemo(() => {
|
| 44 |
-
return Array.isArray(selectedChunk?.positions)
|
|
|
|
| 45 |
? selectedChunk?.positions?.map((x) => {
|
| 46 |
const actualPositions = x.map((y, index) =>
|
| 47 |
index !== 0 ? y / 0.7 : y,
|
|
|
|
| 41 |
const selectedChunk: IChunk = useGetSelectedChunk(selectedChunkId);
|
| 42 |
|
| 43 |
const highlights: IHighlight[] = useMemo(() => {
|
| 44 |
+
return Array.isArray(selectedChunk?.positions) &&
|
| 45 |
+
selectedChunk.positions.every((x) => Array.isArray(x))
|
| 46 |
? selectedChunk?.positions?.map((x) => {
|
| 47 |
const actualPositions = x.map((y, index) =>
|
| 48 |
index !== 0 ? y / 0.7 : y,
|
web/src/pages/chat/chat-configuration-modal/index.tsx
CHANGED
|
@@ -28,8 +28,8 @@ const segmentedMap = {
|
|
| 28 |
};
|
| 29 |
|
| 30 |
const layout = {
|
| 31 |
-
labelCol: { span:
|
| 32 |
-
wrapperCol: { span:
|
| 33 |
};
|
| 34 |
|
| 35 |
const validateMessages = {
|
|
|
|
| 28 |
};
|
| 29 |
|
| 30 |
const layout = {
|
| 31 |
+
labelCol: { span: 7 },
|
| 32 |
+
wrapperCol: { span: 17 },
|
| 33 |
};
|
| 34 |
|
| 35 |
const validateMessages = {
|
web/src/pages/chat/chat-configuration-modal/prompt-engine.tsx
CHANGED
|
@@ -162,8 +162,13 @@ const PromptEngine = (
|
|
| 162 |
<Input.TextArea autoSize={{ maxRows: 8, minRows: 5 }} />
|
| 163 |
</Form.Item>
|
| 164 |
<Divider></Divider>
|
| 165 |
-
<SimilaritySlider></SimilaritySlider>
|
| 166 |
-
<Form.Item<FieldType>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 167 |
<Slider max={30} />
|
| 168 |
</Form.Item>
|
| 169 |
<section className={classNames(styles.variableContainer)}>
|
|
|
|
| 162 |
<Input.TextArea autoSize={{ maxRows: 8, minRows: 5 }} />
|
| 163 |
</Form.Item>
|
| 164 |
<Divider></Divider>
|
| 165 |
+
<SimilaritySlider isTooltipShown></SimilaritySlider>
|
| 166 |
+
<Form.Item<FieldType>
|
| 167 |
+
label="Top n"
|
| 168 |
+
name={'top_n'}
|
| 169 |
+
initialValue={8}
|
| 170 |
+
tooltip={'xxx'}
|
| 171 |
+
>
|
| 172 |
<Slider max={30} />
|
| 173 |
</Form.Item>
|
| 174 |
<section className={classNames(styles.variableContainer)}>
|
web/src/pages/chat/chat-container/index.less
CHANGED
|
@@ -1,7 +1,8 @@
|
|
| 1 |
.chatContainer {
|
| 2 |
-
padding: 0 24px 24px;
|
| 3 |
.messageContainer {
|
| 4 |
overflow-y: auto;
|
|
|
|
| 5 |
}
|
| 6 |
}
|
| 7 |
|
|
|
|
| 1 |
.chatContainer {
|
| 2 |
+
padding: 0 0 24px 24px;
|
| 3 |
.messageContainer {
|
| 4 |
overflow-y: auto;
|
| 5 |
+
padding-right: 24px;
|
| 6 |
}
|
| 7 |
}
|
| 8 |
|
web/src/pages/chat/chat-container/index.tsx
CHANGED
|
@@ -145,7 +145,7 @@ const MessageItem = ({
|
|
| 145 |
<AssistantIcon></AssistantIcon>
|
| 146 |
)}
|
| 147 |
<Flex vertical gap={8} flex={1}>
|
| 148 |
-
<b>{isAssistant ? '
|
| 149 |
<div className={styles.messageText}>
|
| 150 |
<Markdown
|
| 151 |
rehypePlugins={[rehypeWrapReference]}
|
|
|
|
| 145 |
<AssistantIcon></AssistantIcon>
|
| 146 |
)}
|
| 147 |
<Flex vertical gap={8} flex={1}>
|
| 148 |
+
<b>{isAssistant ? '' : userInfo.nickname}</b>
|
| 149 |
<div className={styles.messageText}>
|
| 150 |
<Markdown
|
| 151 |
rehypePlugins={[rehypeWrapReference]}
|
web/src/pages/chat/hooks.ts
CHANGED
|
@@ -124,6 +124,14 @@ export const useSelectPromptConfigParameters = (): VariableTableDataType[] => {
|
|
| 124 |
return finalParameters;
|
| 125 |
};
|
| 126 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
export const useRemoveDialog = () => {
|
| 128 |
const dispatch = useDispatch();
|
| 129 |
|
|
@@ -404,6 +412,8 @@ export const useSelectCurrentConversation = () => {
|
|
| 404 |
const conversation: IClientConversation = useSelector(
|
| 405 |
(state: any) => state.chatModel.currentConversation,
|
| 406 |
);
|
|
|
|
|
|
|
| 407 |
|
| 408 |
const addNewestConversation = useCallback((message: string) => {
|
| 409 |
setCurrentConversation((pre) => {
|
|
@@ -421,13 +431,30 @@ export const useSelectCurrentConversation = () => {
|
|
| 421 |
});
|
| 422 |
}, []);
|
| 423 |
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 427 |
|
| 428 |
useEffect(() => {
|
| 429 |
-
|
|
|
|
| 430 |
|
|
|
|
| 431 |
setCurrentConversation(conversation);
|
| 432 |
}, [conversation]);
|
| 433 |
|
|
@@ -472,7 +499,6 @@ export const useScrollToBottom = (currentConversation: IClientConversation) => {
|
|
| 472 |
|
| 473 |
export const useFetchConversationOnMount = () => {
|
| 474 |
const { conversationId } = useGetChatSearchParams();
|
| 475 |
-
const setCurrentConversation = useSetCurrentConversation();
|
| 476 |
const fetchConversation = useFetchConversation();
|
| 477 |
const { currentConversation, addNewestConversation } =
|
| 478 |
useSelectCurrentConversation();
|
|
@@ -481,10 +507,8 @@ export const useFetchConversationOnMount = () => {
|
|
| 481 |
const fetchConversationOnMount = useCallback(() => {
|
| 482 |
if (isConversationIdExist(conversationId)) {
|
| 483 |
fetchConversation(conversationId);
|
| 484 |
-
} else {
|
| 485 |
-
setCurrentConversation({} as IClientConversation);
|
| 486 |
}
|
| 487 |
-
}, [fetchConversation,
|
| 488 |
|
| 489 |
useEffect(() => {
|
| 490 |
fetchConversationOnMount();
|
|
|
|
| 124 |
return finalParameters;
|
| 125 |
};
|
| 126 |
|
| 127 |
+
export const useSelectCurrentDialog = () => {
|
| 128 |
+
const currentDialog: IDialog = useSelector(
|
| 129 |
+
(state: any) => state.chatModel.currentDialog,
|
| 130 |
+
);
|
| 131 |
+
|
| 132 |
+
return currentDialog;
|
| 133 |
+
};
|
| 134 |
+
|
| 135 |
export const useRemoveDialog = () => {
|
| 136 |
const dispatch = useDispatch();
|
| 137 |
|
|
|
|
| 412 |
const conversation: IClientConversation = useSelector(
|
| 413 |
(state: any) => state.chatModel.currentConversation,
|
| 414 |
);
|
| 415 |
+
const dialog = useSelectCurrentDialog();
|
| 416 |
+
const { conversationId } = useGetChatSearchParams();
|
| 417 |
|
| 418 |
const addNewestConversation = useCallback((message: string) => {
|
| 419 |
setCurrentConversation((pre) => {
|
|
|
|
| 431 |
});
|
| 432 |
}, []);
|
| 433 |
|
| 434 |
+
const addPrologue = useCallback(() => {
|
| 435 |
+
if (conversationId === '') {
|
| 436 |
+
const prologue = dialog.prompt_config?.prologue;
|
| 437 |
+
|
| 438 |
+
const nextMessage = {
|
| 439 |
+
role: MessageType.Assistant,
|
| 440 |
+
content: prologue,
|
| 441 |
+
id: uuid(),
|
| 442 |
+
} as IMessage;
|
| 443 |
+
|
| 444 |
+
setCurrentConversation({
|
| 445 |
+
id: '',
|
| 446 |
+
dialog_id: dialog.id,
|
| 447 |
+
reference: [],
|
| 448 |
+
message: [nextMessage],
|
| 449 |
+
} as any);
|
| 450 |
+
}
|
| 451 |
+
}, [conversationId, dialog]);
|
| 452 |
|
| 453 |
useEffect(() => {
|
| 454 |
+
addPrologue();
|
| 455 |
+
}, [addPrologue]);
|
| 456 |
|
| 457 |
+
useEffect(() => {
|
| 458 |
setCurrentConversation(conversation);
|
| 459 |
}, [conversation]);
|
| 460 |
|
|
|
|
| 499 |
|
| 500 |
export const useFetchConversationOnMount = () => {
|
| 501 |
const { conversationId } = useGetChatSearchParams();
|
|
|
|
| 502 |
const fetchConversation = useFetchConversation();
|
| 503 |
const { currentConversation, addNewestConversation } =
|
| 504 |
useSelectCurrentConversation();
|
|
|
|
| 507 |
const fetchConversationOnMount = useCallback(() => {
|
| 508 |
if (isConversationIdExist(conversationId)) {
|
| 509 |
fetchConversation(conversationId);
|
|
|
|
|
|
|
| 510 |
}
|
| 511 |
+
}, [fetchConversation, conversationId]);
|
| 512 |
|
| 513 |
useEffect(() => {
|
| 514 |
fetchConversationOnMount();
|
web/src/pages/chat/index.less
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
.chatWrapper {
|
| 2 |
height: 100%;
|
|
|
|
| 3 |
|
| 4 |
.chatAppWrapper {
|
| 5 |
width: 288px;
|
|
|
|
| 1 |
.chatWrapper {
|
| 2 |
height: 100%;
|
| 3 |
+
width: 100%;
|
| 4 |
|
| 5 |
.chatAppWrapper {
|
| 6 |
width: 288px;
|