Skip to content

Commit

Permalink
feat: fixed the issue where chat greetings could not appear (infinifl…
Browse files Browse the repository at this point in the history
  • Loading branch information
cike8899 authored Mar 5, 2024
1 parent a9e3dcb commit 830bf29
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 18 deletions.
12 changes: 9 additions & 3 deletions web/src/components/similarity-slider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,26 @@ type FieldType = {
vector_similarity_weight?: number;
};

const SimilaritySlider = () => {
interface IProps {
isTooltipShown?: boolean;
}

const SimilaritySlider = ({ isTooltipShown = false }: IProps) => {
return (
<>
<Form.Item<FieldType>
label="Similarity threshold"
name={'similarity_threshold'}
initialValue={0}
tooltip={isTooltipShown && 'xxx'}
initialValue={0.2}
>
<Slider max={1} step={0.01} />
</Form.Item>
<Form.Item<FieldType>
label="Vector similarity weight"
name={'vector_similarity_weight'}
initialValue={0}
initialValue={0.3}
tooltip={isTooltipShown && 'xxx'}
>
<Slider max={1} step={0.01} />
</Form.Item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions web/src/pages/chat/chat-configuration-modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ const segmentedMap = {
};

const layout = {
labelCol: { span: 6 },
wrapperCol: { span: 18 },
labelCol: { span: 7 },
wrapperCol: { span: 17 },
};

const validateMessages = {
Expand Down
9 changes: 7 additions & 2 deletions web/src/pages/chat/chat-configuration-modal/prompt-engine.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,13 @@ const PromptEngine = (
<Input.TextArea autoSize={{ maxRows: 8, minRows: 5 }} />
</Form.Item>
<Divider></Divider>
<SimilaritySlider></SimilaritySlider>
<Form.Item<FieldType> label="Top n" name={'top_n'} initialValue={0}>
<SimilaritySlider isTooltipShown></SimilaritySlider>
<Form.Item<FieldType>
label="Top n"
name={'top_n'}
initialValue={8}
tooltip={'xxx'}
>
<Slider max={30} />
</Form.Item>
<section className={classNames(styles.variableContainer)}>
Expand Down
3 changes: 2 additions & 1 deletion web/src/pages/chat/chat-container/index.less
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
.chatContainer {
padding: 0 24px 24px;
padding: 0 0 24px 24px;
.messageContainer {
overflow-y: auto;
padding-right: 24px;
}
}

Expand Down
2 changes: 1 addition & 1 deletion web/src/pages/chat/chat-container/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ const MessageItem = ({
<AssistantIcon></AssistantIcon>
)}
<Flex vertical gap={8} flex={1}>
<b>{isAssistant ? 'Resume Assistant' : 'You'}</b>
<b>{isAssistant ? '' : userInfo.nickname}</b>
<div className={styles.messageText}>
<Markdown
rehypePlugins={[rehypeWrapReference]}
Expand Down
40 changes: 32 additions & 8 deletions web/src/pages/chat/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,14 @@ export const useSelectPromptConfigParameters = (): VariableTableDataType[] => {
return finalParameters;
};

export const useSelectCurrentDialog = () => {
const currentDialog: IDialog = useSelector(
(state: any) => state.chatModel.currentDialog,
);

return currentDialog;
};

export const useRemoveDialog = () => {
const dispatch = useDispatch();

Expand Down Expand Up @@ -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) => {
Expand All @@ -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]);

Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down
1 change: 1 addition & 0 deletions web/src/pages/chat/index.less
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.chatWrapper {
height: 100%;
width: 100%;

.chatAppWrapper {
width: 288px;
Expand Down

0 comments on commit 830bf29

Please sign in to comment.