new framwork

This commit is contained in:
archer
2023-06-09 12:57:42 +08:00
parent d9450bd7ee
commit ba9d9c3d5f
263 changed files with 12269 additions and 11599 deletions

46
client/src/types/chat.d.ts vendored Normal file
View File

@@ -0,0 +1,46 @@
import { ChatRoleEnum } from '@/constants/chat';
import type { InitChatResponse, InitShareChatResponse } from '@/api/response/chat';
import { QuoteItemType } from '@/pages/api/openapi/kb/appKbSearch';
export type ExportChatType = 'md' | 'pdf' | 'html';
export type ChatItemSimpleType = {
obj: `${ChatRoleEnum}`;
value: string;
quoteLen?: number;
quote?: QuoteItemType[];
systemPrompt?: string;
};
export type ChatItemType = {
_id: string;
} & ChatItemSimpleType;
export type ChatSiteItemType = {
status: 'loading' | 'finish';
} & ChatItemType;
export interface ChatType extends InitChatResponse {
history: ChatSiteItemType[];
}
export interface ShareChatType extends InitShareChatResponse {
history: ChatSiteItemType[];
}
export type HistoryItemType = {
_id: string;
updateTime: Date;
modelId: string;
title: string;
latestChat: string;
top: boolean;
};
export type ShareChatHistoryItemType = {
_id: string;
shareId: string;
updateTime: Date;
title: string;
latestChat: string;
chats: ChatSiteItemType[];
};

29
client/src/types/index.d.ts vendored Normal file
View File

@@ -0,0 +1,29 @@
import type { Mongoose } from 'mongoose';
import type { Agent } from 'http';
import type { Pool } from 'pg';
import type { Tiktoken } from '@dqbd/tiktoken';
declare global {
var mongodb: Mongoose | string | null;
var pgClient: Pool | null;
var httpsAgent: Agent;
var particlesJS: any;
var grecaptcha: any;
var QRCode: any;
var qaQueueLen: number;
var vectorQueueLen: number;
var OpenAiEncMap: Record<string, Tiktoken>;
interface Window {
['pdfjs-dist/build/pdf']: any;
}
}
export type PagingData<T> = {
pageNum: number;
pageSize: number;
data: T[];
total?: number;
};
export type RequestPaging = { pageNum: number; pageSize: number; [key]: any };

32
client/src/types/model.d.ts vendored Normal file
View File

@@ -0,0 +1,32 @@
import { ModelStatusEnum } from '@/constants/model';
import type { ModelSchema, kbSchema } from './mongoSchema';
import { ChatModelType, appVectorSearchModeEnum } from '@/constants/model';
export type ModelListItemType = {
_id: string;
name: string;
avatar: string;
systemPrompt: string;
};
export interface ModelUpdateParams {
name: string;
avatar: string;
chat: ModelSchema['chat'];
share: ModelSchema['share'];
}
export interface ShareModelItem {
_id: string;
avatar: string;
name: string;
userId: string;
share: ModelSchema['share'];
isCollection: boolean;
}
export type ShareChatEditType = {
name: string;
password: string;
maxContext: number;
};

167
client/src/types/mongoSchema.d.ts vendored Normal file
View File

