This commit is contained in:
Archer
2023-11-09 09:46:57 +08:00
committed by GitHub
parent 661ee79943
commit 8bb5588305
402 changed files with 9899 additions and 5967 deletions

View File

@@ -1,5 +1,5 @@
import { GET, POST, PUT, DELETE } from '@/web/common/api/request';
import type { CreateQuestionGuideParams } from '@/global/core/api/aiReq.d';
import type { CreateQuestionGuideParams } from '@/global/core/ai/api.d';
export const postQuestionGuide = (data: CreateQuestionGuideParams, cancelToken: AbortController) =>
POST<string[]>('/core/ai/agent/createQuestionGuide', data, { cancelToken });

View File

@@ -1,57 +1,56 @@
import { GET, POST, DELETE, PUT } from '@/web/common/api/request';
import type { AppSchema } from '@/types/mongoSchema';
import type { AppListItemType, AppUpdateParams } from '@/types/app';
import type { AppDetailType, AppListItemType } from '@fastgpt/global/core/app/type.d';
import { RequestPaging } from '@/types/index';
import { addDays } from 'date-fns';
import type { GetAppChatLogsParams } from '@/global/core/api/appReq.d';
import type { CreateAppParams } from '@/types/app';
import type { CreateAppParams, AppUpdateParams } from '@fastgpt/global/core/app/api.d';
/**
* 获取模型列表
*/
export const getMyApps = () => GET<AppListItemType[]>('/app/myApps');
export const getMyApps = () => GET<AppListItemType[]>('/core/app/list');
/**
* 创建一个模型
*/
export const postCreateApp = (data: CreateAppParams) => POST<string>('/app/create', data);
export const postCreateApp = (data: CreateAppParams) => POST<string>('/core/app/create', data);
/**
* 根据 ID 删除模型
*/
export const delModelById = (id: string) => DELETE(`/app/del?appId=${id}`);
export const delModelById = (id: string) => DELETE(`/core/app/del?appId=${id}`);
/**
* 根据 ID 获取模型
*/
export const getModelById = (id: string) => GET<AppSchema>(`/app/detail?appId=${id}`);
export const getModelById = (id: string) => GET<AppDetailType>(`/core/app/detail?appId=${id}`);
/**
* 根据 ID 更新模型
*/
export const putAppById = (id: string, data: AppUpdateParams) =>
PUT(`/app/update?appId=${id}`, data);
PUT(`/core/app/update?appId=${id}`, data);
/* 共享市场 */
/**
* 获取共享市场模型
*/
export const getShareModelList = (data: { searchText?: string } & RequestPaging) =>
POST(`/app/share/getModels`, data);
POST(`/core/app/share/getModels`, data);
/**
* 收藏/取消收藏模型
*/
export const triggerModelCollection = (appId: string) =>
POST<number>(`/app/share/collection?appId=${appId}`);
POST<number>(`/core/app/share/collection?appId=${appId}`);
// ====================== data
export const getAppTotalUsage = (data: { appId: string }) =>
POST<{ date: String; total: number }[]>(`/app/data/totalUsage`, {
POST<{ date: String; total: number }[]>(`/core/app/data/totalUsage`, {
...data,
start: addDays(new Date(), -13),
end: addDays(new Date(), 1)
}).then((res) => (res.length === 0 ? [{ date: new Date(), total: 0 }] : res));
// =================== chat logs
export const getAppChatLogs = (data: GetAppChatLogsParams) => POST(`/app/getChatLogs`, data);
export const getAppChatLogs = (data: GetAppChatLogsParams) => POST(`/core/app/getChatLogs`, data);

View File

@@ -1,4 +1,4 @@
import type { VariableItemType } from '@/types/app';
import type { AppTTSConfigType, VariableItemType } from '@/types/app';
import { chatModelList } from '@/web/common/system/staticData';
import type { ModuleItemType } from '@fastgpt/global/core/module/type';
import {
@@ -15,7 +15,7 @@ import { getGuideModule, splitGuideModule } from '@/global/core/app/modules/util
export type EditFormType = {
chatModel: AIChatProps;
kb: {
dataset: {
list: SelectedDatasetType;
searchSimilarity: number;
searchLimit: number;
@@ -28,6 +28,7 @@ export type EditFormType = {
};
variables: VariableItemType[];
questionGuide: boolean;
tts: AppTTSConfigType;
};
export const getDefaultAppForm = (): EditFormType => {
const defaultChatModel = chatModelList[0];
@@ -40,11 +41,11 @@ export const getDefaultAppForm = (): EditFormType => {
[SystemInputEnum.isResponseAnswerText]: true,
quotePrompt: '',
quoteTemplate: '',
maxToken: defaultChatModel ? defaultChatModel.maxToken / 2 : 4000,
maxToken: defaultChatModel ? defaultChatModel.maxResponse / 2 : 4000,
frequency: 0.5,
presence: -0.5
},
kb: {
dataset: {
list: [],
searchSimilarity: 0.4,
searchLimit: 5,
@@ -56,7 +57,10 @@ export const getDefaultAppForm = (): EditFormType => {
}
},
variables: [],
questionGuide: false
questionGuide: false,
tts: {
type: 'web'
}
};
};
@@ -118,17 +122,17 @@ export const appModules2Form = (modules: ModuleItemType[]) => {
});
} else if (module.flowType === FlowNodeTypeEnum.datasetSearchNode) {
updateVal({
formKey: 'kb.list',
formKey: 'dataset.list',
inputs: module.inputs,
key: 'datasets'
});
updateVal({
formKey: 'kb.searchSimilarity',
formKey: 'dataset.searchSimilarity',
inputs: module.inputs,
key: 'similarity'
});
updateVal({
formKey: 'kb.searchLimit',
formKey: 'dataset.searchLimit',
inputs: module.inputs,
key: 'limit'
});
@@ -137,12 +141,12 @@ export const appModules2Form = (modules: ModuleItemType[]) => {
const emptyOutput = emptyOutputs[0];
if (emptyOutput) {
const target = modules.find((item) => item.moduleId === emptyOutput.moduleId);
defaultAppForm.kb.searchEmptyText =
defaultAppForm.dataset.searchEmptyText =
target?.inputs?.find((item) => item.key === FlowNodeSpecialInputKeyEnum.answerText)
?.value || '';
}
} else if (module.flowType === FlowNodeTypeEnum.userGuide) {
const { welcomeText, variableModules, questionGuide } = splitGuideModule(
const { welcomeText, variableModules, questionGuide, ttsConfig } = splitGuideModule(
getGuideModule(modules)
);
if (welcomeText) {
@@ -153,6 +157,7 @@ export const appModules2Form = (modules: ModuleItemType[]) => {
defaultAppForm.variables = variableModules;
defaultAppForm.questionGuide = !!questionGuide;
defaultAppForm.tts = ttsConfig;
}
});
@@ -213,13 +218,13 @@ const chatModelInput = (formData: EditFormType): FlowNodeInputItemType[] => [
key: 'switch',
type: 'target',
label: '触发器',
connected: formData.kb.list.length > 0 && !!formData.kb.searchEmptyText
connected: formData.dataset.list.length > 0 && !!formData.dataset.searchEmptyText
},
{
key: 'quoteQA',
type: 'target',
label: '引用内容',
connected: formData.kb.list.length > 0
connected: formData.dataset.list.length > 0
},
{
key: 'history',
@@ -256,6 +261,12 @@ const userGuideTemplate = (formData: EditFormType): ModuleItemType[] => [
type: FlowNodeInputTypeEnum.hidden,
label: '问题引导',
value: formData.questionGuide
},
{
key: SystemInputEnum.tts,
type: FlowNodeInputTypeEnum.hidden,
label: '语音播报',
value: formData.tts
}
],
outputs: [],
@@ -434,21 +445,21 @@ const kbTemplate = (formData: EditFormType): ModuleItemType[] => [
inputs: [
{
key: 'datasets',
value: formData.kb.list,
value: formData.dataset.list,
type: FlowNodeInputTypeEnum.custom,
label: '关联的知识库',
connected: true
},
{
key: 'similarity',
value: formData.kb.searchSimilarity,
value: formData.dataset.searchSimilarity,
type: FlowNodeInputTypeEnum.slider,
label: '相似度',
connected: true
},
{
key: 'limit',
value: formData.kb.searchLimit,
value: formData.dataset.searchLimit,
type: FlowNodeInputTypeEnum.slider,
label: '单次搜索上限',
connected: true
@@ -469,7 +480,7 @@ const kbTemplate = (formData: EditFormType): ModuleItemType[] => [
outputs: [
{
key: 'isEmpty',
targets: formData.kb.searchEmptyText
targets: formData.dataset.searchEmptyText
? [
{
moduleId: 'emptyText',
@@ -480,7 +491,7 @@ const kbTemplate = (formData: EditFormType): ModuleItemType[] => [
},
{
key: 'unEmpty',
targets: formData.kb.searchEmptyText
targets: formData.dataset.searchEmptyText
? [
{
moduleId: 'chatModule',
@@ -505,7 +516,7 @@ const kbTemplate = (formData: EditFormType): ModuleItemType[] => [
},
moduleId: 'datasetSearch'
},
...(formData.kb.searchEmptyText
...(formData.dataset.searchEmptyText
? [
{
name: '指定回复',
@@ -519,7 +530,7 @@ const kbTemplate = (formData: EditFormType): ModuleItemType[] => [
},
{
key: FlowNodeSpecialInputKeyEnum.answerText,
value: formData.kb.searchEmptyText,
value: formData.dataset.searchEmptyText,
type: FlowNodeInputTypeEnum.textarea,
valueType: FlowNodeValTypeEnum.string,
label: '回复的内容',
@@ -568,7 +579,7 @@ const kbTemplate = (formData: EditFormType): ModuleItemType[] => [
export const appForm2Modules = (formData: EditFormType) => {
const modules = [
...userGuideTemplate(formData),
...(formData.kb.list.length > 0 ? kbTemplate(formData) : simpleChatTemplate(formData))
...(formData.dataset.list.length > 0 ? kbTemplate(formData) : simpleChatTemplate(formData))
];
return modules as ModuleItemType[];

View File

@@ -0,0 +1,65 @@
import { create } from 'zustand';
import { devtools, persist } from 'zustand/middleware';
import { immer } from 'zustand/middleware/immer';
import { getMyApps, getModelById, putAppById } from '@/web/core/app/api';
import { defaultApp } from '@/constants/app';
import type { AppUpdateParams } from '@fastgpt/global/core/app/api.d';
import { AppDetailType, AppListItemType } from '@fastgpt/global/core/app/type.d';
type State = {
myApps: AppListItemType[];
loadMyApps: (init?: boolean) => Promise<AppListItemType[]>;
appDetail: AppDetailType;
loadAppDetail: (id: string, init?: boolean) => Promise<AppDetailType>;
updateAppDetail(appId: string, data: AppUpdateParams): Promise<void>;
clearAppModules(): void;
};
export const useAppStore = create<State>()(
devtools(
persist(
immer((set, get) => ({
myApps: [],
async loadMyApps(init = true) {
if (get().myApps.length > 0 && !init) return [];
const res = await getMyApps();
set((state) => {
state.myApps = res;
});
return res;
},
appDetail: defaultApp,
async loadAppDetail(id: string, init = false) {
if (id === get().appDetail._id && !init) return get().appDetail;
const res = await getModelById(id);
set((state) => {
state.appDetail = res;
});
return res;
},
async updateAppDetail(appId: string, data: AppUpdateParams) {
await putAppById(appId, data);
set((state) => {
state.appDetail = {
...state.appDetail,
...data
};
});
},
clearAppModules() {
set((state) => {
state.appDetail = {
...state.appDetail,
modules: []
};
});
}
})),
{
name: 'appStore',
partialize: (state) => ({})
}
)
)
);

View File

@@ -1,45 +1,49 @@
import { GET, POST, DELETE, PUT } from '@/web/common/api/request';
import type { ChatHistoryItemType } from '@/types/chat';
import type { InitChatResponse } from '@/global/core/api/chatRes.d';
import type { ChatHistoryItemType } from '@fastgpt/global/core/chat/type.d';
import type { InitChatResponse } from '@fastgpt/global/core/chat/api.d';
import type { RequestPaging } from '@/types';
import type { Props as UpdateHistoryProps } from '@/pages/api/chat/history/updateChatHistory';
import type { AdminUpdateFeedbackParams } from '@/global/core/api/chatReq.d';
import { UpdateHistoryProps } from '@fastgpt/global/core/chat/api.d';
import type { AdminUpdateFeedbackParams } from '@fastgpt/global/core/chat/api.d';
import { GetChatSpeechProps } from '@/global/core/chat/api.d';
/**
* 获取初始化聊天内容
*/
export const getInitChatSiteInfo = (data: { appId: string; chatId?: string }) =>
GET<InitChatResponse>(`/chat/init`, data);
GET<InitChatResponse>(`/core/chat/init`, data);
/**
* 获取历史记录
*/
export const getChatHistory = (data: RequestPaging & { appId?: string }) =>
POST<ChatHistoryItemType[]>('/chat/history/getHistory', data);
export const getChatHistory = (data: RequestPaging & { appId: string }) =>
POST<ChatHistoryItemType[]>('/core/chat/list', data);
/**
* 删除一条历史记录
*/
export const delChatHistoryById = (chatId: string) => DELETE(`/chat/removeHistory`, { chatId });
export const delChatHistoryById = (chatId: string) => DELETE(`/core/chat/delete`, { chatId });
/**
* clear all history by appid
*/
export const clearChatHistoryByAppId = (appId: string) => DELETE(`/chat/removeHistory`, { appId });
export const clearChatHistoryByAppId = (appId: string) => DELETE(`/core/chat/delete`, { appId });
/**
* 删除一句对话
*/
export const delChatRecordById = (data: { chatId: string; contentId: string }) =>
DELETE(`/chat/delChatRecordByContentId`, data);
DELETE(`/core/chat/item/delete`, data);
/**
* 修改历史记录: 标题/置顶
*/
export const putChatHistory = (data: UpdateHistoryProps) =>
PUT('/chat/history/updateChatHistory', data);
export const putChatHistory = (data: UpdateHistoryProps) => PUT('/core/chat/update', data);
export const userUpdateChatFeedback = (data: { chatItemId: string; userFeedback?: string }) =>
POST('/chat/feedback/userUpdate', data);
POST('/core/chat/feedback/userUpdate', data);
export const adminUpdateChatFeedback = (data: AdminUpdateFeedbackParams) =>
POST('/chat/feedback/adminUpdate', data);
POST('/core/chat/feedback/adminUpdate', data);
/* ------------- function ------------- */
export const getChatItemSpeech = (data: GetChatSpeechProps) =>
POST<{ data: Buffer }>('/core/chat/item/getSpeech', data);

View File

@@ -1,14 +1,13 @@
import { create } from 'zustand';
import { devtools, persist } from 'zustand/middleware';
import { immer } from 'zustand/middleware/immer';
import { ChatHistoryItemType } from '@/types/chat';
import type { InitChatResponse } from '@/global/core/api/chatRes.d';
import type { ChatHistoryItemType } from '@fastgpt/global/core/chat/type.d';
import type { InitChatResponse } from '@fastgpt/global/core/chat/api';
import { delChatHistoryById, getChatHistory, clearChatHistoryByAppId } from '@/web/core/chat/api';
type State = {
history: ChatHistoryItemType[];
loadHistory: (data: { appId?: string }) => Promise<null>;
loadHistory: (data: { appId: string }) => Promise<null>;
delHistory(history: string): Promise<void>;
clearHistory(appId: string): Promise<void>;
updateHistory: (history: ChatHistoryItemType) => void;

View File

@@ -1,9 +1,12 @@
import { create } from 'zustand';
import { devtools, persist } from 'zustand/middleware';
import { immer } from 'zustand/middleware/immer';
import type { ChatSiteItemType, ShareChatHistoryItemType, ShareChatType } from '@/types/chat';
import { HUMAN_ICON } from '@/constants/chat';
import type {
ShareChatHistoryItemType,
ShareChatType
} from '@fastgpt/global/support/outLink/api.d';
import type { ChatSiteItemType } from '@fastgpt/global/core/chat/type.d';
import { HUMAN_ICON } from '@fastgpt/global/core/chat/constants';
type State = {
shareChatData: ShareChatType;

View File

@@ -1,5 +1,5 @@
import { GET, POST, PUT, DELETE } from '@/web/common/api/request';
import type { DatasetItemType, DatasetsItemType, DatasetPathItemType } from '@/types/core/dataset';
import type { DatasetItemType, DatasetPathItemType } from '@/types/core/dataset';
import type {
DatasetUpdateParams,
CreateDatasetParams,
@@ -12,27 +12,26 @@ import type {
SetOneDatasetDataProps
} from '@/global/core/api/datasetReq.d';
import type { PushDataResponse } from '@/global/core/api/datasetRes.d';
import type { SearchDataResponseItemType } from '@fastgpt/global/core/dataset/type';
import type {
DatasetCollectionItemType,
SearchDataResponseItemType
} from '@fastgpt/global/core/dataset/type';
import { DatasetTypeEnum } from '@fastgpt/global/core/dataset/constant';
import type { GSFileInfoType } from '@/types/common/file';
import { getToken } from '@/web/support/user/auth';
import download from 'downloadjs';
import type {
DatasetCollectionSchemaType,
DatasetDataItemType
} from '@fastgpt/global/core/dataset/type';
import type { DatasetDataItemType } from '@fastgpt/global/core/dataset/type';
import { ParentTreePathItemType } from '@fastgpt/global/common/parentFolder/type';
import { DatasetCollectionsListItemType } from '@/global/core/dataset/response';
import { PagingData } from '@/types';
/* ======================== dataset ======================= */
export const getDatasets = (data: { parentId?: string; type?: `${DatasetTypeEnum}` }) =>
GET<DatasetsItemType[]>(`/core/dataset/list`, data);
GET<DatasetItemType[]>(`/core/dataset/list`, data);
/**
* get type=dataset list
*/
export const getAllDataset = () => GET<DatasetsItemType[]>(`/core/dataset/allDataset`);
export const getAllDataset = () => GET<DatasetItemType[]>(`/core/dataset/allDataset`);
export const getDatasetPaths = (parentId?: string) =>
GET<DatasetPathItemType[]>('/core/dataset/paths', { parentId });
@@ -56,7 +55,7 @@ export const getDatasetCollections = (data: GetDatasetCollectionsProps) =>
export const getDatasetCollectionPathById = (parentId: string) =>
GET<ParentTreePathItemType[]>(`/core/dataset/collection/paths`, { parentId });
export const getDatasetCollectionById = (id: string) =>
GET<DatasetCollectionSchemaType>(`/core/dataset/collection/detail`, { id });
GET<DatasetCollectionItemType>(`/core/dataset/collection/detail`, { id });
export const postDatasetCollection = (data: CreateDatasetCollectionParams) =>
POST<string>(`/core/dataset/collection/create`, data);
export const putDatasetCollectionById = (data: UpdateDatasetCollectionParams) =>
@@ -119,7 +118,5 @@ export const delOneDatasetDataById = (dataId: string) =>
DELETE(`/core/dataset/data/delDataById?dataId=${dataId}`);
/* ================== file ======================== */
export const getFileInfoById = (fileId: string) =>
GET<GSFileInfoType>(`/core/dataset/file/detail`, { fileId });
export const delDatasetEmptyFiles = (datasetId: string) =>
DELETE(`/core/dataset/file/delEmptyFiles`, { datasetId });
export const getFileViewUrl = (fileId: string) =>
GET<string>('/core/dataset/file/getPreviewUrl', { fileId });

View File

@@ -1,17 +1,17 @@
import { create } from 'zustand';
import { devtools, persist } from 'zustand/middleware';
import { immer } from 'zustand/middleware/immer';
import type { DatasetItemType, DatasetsItemType } from '@/types/core/dataset';
import type { DatasetItemType } from '@/types/core/dataset';
import { getAllDataset, getDatasets, getDatasetById, putDatasetById } from '@/web/core/dataset/api';
import { defaultKbDetail } from '@/constants/dataset';
import { defaultDatasetDetail } from '@/constants/dataset';
import type { DatasetUpdateParams } from '@/global/core/api/datasetReq.d';
type State = {
allDatasets: DatasetsItemType[];
loadAllDatasets: () => Promise<DatasetsItemType[]>;
myDatasets: DatasetsItemType[];
allDatasets: DatasetItemType[];
loadAllDatasets: () => Promise<DatasetItemType[]>;
myDatasets: DatasetItemType[];
loadDatasets: (parentId?: string) => Promise<any>;
setDatasets(val: DatasetsItemType[]): void;
setDatasets(val: DatasetItemType[]): void;
datasetDetail: DatasetItemType;
loadDatasetDetail: (id: string, init?: boolean) => Promise<DatasetItemType>;
updateDataset: (data: DatasetUpdateParams) => Promise<any>;
@@ -42,7 +42,7 @@ export const useDatasetStore = create<State>()(
state.myDatasets = val;
});
},
datasetDetail: defaultKbDetail,
datasetDetail: defaultDatasetDetail,
async loadDatasetDetail(id: string, init = false) {
if (!id || (id === get().datasetDetail._id && !init)) return get().datasetDetail;
@@ -69,7 +69,7 @@ export const useDatasetStore = create<State>()(
? {
...item,
...data,
tags: data.tags?.split(' ') || []
tags: data.tags || ''
}
: item
);

View File

@@ -1,4 +1,4 @@
import { postChunks2Dataset } from '@/web/core/dataset/api';
import { getFileViewUrl, postChunks2Dataset } from '@/web/core/dataset/api';
import { TrainingModeEnum } from '@fastgpt/global/core/dataset/constant';
import { DatasetChunkItemType } from '@fastgpt/global/core/dataset/type';
import { delay } from '@/utils/tools';
@@ -49,3 +49,9 @@ export async function chunksUpload({
return { insertLen: successInsert };
}
export async function getFileAndOpen(fileId: string) {
const url = await getFileViewUrl(fileId);
const asPath = `${location.origin}${url}`;
window.open(asPath, '_blank');
}