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

@@ -2,5 +2,6 @@ export enum ChatCompletionRequestMessageRoleEnum {
'System' = 'system',
'User' = 'user',
'Assistant' = 'assistant',
'Function' = 'function'
'Function' = 'function',
'Tool' = 'tool'
}

View File

@@ -0,0 +1,2 @@
import OpenAI from 'openai';
export default OpenAI;

32
packages/global/core/ai/model.d.ts vendored Normal file
View File

@@ -0,0 +1,32 @@
export type LLMModelItemType = {
model: string;
name: string;
maxContext: number;
maxResponse: number;
price: number;
};
export type ChatModelItemType = LLMModelItemType & {
quoteMaxToken: number;
maxTemperature: number;
censor?: boolean;
defaultSystemChatPrompt?: string;
};
export type FunctionModelItemType = LLMModelItemType & {
functionCall: boolean;
functionPrompt: string;
};
export type VectorModelItemType = {
model: string;
name: string;
defaultToken: number;
price: number;
maxToken: number;
};
export type AudioSpeechModelType = {
model: string;
name: string;
price: number;
};

View File

@@ -0,0 +1,115 @@
import type {
LLMModelItemType,
ChatModelItemType,
FunctionModelItemType,
VectorModelItemType,
AudioSpeechModelType
} from './model.d';
export const defaultChatModels: ChatModelItemType[] = [
{
model: 'gpt-3.5-turbo-1106',
name: 'GPT35-1106',
price: 0,
maxContext: 16000,
maxResponse: 4000,
quoteMaxToken: 2000,
maxTemperature: 1.2,
censor: false,
defaultSystemChatPrompt: ''
},
{
model: 'gpt-3.5-turbo-16k',
name: 'GPT35-16k',
maxContext: 16000,
maxResponse: 16000,
price: 0,
quoteMaxToken: 8000,
maxTemperature: 1.2,
censor: false,
defaultSystemChatPrompt: ''
},
{
model: 'gpt-4',
name: 'GPT4-8k',
maxContext: 8000,
maxResponse: 8000,
price: 0,
quoteMaxToken: 4000,
maxTemperature: 1.2,
censor: false,
defaultSystemChatPrompt: ''
}
];
export const defaultQAModels: LLMModelItemType[] = [
{
model: 'gpt-3.5-turbo-16k',
name: 'GPT35-16k',
maxContext: 16000,
maxResponse: 16000,
price: 0
}
];
export const defaultCQModels: FunctionModelItemType[] = [
{
model: 'gpt-3.5-turbo-1106',
name: 'GPT35-1106',
maxContext: 16000,
maxResponse: 4000,
price: 0,
functionCall: true,
functionPrompt: ''
},
{
model: 'gpt-4',
name: 'GPT4-8k',
maxContext: 8000,
maxResponse: 8000,
price: 0,
functionCall: true,
functionPrompt: ''
}
];
export const defaultExtractModels: FunctionModelItemType[] = [
{
model: 'gpt-3.5-turbo-1106',
name: 'GPT35-1106',
maxContext: 16000,
maxResponse: 4000,
price: 0,
functionCall: true,
functionPrompt: ''
}
];
export const defaultQGModels: LLMModelItemType[] = [
{
model: 'gpt-3.5-turbo-1106',
name: 'GPT35-1106',
maxContext: 1600,
maxResponse: 4000,
price: 0
}
];
export const defaultVectorModels: VectorModelItemType[] = [
{
model: 'text-embedding-ada-002',
name: 'Embedding-2',
price: 0,
defaultToken: 500,
maxToken: 3000
}
];
export const defaultAudioSpeechModels: AudioSpeechModelType[] = [
{
model: 'tts-1',
name: 'OpenAI TTS1',
price: 0
},
{
model: 'tts-1-hd',
name: 'OpenAI TTS1',
price: 0
}
];

View File

@@ -0,0 +1,8 @@
import { Text2SpeechVoiceEnum } from './constant';
export type Text2SpeechProps = {
model?: string;
voice?: `${Text2SpeechVoiceEnum}`;
input: string;
speed?: number;
};

