feat: fixed the issue where chat greetings could not appear (#95)

This commit is contained in:
balibabu
2024-03-05 12:01:48 +08:00
committed by GitHub
parent eec529f8c5
commit 59d8442d0d
8 changed files with 56 additions and 18 deletions

View File

@ -5,20 +5,26 @@ type FieldType = {
vector_similarity_weight?: number; vector_similarity_weight?: number;
}; };
const SimilaritySlider = () => { interface IProps {
isTooltipShown?: boolean;
}
const SimilaritySlider = ({ isTooltipShown = false }: IProps) => {
return ( return (
<> <>
<Form.Item<FieldType> <Form.Item<FieldType>
label="Similarity threshold" label="Similarity threshold"
name={'similarity_threshold'} name={'similarity_threshold'}
initialValue={0} tooltip={isTooltipShown && 'xxx'}
initialValue={0.2}
> >
<Slider max={1} step={0.01} /> <Slider max={1} step={0.01} />
</Form.Item> </Form.Item>
<Form.Item<FieldType> <Form.Item<FieldType>
label="Vector similarity weight" label="Vector similarity weight"
name={'vector_similarity_weight'} name={'vector_similarity_weight'}
initialValue={0} initialValue={0.3}
tooltip={isTooltipShown && 'xxx'}
> >
<Slider max={1} step={0.01} /> <Slider max={1} step={0.01} />
</Form.Item> </Form.Item>

View File

@ -41,7 +41,8 @@ export const useGetChunkHighlights = (
const selectedChunk: IChunk = useGetSelectedChunk(selectedChunkId); const selectedChunk: IChunk = useGetSelectedChunk(selectedChunkId);
const highlights: IHighlight[] = useMemo(() => { 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) => { ? selectedChunk?.positions?.map((x) => {
const actualPositions = x.map((y, index) => const actualPositions = x.map((y, index) =>
index !== 0 ? y / 0.7 : y, index !== 0 ? y / 0.7 : y,

View File

@ -28,8 +28,8 @@ const segmentedMap = {
}; };
const layout = { const layout = {
labelCol: { span: 6 }, labelCol: { span: 7 },
wrapperCol: { span: 18 }, wrapperCol: { span: 17 },
}; };
const validateMessages = { const validateMessages = {

View File

@ -162,8 +162,13 @@ const PromptEngine = (
<Input.TextArea autoSize={{ maxRows: 8, minRows: 5 }} /> <Input.TextArea autoSize={{ maxRows: 8, minRows: 5 }} />
</Form.Item> </Form.Item>
<Divider></Divider> <Divider></Divider>
<SimilaritySlider></SimilaritySlider> <SimilaritySlider isTooltipShown></SimilaritySlider>
<Form.Item<FieldType> label="Top n" name={'top_n'} initialValue={0}> <Form.Item<FieldType>
label="Top n"
name={'top_n'}
initialValue={8}
tooltip={'xxx'}
>
<Slider max={30} /> <Slider max={30} />
</Form.Item> </Form.Item>
<section className={classNames(styles.variableContainer)}> <section className={classNames(styles.variableContainer)}>

View File

@ -1,7 +1,8 @@
.chatContainer { .chatContainer {
padding: 0 24px 24px; padding: 0 0 24px 24px;
.messageContainer { .messageContainer {
overflow-y: auto; overflow-y: auto;
padding-right: 24px;
} }
} }

View File

@ -145,7 +145,7 @@ const MessageItem = ({
<AssistantIcon></AssistantIcon> <AssistantIcon></AssistantIcon>
)} )}
<Flex vertical gap={8} flex={1}> <Flex vertical gap={8} flex={1}>
<b>{isAssistant ? 'Resume Assistant' : 'You'}</b> <b>{isAssistant ? '' : userInfo.nickname}</b>
<div className={styles.messageText}> <div className={styles.messageText}>
<Markdown <Markdown
rehypePlugins={[rehypeWrapReference]} rehypePlugins={[rehypeWrapReference]}

View File

@ -124,6 +124,14 @@ export const useSelectPromptConfigParameters = (): VariableTableDataType[] => {
return finalParameters; return finalParameters;
}; };
export const useSelectCurrentDialog = () => {
const currentDialog: IDialog = useSelector(
(state: any) => state.chatModel.currentDialog,
);
return currentDialog;
};
export const useRemoveDialog = () => { export const useRemoveDialog = () => {
const dispatch = useDispatch(); const dispatch = useDispatch();
@ -404,6 +412,8 @@ export const useSelectCurrentConversation = () => {
const conversation: IClientConversation = useSelector( const conversation: IClientConversation = useSelector(
(state: any) => state.chatModel.currentConversation, (state: any) => state.chatModel.currentConversation,
); );
const dialog = useSelectCurrentDialog();
const { conversationId } = useGetChatSearchParams();
const addNewestConversation = useCallback((message: string) => { const addNewestConversation = useCallback((message: string) => {
setCurrentConversation((pre) => { setCurrentConversation((pre) => {
@ -421,13 +431,30 @@ export const useSelectCurrentConversation = () => {
}); });
}, []); }, []);
useEffect(() => { const addPrologue = useCallback(() => {
console.info('useSelectCurrentConversation: 1', currentConversation); if (conversationId === '') {
}, [currentConversation]); 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(() => { useEffect(() => {
console.info('useSelectCurrentConversation: 2', conversation); addPrologue();
}, [addPrologue]);
useEffect(() => {
setCurrentConversation(conversation); setCurrentConversation(conversation);
}, [conversation]); }, [conversation]);
@ -472,7 +499,6 @@ export const useScrollToBottom = (currentConversation: IClientConversation) => {
export const useFetchConversationOnMount = () => { export const useFetchConversationOnMount = () => {
const { conversationId } = useGetChatSearchParams(); const { conversationId } = useGetChatSearchParams();
const setCurrentConversation = useSetCurrentConversation();
const fetchConversation = useFetchConversation(); const fetchConversation = useFetchConversation();
const { currentConversation, addNewestConversation } = const { currentConversation, addNewestConversation } =
useSelectCurrentConversation(); useSelectCurrentConversation();
@ -481,10 +507,8 @@ export const useFetchConversationOnMount = () => {
const fetchConversationOnMount = useCallback(() => { const fetchConversationOnMount = useCallback(() => {
if (isConversationIdExist(conversationId)) { if (isConversationIdExist(conversationId)) {
fetchConversation(conversationId); fetchConversation(conversationId);
} else {
setCurrentConversation({} as IClientConversation);
} }
}, [fetchConversation, setCurrentConversation, conversationId]); }, [fetchConversation, conversationId]);
useEffect(() => { useEffect(() => {
fetchConversationOnMount(); fetchConversationOnMount();

View File

@ -1,5 +1,6 @@
.chatWrapper { .chatWrapper {
height: 100%; height: 100%;
width: 100%;
.chatAppWrapper { .chatAppWrapper {
width: 288px; width: 288px;