feat: fetch knowledge detail on KnowledgeUploadFile mount and add category column to chunk table and set initial value for the model field of chat setting (#104)
* feat: set initial value for the model field of chat setting * feat: add category column to chunk table * feat: fetch knowledge detail on KnowledgeUploadFile mount
This commit is contained in:
18
web/src/pages/chat/chat-configuration-modal/hooks.ts
Normal file
18
web/src/pages/chat/chat-configuration-modal/hooks.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import {
|
||||
useFetchTenantInfo,
|
||||
useSelectTenantInfo,
|
||||
} from '@/hooks/userSettingHook';
|
||||
import { useEffect } from 'react';
|
||||
|
||||
export const useFetchModelId = (visible: boolean) => {
|
||||
const fetchTenantInfo = useFetchTenantInfo(false);
|
||||
const tenantInfo = useSelectTenantInfo();
|
||||
|
||||
useEffect(() => {
|
||||
if (visible) {
|
||||
fetchTenantInfo();
|
||||
}
|
||||
}, [visible, fetchTenantInfo]);
|
||||
|
||||
return tenantInfo?.llm_id ?? '';
|
||||
};
|
||||
@@ -13,6 +13,7 @@ import { variableEnabledFieldMap } from '../constants';
|
||||
import { useFetchDialog, useResetCurrentDialog, useSetDialog } from '../hooks';
|
||||
import { IPromptConfigParameters } from '../interface';
|
||||
import { excludeUnEnabledVariables } from '../utils';
|
||||
import { useFetchModelId } from './hooks';
|
||||
import styles from './index.less';
|
||||
|
||||
enum ConfigurationSegmented {
|
||||
@@ -54,6 +55,7 @@ const ChatConfigurationModal = ({ visible, hideModal, id }: IProps) => {
|
||||
);
|
||||
const promptEngineRef = useRef<Array<IPromptConfigParameters>>([]);
|
||||
const loading = useOneNamespaceEffectsLoading('chatModel', ['setDialog']);
|
||||
const modelId = useFetchModelId(visible);
|
||||
|
||||
const setDialog = useSetDialog();
|
||||
const currentDialog = useFetchDialog(id, visible);
|
||||
@@ -128,9 +130,13 @@ const ChatConfigurationModal = ({ visible, hideModal, id }: IProps) => {
|
||||
if (icon) {
|
||||
fileList = [{ uid: '1', name: 'file', thumbUrl: icon, status: 'done' }];
|
||||
}
|
||||
form.setFieldsValue({ ...currentDialog, icon: fileList });
|
||||
form.setFieldsValue({
|
||||
...currentDialog,
|
||||
icon: fileList,
|
||||
llm_id: currentDialog.llm_id ?? modelId,
|
||||
});
|
||||
}
|
||||
}, [currentDialog, form, visible]);
|
||||
}, [currentDialog, form, visible, modelId]);
|
||||
|
||||
return (
|
||||
<Modal
|
||||
|
||||
@@ -10,7 +10,7 @@ import omit from 'lodash/omit';
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { useDispatch, useSearchParams, useSelector } from 'umi';
|
||||
import { v4 as uuid } from 'uuid';
|
||||
import { ChatSearchParams, EmptyConversationId } from './constants';
|
||||
import { ChatSearchParams } from './constants';
|
||||
import {
|
||||
IClientConversation,
|
||||
IMessage,
|
||||
@@ -233,75 +233,6 @@ export const useHandleItemHover = () => {
|
||||
|
||||
//#region conversation
|
||||
|
||||
export const useCreateTemporaryConversation = () => {
|
||||
const dispatch = useDispatch();
|
||||
const { dialogId } = useGetChatSearchParams();
|
||||
const { handleClickConversation } = useClickConversationCard();
|
||||
let chatModel = useSelector((state: any) => state.chatModel);
|
||||
|
||||
const currentConversation: Pick<
|
||||
IClientConversation,
|
||||
'id' | 'message' | 'name' | 'dialog_id'
|
||||
> = chatModel.currentConversation;
|
||||
|
||||
const conversationList: IClientConversation[] = chatModel.conversationList;
|
||||
const currentDialog: IDialog = chatModel.currentDialog;
|
||||
|
||||
const setCurrentConversation = useSetCurrentConversation();
|
||||
|
||||
const createTemporaryConversation = useCallback(() => {
|
||||
const firstConversation = conversationList[0];
|
||||
const messages = [...(firstConversation?.message ?? [])];
|
||||
if (messages.some((x) => x.id === EmptyConversationId)) {
|
||||
return;
|
||||
}
|
||||
messages.push({
|
||||
id: EmptyConversationId,
|
||||
content: currentDialog?.prompt_config?.prologue ?? '',
|
||||
role: MessageType.Assistant,
|
||||
});
|
||||
|
||||
let nextCurrentConversation = currentConversation;
|
||||
|
||||
// It’s the back-end data.
|
||||
if ('id' in currentConversation) {
|
||||
nextCurrentConversation = { ...currentConversation, message: messages };
|
||||
} else {
|
||||
// client data
|
||||
nextCurrentConversation = {
|
||||
id: EmptyConversationId,
|
||||
name: 'New conversation',
|
||||
dialog_id: dialogId,
|
||||
message: messages,
|
||||
};
|
||||
}
|
||||
|
||||
const nextConversationList = [...conversationList];
|
||||
|
||||
nextConversationList.unshift(
|
||||
nextCurrentConversation as IClientConversation,
|
||||
);
|
||||
|
||||
setCurrentConversation(nextCurrentConversation as IClientConversation);
|
||||
|
||||
dispatch({
|
||||
type: 'chatModel/setConversationList',
|
||||
payload: nextConversationList,
|
||||
});
|
||||
handleClickConversation(EmptyConversationId);
|
||||
}, [
|
||||
dispatch,
|
||||
currentConversation,
|
||||
dialogId,
|
||||
setCurrentConversation,
|
||||
handleClickConversation,
|
||||
conversationList,
|
||||
currentDialog,
|
||||
]);
|
||||
|
||||
return { createTemporaryConversation };
|
||||
};
|
||||
|
||||
export const useFetchConversationList = () => {
|
||||
const dispatch = useDispatch();
|
||||
const conversationList: any[] = useSelector(
|
||||
@@ -412,7 +343,7 @@ export const useSelectCurrentConversation = () => {
|
||||
(state: any) => state.chatModel.currentConversation,
|
||||
);
|
||||
const dialog = useSelectCurrentDialog();
|
||||
const { conversationId } = useGetChatSearchParams();
|
||||
const { conversationId, dialogId } = useGetChatSearchParams();
|
||||
|
||||
const addNewestConversation = useCallback((message: string) => {
|
||||
setCurrentConversation((pre) => {
|
||||
@@ -448,12 +379,12 @@ export const useSelectCurrentConversation = () => {
|
||||
|
||||
setCurrentConversation({
|
||||
id: '',
|
||||
dialog_id: dialog.id,
|
||||
dialog_id: dialogId,
|
||||
reference: [],
|
||||
message: [nextMessage],
|
||||
} as any);
|
||||
}
|
||||
}, [conversationId, dialog]);
|
||||
}, [conversationId, dialog, dialogId]);
|
||||
|
||||
useEffect(() => {
|
||||
addPrologue();
|
||||
|
||||
Reference in New Issue
Block a user