@@ -0,0 +1,167 @@
import type { ChatItemType } from './chat';
import {
ModelStatusEnum,
ModelNameEnum,
appVectorSearchModeEnum,
ChatModelType,
EmbeddingModelType
} from '@/constants/model';
import type { DataType } from './data';
import { BillTypeEnum, InformTypeEnum } from '@/constants/user';
import { TrainingModeEnum } from '@/constants/plugin';
export interface UserModelSchema {
_id: string;
username: string;
password: string;
avatar: string;
balance: number;
inviterId?: string;
promotionAmount: number;
openaiKey: string;
createTime: number;
promotion: {
rate: number;
};
limit: {
exportKbTime?: Date;
};
}
export interface AuthCodeSchema {
_id: string;
username: string;
code: string;
type: 'register' | 'findPassword';
expiredTime: number;
}
export interface ModelSchema {
_id: string;
userId: string;
name: string;
avatar: string;
status: `${ModelStatusEnum}`;
updateTime: number;
chat: {
relatedKbs: string[];
searchMode: `${appVectorSearchModeEnum}`;
systemPrompt: string;
temperature: number;
chatModel: ChatModelType; // 聊天时用的模型,训练后就是训练的模型
};
share: {
isShare: boolean;
isShareDetail: boolean;
intro: string;
collection: number;
};
}
export interface ModelPopulate extends ModelSchema {
userId: UserModelSchema;
}
export interface CollectionSchema {
modelId: string;
userId: string;
}
export type ModelDataType = 0 | 1;
export interface TrainingDataSchema {
_id: string;
userId: string;
kbId: string;
lockTime: Date;
mode: `${TrainingModeEnum}`;
prompt: string;
q: string;
a: string;
source: string;
}
export interface ChatSchema {
_id: string;
userId: string;
modelId: string;
expiredTime: number;
updateTime: Date;
title: string;
customTitle: string;
latestChat: string;
top: boolean;
content: ChatItemType[];
}
export interface ChatPopulate extends ChatSchema {
userId: UserModelSchema;
modelId: ModelSchema;
}
export interface BillSchema {
_id: string;
userId: string;
type: `${BillTypeEnum}`;
modelName: ChatModelType | EmbeddingModelType;
chatId: string;
time: Date;
textLen: number;
tokenLen: number;
price: number;
}
export interface PaySchema {
_id: string;
userId: string;
createTime: Date;
price: number;
orderId: string;
status: 'SUCCESS' | 'REFUND' | 'NOTPAY' | 'CLOSED';
}
export interface OpenApiSchema {
_id: string;
userId: string;
createTime: Date;
lastUsedTime?: Date;
apiKey: String;
}
export interface PromotionRecordSchema {
_id: string;
userId: string; // 收益人
objUId?: string; // 目标对象如果是withdraw则为空
type: 'invite' | 'shareModel' | 'withdraw';
createTime: Date; // 记录时间
amount: number;
}
export interface ShareChatSchema {
_id: string;
userId: string;
modelId: string;
password: string;
name: string;
tokens: number;
maxContext: number;
lastTime: Date;
}
export interface kbSchema {
_id: string;
userId: string;
updateTime: Date;
avatar: string;
name: string;
tags: string[];
}
export interface informSchema {
_id: string;
userId: string;
time: Date;
type: `${InformTypeEnum}`;
title: string;
content: string;
read: boolean;
}

6
client/src/types/openapi.d.ts vendored Normal file
View File

@@ -0,0 +1,6 @@
export interface UserOpenApiKey {
id: string;
apiKey: string;
createTime: Date;
lastUsedTime?: Date;
}

0
client/src/types/pg.d.ts vendored Normal file
View File

18
client/src/types/plugin.d.ts vendored Normal file
View File

@@ -0,0 +1,18 @@
import type { kbSchema } from './mongoSchema';
/* kb type */
export interface KbItemType extends kbSchema {
totalData: number;
tags: string;
}
export interface KbDataItemType {
id: string;
q: string; // 提问词
a: string; // 原文
source: string;
}
export type TextPluginRequestParams = {
input: string;
};

27
client/src/types/user.d.ts vendored Normal file
View File

@@ -0,0 +1,27 @@
import type { BillSchema } from './mongoSchema';
export interface UserType {
_id: string;
username: string;
avatar: string;
openaiKey: string;
balance: number;
promotion: {
rate: number;
};
}
export interface UserUpdateParams {
balance?: number;
avatar?: string;
openaiKey?: string;
}
export interface UserBillType {
id: string;
time: Date;
modelName: BillSchema['modelName'];
type: BillSchema['type'];
textLen: number;
tokenLen: number;
price: number;
}