View File

@@ -0,0 +1,17 @@
export enum Text2SpeechVoiceEnum {
alloy = 'alloy',
echo = 'echo',
fable = 'fable',
onyx = 'onyx',
nova = 'nova',
shimmer = 'shimmer'
}
export const openaiTTSList = [
Text2SpeechVoiceEnum.alloy,
Text2SpeechVoiceEnum.echo,
Text2SpeechVoiceEnum.fable,
Text2SpeechVoiceEnum.onyx,
Text2SpeechVoiceEnum.nova,
Text2SpeechVoiceEnum.shimmer
];
export const openaiTTSModel = 'tts-1';

View File

@@ -1,9 +1,19 @@
import OpenAI from 'openai';
export type ChatCompletionRequestMessage = OpenAI.Chat.CreateChatCompletionRequestMessage;
export type ChatCompletion = OpenAI.Chat.ChatCompletion;
export type CreateChatCompletionRequest = OpenAI.Chat.ChatCompletionCreateParams;
import type {
ChatCompletion,
ChatCompletionCreateParams,
ChatCompletionChunk,
ChatCompletionMessageParam,
ChatCompletionContentPart
} from 'openai/resources';
export type ChatCompletionContentPart = ChatCompletionContentPart;
export type ChatCompletionCreateParams = ChatCompletionCreateParams;
export type ChatMessageItemType = Omit<ChatCompletionMessageParam> & {
dataId?: string;
content: any;
};
export type StreamChatType = Stream<OpenAI.Chat.ChatCompletionChunk>;
export type ChatCompletion = ChatCompletion;
export type StreamChatType = Stream<ChatCompletionChunk>;
export type PromptTemplateItem = {
title: string;

18
packages/global/core/app/api.d.ts vendored Normal file
View File

@@ -0,0 +1,18 @@
import { AppTypeEnum } from './constants';
import { AppSchema } from './type';
export type CreateAppParams = {
name?: string;
avatar?: string;
type?: `${AppTypeEnum}`;
modules: AppSchema['modules'];
};
export interface AppUpdateParams {
name?: string;
type?: `${AppTypeEnum}`;
avatar?: string;
intro?: string;
modules?: AppSchema['modules'];
permission?: AppSchema['permission'];
}

View File

@@ -0,0 +1,4 @@
export enum AppTypeEnum {
basic = 'basic',
advanced = 'advanced'
}

32
packages/global/core/app/type.d.ts vendored Normal file
View File

@@ -0,0 +1,32 @@
import { ModuleItemType } from '../module/type';
import { AppTypeEnum } from './constants';
import { PermissionTypeEnum } from '../../support/permission/constant';
import { Text2SpeechVoiceEnum } from '../ai/speech/constant';
export interface AppSchema {
_id: string;
userId: string;
teamId: string;
tmbId: string;
name: string;
type: `${AppTypeEnum}`;
avatar: string;
intro: string;
updateTime: number;
modules: ModuleItemType[];
permission: `${PermissionTypeEnum}`;
}
export type AppListItemType = {
_id: string;
name: string;
avatar: string;
intro: string;
isOwner: boolean;
permission: `${PermissionTypeEnum}`;
};
export type AppDetailType = AppSchema & {
isOwner: boolean;
canWrite: boolean;
};

34
packages/global/core/chat/api.d.ts vendored Normal file
View File

@@ -0,0 +1,34 @@
import { ModuleItemType } from '../module/type';
import { AdminFbkType, ChatItemType, moduleDispatchResType } from './type';
export type UpdateHistoryProps = {
chatId: string;
customTitle?: string;
top?: boolean;
};
export type AdminUpdateFeedbackParams = AdminFbkType & {
chatItemId: string;
};
export type InitChatResponse = {
chatId: string;
appId: string;
app: {
userGuideModule?: ModuleItemType;
chatModels?: string[];
name: string;
avatar: string;
intro: string;
canUse?: boolean;
};
title: string;
variables: Record<string, any>;
history: ChatItemType[];
};
export type ChatHistoryItemResType = moduleDispatchResType & {
moduleType: `${FlowNodeTypeEnum}`;
moduleName: string;
moduleLogo?: string;
};

View File

@@ -0,0 +1,56 @@
export enum ChatRoleEnum {
System = 'System',
Human = 'Human',
AI = 'AI',
Function = 'Function',
Tool = 'Tool'
}
export enum TaskResponseKeyEnum {
'answerText' = 'answerText', // answer module text key
'responseData' = 'responseData',
'history' = 'history'
}
export const ChatRoleMap = {
[ChatRoleEnum.System]: {
name: '系统提示词'
},
[ChatRoleEnum.Human]: {
name: '用户'
},
[ChatRoleEnum.AI]: {
name: 'AI'
},
[ChatRoleEnum.Function]: {
name: 'Function'
},
[ChatRoleEnum.Tool]: {
name: 'Tool'
}
};
export enum ChatSourceEnum {
test = 'test',
online = 'online',
share = 'share',
api = 'api'
}
export const ChatSourceMap = {
[ChatSourceEnum.test]: {
name: 'chat.logs.test'
},
[ChatSourceEnum.online]: {
name: 'chat.logs.online'
},
[ChatSourceEnum.share]: {
name: 'chat.logs.share'
},
[ChatSourceEnum.api]: {
name: 'chat.logs.api'
}
};
export const HUMAN_ICON = `/icon/human.svg`;
export const LOGO_ICON = `/icon/logo.svg`;

111
packages/global/core/chat/type.d.ts vendored Normal file
View File

@@ -0,0 +1,111 @@
import { ClassifyQuestionAgentItemType } from '../module/type';
import { SearchDataResponseItemType } from '../dataset/type';
import { ChatRoleEnum, ChatSourceEnum, TaskResponseKeyEnum } from './constants';
import { FlowNodeTypeEnum } from '../module/node/constant';
import { AppSchema } from 'core/app/type';
export type ChatSchema = {
_id: string;
chatId: string;
userId: string;
teamId: string;
tmbId: string;
appId: string;
updateTime: Date;
title: string;
customTitle: string;
top: boolean;
variables: Record<string, any>;
source: `${ChatSourceEnum}`;
shareId?: string;
isInit: boolean;
content: ChatItemType[];
};
export type ChatWithAppSchema = Omit<ChatSchema, 'appId'> & {
appId: AppSchema;
};
export type ChatItemSchema = {
dataId: string;
chatId: string;
userId: string;
teamId: string;
tmbId: string;
appId: string;
time: Date;
obj: `${ChatRoleEnum}`;
value: string;
userFeedback?: string;
adminFeedback?: AdminFbkType;
[TaskResponseKeyEnum.responseData]?: ChatHistoryItemResType[];
tts?: Buffer;
};
export type AdminFbkType = {
dataId: string;
datasetId: string;
collectionId: string;
q: string;
a?: string;
};
export type ChatItemType = {
dataId?: string;
obj: ChatItemSchema['obj'];
value: any;
userFeedback?: string;
adminFeedback?: ChatItemSchema['feedback'];
[TaskResponseKeyEnum.responseData]?: ChatItemSchema[TaskResponseKeyEnum.responseData];
};
export type ChatSiteItemType = {
status: 'loading' | 'running' | 'finish';
moduleName?: string;
ttsBuffer?: Buffer;
} & ChatItemType;
export type HistoryItemType = {
chatId: string;
updateTime: Date;
customTitle?: string;
title: string;
};
export type ChatHistoryItemType = HistoryItemType & {
appId: string;
top: boolean;
};
// response data
export type moduleDispatchResType = {
price: number;
runningTime?: number;
tokens?: number;
model?: string;
// chat
question?: string;
temperature?: number;
maxToken?: number;
quoteList?: SearchDataResponseItemType[];
historyPreview?: ChatItemType[]; // completion context array. history will slice
// dataset search
similarity?: number;
limit?: number;
// cq
cqList?: ClassifyQuestionAgentItemType[];
cqResult?: string;
// content extract
extractDescription?: string;
extractResult?: Record<string, any>;
// http
body?: Record<string, any>;
httpResult?: Record<string, any>;
// plugin output
pluginOutput?: Record<string, any>;
};

View File

@@ -1,3 +1,5 @@
export const PgDatasetTableName = 'modeldata';
export enum DatasetTypeEnum {
folder = 'folder',
dataset = 'dataset'

View File

@@ -1,20 +1,26 @@
import { PermissionTypeEnum } from '../../support/permission/constant';
import { DatasetCollectionTypeEnum, DatasetTypeEnum, TrainingModeEnum } from './constant';
export type DatasetSchemaType = {
_id: string;
userId: string;
parentId: string;
userId: string;
teamId: string;
tmbId: string;
updateTime: Date;
avatar: string;
name: string;
vectorModel: string;
tags: string[];
type: `${DatasetTypeEnum}`;
permission: `${PermissionTypeEnum}`;
};
export type DatasetCollectionSchemaType = {
_id: string;
userId: string;
teamId: string;
tmbId: string;
datasetId: string;
parentId?: string;
name: string;
@@ -30,6 +36,8 @@ export type DatasetCollectionSchemaType = {
export type DatasetTrainingSchemaType = {
_id: string;
userId: string;
teamId: string;
tmbId: string;
datasetId: string;
datasetCollectionId: string;
billId: string;
@@ -42,17 +50,35 @@ export type DatasetTrainingSchemaType = {
a: string;
};
export type CollectionWithDatasetType = Omit<DatasetCollectionSchemaType, 'datasetId'> & {
datasetId: DatasetSchemaType;
};
/* ================= dataset ===================== */
/* ================= collection ===================== */
export type DatasetCollectionItemType = DatasetCollectionSchemaType & {
canWrite: boolean;
};
/* ================= data ===================== */
export type PgRawDataItemType = {
id: string;
q: string;
a: string;
team_id: string;
tmb_id: string;
dataset_id: string;
collection_id: string;
};
export type PgDataItemType = {
id: string;
q: string;
a: string;
dataset_id: string;
collection_id: string;
teamId: string;
tmbId: string;
datasetId: string;
collectionId: string;
};
export type DatasetChunkItemType = {
q: string;
@@ -66,8 +92,24 @@ export type DatasetDataItemType = DatasetChunkItemType & {
sourceId?: string;
};
/* --------------- file ---------------------- */
export type DatasetFileSchema = {
_id: string;
length: number;
chunkSize: number;
uploadDate: Date;
filename: string;
contentType: string;
metadata: {
contentType: string;
datasetId: string;
teamId: string;
tmbId: string;
};
};
/* ============= search =============== */
export type SearchDataResultItemType = PgDataItemType & {
export type SearchDataResultItemType = PgRawDataItemType & {
score: number;
};
export type SearchDataResponseItemType = DatasetDataItemType & {

0
packages/global/core/module/api.d.ts vendored Normal file
View File

View File

@@ -1,4 +1,4 @@
import { FlowNodeTypeEnum } from './node/constant';
import { FlowNodeTypeEnum, FlowNodeValTypeEnum } from './node/constant';
import { FlowNodeInputItemType, FlowNodeOutputItemType } from './node/type';
export type FlowModuleTemplateType = {
@@ -42,3 +42,14 @@ export type SelectAppItemType = {
name: string;
logo: string;
};
/* agent */
export type ClassifyQuestionAgentItemType = {
value: string;
key: string;
};
export type ContextExtractAgentItemType = {
desc: string;
key: string;
required: boolean;
};

View File

@@ -3,6 +3,8 @@ import type { ModuleItemType } from '../module/type.d';
export type PluginItemSchema = {
_id: string;
userId: string;
teamId: string;
tmbId: string;
name: string;
avatar: string;
intro: string;