Initial commit

This commit is contained in:
John Wang
2023-05-15 08:51:32 +08:00
commit db896255d6
744 changed files with 56028 additions and 0 deletions

118
web/models/app.ts Normal file
View File

@@ -0,0 +1,118 @@
import type { App, AppTemplate, SiteConfig } from '@/types/app'
export type AppMode = 'chat' | 'completion'
/* export type App = {
id: string
name: string
decription: string
mode: AppMode
enable_site: boolean
enable_api: boolean
api_rpm: number
api_rph: number
is_demo: boolean
model_config: AppModelConfig
providers: Array<{ provider: string; token_is_set: boolean }>
site: SiteConfig
created_at: string
}
export type AppModelConfig = {
provider: string
model_id: string
configs: {
prompt_template: string
prompt_variables: Array<PromptVariable>
completion_params: CompletionParam
}
}
export type PromptVariable = {
key: string
name: string
description: string
type: string | number
default: string
options: string[]
}
export type CompletionParam = {
max_tokens: number
temperature: number
top_p: number
echo: boolean
stop: string[]
presence_penalty: number
frequency_penalty: number
}
export type SiteConfig = {
access_token: string
title: string
author: string
support_email: string
default_language: string
customize_domain: string
theme: string
customize_token_strategy: 'must' | 'allow' | 'not_allow'
prompt_public: boolean
} */
export type AppListResponse = {
data: App[]
}
export type AppDetailResponse = App
export type AppTemplatesResponse = {
data: AppTemplate[]
}
export type CreateAppResponse = App
export type UpdateAppNameResponse = App
export type UpdateAppSiteCodeResponse = { app_id: string } & SiteConfig
export type AppDailyConversationsResponse = {
data: Array<{ date: string; conversation_count: number }>
}
export type AppDailyEndUsersResponse = {
data: Array<{ date: string; terminal_count: number }>
}
export type AppTokenCostsResponse = {
data: Array<{ date: string; token_count: number; total_price: number; currency: number }>
}
export type UpdateAppModelConfigResponse = { result: string }
export type ApikeyItemResponse = {
id: string
token: string
last_used_at: string
created_at: string
}
export type ApikeysListResponse = {
data: ApikeyItemResponse[]
}
export type CreateApiKeyResponse = {
id: string
token: string
created_at: string
}
export type ValidateOpenAIKeyResponse = {
result: string
error?: string
}
export type UpdateOpenAIKeyResponse = ValidateOpenAIKeyResponse
export type GenerationIntroductionResponse = {
introduction: string
}

92
web/models/common.ts Normal file
View File

@@ -0,0 +1,92 @@
export type CommonResponse = {
result: 'success' | 'fail'
}
export type OauthResponse = {
redirect_url: string
}
export type UserProfileResponse = {
id: string
name: string
email: string
interface_language?: string
interface_theme?: string
timezone?: string
last_login_at?: string
last_login_ip?: string
created_at?: string
}
export type UserProfileOriginResponse = {
json: () => Promise<UserProfileResponse>
bodyUsed: boolean
headers: any
}
export type LangGeniusVersionResponse = {
current_version: string
latest_version: string
version: string
release_date: string
release_notes: string
can_auto_update: boolean
current_env: string
}
export type TenantInfoResponse = {
name: string
created_at: string
providers: Array<{
provider: string
provider_name: string
token_is_set: boolean
is_valid: boolean
token_is_valid: boolean
}>
in_trail: boolean
trial_end_reason: null | 'trial_exceeded' | 'using_custom'
}
export type Member = Pick<UserProfileResponse, 'id' | 'name' | 'email' | 'last_login_at' | 'created_at'> & {
avatar: string
status: 'pending' | 'active' | 'banned' | 'closed'
role: 'owner' | 'admin' | 'normal'
}
export type ProviderAzureToken = {
azure_api_base: string
azure_api_key: string
azure_api_type: string
azure_api_version: string
}
export type Provider = {
provider_name: string
provider_type: string
is_valid: boolean
is_enabled: boolean
last_used: string
token?: string | ProviderAzureToken
}
export type ProviderHosted = Provider & {
quota_type: string
quota_limit: number
quota_used: number
}
export type AccountIntegrate = {
provider: 'google' | 'github'
created_at: number
is_bound: boolean
link: string
}
export interface IWorkspace {
id: string
name: string
plan: string
status: string
created_at: number
current: boolean
}

339
web/models/datasets.ts Normal file
View File

@@ -0,0 +1,339 @@
import { AppMode } from './app'
export type DataSet = {
id: string
name: string
description: string
permission: 'only_me' | 'all_team_members'
data_source_type: 'upload_file'
indexing_technique: 'high_quality' | 'economy'
created_by: string
updated_by: string
updated_at: number
app_count: number
document_count: number
word_count: number
}
export type File = {
id: string
name: string
size: number
extension: string
mime_type: string
created_by: string
created_at: number
}
export type DataSetListResponse = {
data: DataSet[]
}
export type IndexingEstimateResponse = {
tokens: number
total_price: number
currency: string
total_segments: number
preview: string[]
}
export interface FileIndexingEstimateResponse extends IndexingEstimateResponse {
total_nodes: number
}
export type IndexingStatusResponse = {
id: string
indexing_status: DocumentIndexingStatus
processing_started_at: number
parsing_completed_at: number
cleaning_completed_at: number
splitting_completed_at: number
completed_at: any
paused_at: any
error: any
stopped_at: any
completed_segments: number
total_segments: number
}
export type ProcessMode = 'automatic' | 'custom'
export type ProcessRuleResponse = {
mode: ProcessMode
rules: Rules
}
export type Rules = {
pre_processing_rules: PreProcessingRule[]
segmentation: Segmentation
}
export type PreProcessingRule = {
id: string
enabled: boolean
}
export type Segmentation = {
separator: string
max_tokens: number
}
export const DocumentIndexingStatusList = [
'waiting',
'parsing',
'cleaning',
'splitting',
'indexing',
'paused',
'error',
'completed',
] as const
export type DocumentIndexingStatus = typeof DocumentIndexingStatusList[number]
export const DisplayStatusList = [
"queuing",
"indexing",
"paused",
"error",
"available",
"enabled",
"disabled",
"archived",
] as const;
export type DocumentDisplayStatus = typeof DisplayStatusList[number];
export type DataSourceInfo = {
upload_file: {
id: string
name: string
size: number
mime_type: string
created_at: number
created_by: string
extension: string
}
}
export type InitialDocumentDetail = {
id: string
position: number
dataset_id: string
data_source_type: 'upload_file'
data_source_info: DataSourceInfo
dataset_process_rule_id: string
name: string
created_from: 'api' | 'web'
created_by: string
created_at: number
indexing_status: DocumentIndexingStatus
display_status: DocumentDisplayStatus
}
export type SimpleDocumentDetail = InitialDocumentDetail & {
enabled: boolean
word_count: number
error?: string | null
archived: boolean
updated_at: number
hit_count: number
dataset_process_rule_id?: string
}
export type DocumentListResponse = {
data: SimpleDocumentDetail[]
has_more: boolean
total: number
page: number
limit: number
}
export type CreateDocumentReq = {
original_document_id?: string
indexing_technique?: string;
name: string
data_source: DataSource
process_rule: ProcessRule
}
export type DataSource = {
type: string
info: string // upload_file_id
name: string
}
export type ProcessRule = {
mode: string
rules: Rules
}
export type createDocumentResponse = {
dataset?: DataSet
document: InitialDocumentDetail
}
export type FullDocumentDetail = SimpleDocumentDetail & {
batch: string
created_api_request_id: string
processing_started_at: number
parsing_completed_at: number
cleaning_completed_at: number
splitting_completed_at: number
tokens: number
indexing_latency: number
completed_at: number
paused_by: string
paused_at: number
stopped_at: number
indexing_status: string
disabled_at: number
disabled_by: string
archived_reason: 'rule_modified' | 're_upload'
archived_by: string
archived_at: number
doc_type?: DocType | null
doc_metadata?: DocMetadata | null
segment_count: number
[key: string]: any
}
export type DocMetadata = {
title: string
language: string
author: string
publisher: string
publicationDate: string
ISBN: string
category: string
[key: string]: string
}
export const CUSTOMIZABLE_DOC_TYPES = [
"book",
"web_page",
"paper",
"social_media_post",
"personal_document",
"business_document",
"im_chat_log",
] as const;
export const FIXED_DOC_TYPES = ["synced_from_github", "synced_from_notion", "wikipedia_entry"] as const;
export type CustomizableDocType = typeof CUSTOMIZABLE_DOC_TYPES[number];
export type FixedDocType = typeof FIXED_DOC_TYPES[number];
export type DocType = CustomizableDocType | FixedDocType;
export type DocumentDetailResponse = FullDocumentDetail
export const SEGMENT_STATUS_LIST = ['waiting', 'completed', 'error', 'indexing']
export type SegmentStatus = typeof SEGMENT_STATUS_LIST[number]
export type SegmentsQuery = {
last_id?: string
limit: number
// status?: SegmentStatus
hit_count_gte?: number
keyword?: string
enabled?: boolean
}
export type SegmentDetailModel = {
id: string
position: number
document_id: string
content: string
word_count: number
tokens: number
keywords: string[]
index_node_id: string
index_node_hash: string
hit_count: number
enabled: boolean
disabled_at: number
disabled_by: string
status: SegmentStatus
created_by: string
created_at: number
indexing_at: number
completed_at: number
error: string | null
stopped_at: number
}
export type SegmentsResponse = {
data: SegmentDetailModel[]
has_more: boolean
limit: number
total: number
}
export type HitTestingRecord = {
id: string
content: string
source: 'app' | 'hit_testing' | 'plugin'
source_app_id: string
created_by_role: 'account' | 'end_user'
created_by: string
created_at: number
}
export type HitTesting = {
segment: Segment
score: number
tsne_position: TsnePosition
}
export type Segment = {
id: string
document: Document
content: string
position: number
word_count: number
tokens: number
keywords: string[]
hit_count: number
index_node_hash: string
}
export type Document = {
id: string
data_source_type: string
name: string
doc_type: DocType
}
export type HitTestingRecordsResponse = {
data: HitTestingRecord[]
has_more: boolean
limit: number
total: number
page: number
}
export type TsnePosition = {
x: number
y: number
}
export type HitTestingResponse = {
query: {
content: string
tsne_position: TsnePosition
}
records: Array<HitTesting>
}
export type RelatedApp = {
id: string
name: string
mode: AppMode
icon: string
icon_background: string
}
export type RelatedAppResponse = {
data: Array<RelatedApp>
total: number
}

115
web/models/debug.ts Normal file
View File

@@ -0,0 +1,115 @@
export type Inputs = Record<string, string | number | object>
export type PromptVariable = {
key: string,
name: string,
type: string, // "string" | "number" | "select",
default?: string | number,
required: boolean,
options?: string[]
max_length?: number
}
export type CompletionParams = {
max_tokens: number,
temperature: number,
top_p: number,
presence_penalty: number,
frequency_penalty: number,
}
export type ModelId = "gpt-3.5-turbo" | "text-davinci-003"
export type PromptConfig = {
prompt_template: string,
prompt_variables: PromptVariable[],
}
export type MoreLikeThisConfig = {
enabled: boolean
}
export type SuggestedQuestionsAfterAnswerConfig = MoreLikeThisConfig
// frontend use. Not the same as backend
export type ModelConfig = {
provider: string, // LLM Provider: for example "OPENAI"
model_id: string,
configs: PromptConfig
}
export type DebugRequestBody = {
inputs: Inputs,
query: string,
completion_params: CompletionParams,
model_config: ModelConfig
}
export type DebugResponse = {
id: string,
answer: string,
created_at: string,
}
export type DebugResponseStream = {
id: string,
data: string,
created_at: string,
}
export type FeedBackRequestBody = {
message_id: string,
rating: 'like' | 'dislike',
content?: string,
from_source: 'api' | 'log'
}
export type FeedBackResponse = {
message_id: string,
rating: 'like' | 'dislike'
}
// Log session list
export type LogSessionListQuery = {
keyword?: string,
start?: string, // format datetime(YYYY-mm-dd HH:ii)
end?: string, // format datetime(YYYY-mm-dd HH:ii)
page: number,
limit: number, // default 20. 1-100
}
export type LogSessionListResponse = {
data: {
id: string,
conversation_id: string,
query: string, // user's query question
message: string, // prompt send to LLM
answer: string,
creat_at: string,
}[],
total: number,
page: number,
}
// log session detail and debug
export type LogSessionDetailResponse = {
id: string,
cnversation_id: string,
model_provider: string,
query: string,
inputs: Record<string, string | number | object>[],
message: string,
message_tokens: number, // number of tokens in message
answer: string,
answer_tokens: number, // number of tokens in answer
provider_response_latency: number, // used time in ms
from_source: 'api' | 'log',
}
export type SavedMessage = {
id: string,
answer: string
}

11
web/models/history.ts Normal file
View File

@@ -0,0 +1,11 @@
export type History = {
id: string
source: string
target: string
}
export type HistoryResponse = {
histories: History[]
}
export const fetchHistories = (url: string) =>
fetch(url).then<HistoryResponse>(r => r.json())

192
web/models/log.ts Normal file
View File

@@ -0,0 +1,192 @@
// Log type contains key:string conversation_id:string created_at:string quesiton:string answer:string
export type Conversation = {
id: string
key: string
conversationId: string
question: string
answer: string
userRate: number
adminRate: number
}
export type ConversationListResponse = {
logs: Conversation[]
}
export const fetchLogs = (url: string) =>
fetch(url).then<ConversationListResponse>(r => r.json())
export const CompletionParams = ['temperature', 'top_p', 'presence_penalty', 'max_token', 'stop', 'frequency_penalty'] as const
export type CompletionParamType = typeof CompletionParams[number]
export type CompletionParamsType = {
max_tokens: number
temperature: number
top_p: number
stop: string[]
presence_penalty: number
frequency_penalty: number
}
export type ModelConfigDetail = {
introduction: string
prompt_template: string
prompt_variables: Array<{
key: string
name: string
description: string
type: string | number
default: string
options: string[]
}>
completion_params: CompletionParamsType
}
export type Annotation = {
content: string
account: {
id: string
name: string
email: string
}
created_at?: number
}
export type MessageContent = {
id: string
conversation_id: string
query: string
inputs: Record<string, any>
// message: Record<string, any>
message: string
message_tokens: number
answer_tokens: number
answer: string
provider_response_latency: number
created_at: number
annotation: Annotation
feedbacks: Array<{
rating: 'like' | 'dislike' | null
content: string | null
from_source?: 'admin' | 'user'
from_end_user_id?: string
}>
}
export type CompletionConversationGeneralDetail = {
id: string
status: 'normal' | 'finished'
from_source: 'api' | 'console'
from_end_user_id: string
from_account_id: string
read_at: Date
created_at: number
annotation: Annotation
user_feedback_stats: {
like: number
dislike: number
}
admin_feedback_stats: {
like: number
dislike: number
}
model_config: {
provider: string
model_id: string
configs: Pick<ModelConfigDetail, 'prompt_template'>
}
message: Pick<MessageContent, 'inputs' | 'query' | 'answer' | 'message'>
}
export type CompletionConversationFullDetailResponse = {
id: string
status: 'normal' | 'finished'
from_source: 'api' | 'console'
from_end_user_id: string
from_account_id: string
// read_at: Date
created_at: number
model_config: {
provider: string
model_id: string
configs: ModelConfigDetail
}
message: MessageContent
}
export type CompletionConversationsResponse = {
data: Array<CompletionConversationGeneralDetail>
has_more: boolean
limit: number
total: number
page: number
}
export type CompletionConversationsRequest = {
keyword: string
start: string
end: string
annotation_status: string
page: number
limit: number // The default value is 20 and the range is 1-100
}
export type ChatConversationGeneralDetail = Omit<CompletionConversationGeneralDetail, 'message' | 'annotation'> & {
summary: string
message_count: number
annotated: boolean
}
export type ChatConversationsResponse = {
data: Array<ChatConversationGeneralDetail>
has_more: boolean
limit: number
total: number
page: number
}
export type ChatConversationsRequest = CompletionConversationsRequest & { message_count: number }
export type ChatConversationFullDetailResponse = Omit<CompletionConversationGeneralDetail, 'message' | 'model_config'> & {
message_count: number
model_config: {
provider: string
model_id: string
configs: ModelConfigDetail
}
}
export type ChatMessagesRequest = {
conversation_id: string
first_id?: string
limit: number
}
export type ChatMessage = MessageContent
export type ChatMessagesResponse = {
data: Array<ChatMessage>
has_more: boolean
limit: number
}
export const MessageRatings = ['like', 'dislike', null] as const
export type MessageRating = typeof MessageRatings[number]
export type LogMessageFeedbacksRequest = {
message_id: string
rating: MessageRating
content?: string
}
export type LogMessageFeedbacksResponse = {
result: 'success' | 'error'
}
export type LogMessageAnnotationsRequest = Omit<LogMessageFeedbacksRequest, 'rating'>
export type LogMessageAnnotationsResponse = LogMessageFeedbacksResponse
export type AnnotationsCountResponse = {
count: number
}

19
web/models/share.ts Normal file
View File

@@ -0,0 +1,19 @@
import { Locale } from '@/i18n'
export type ResponseHolder = {}
export type ConversationItem = {
id: string
name: string
inputs: Record<string, any> | null
introduction: string,
}
export type SiteInfo = {
title: string
description: string
default_language: Locale
prompt_public: boolean
copyright?: string
privacy_policy?: string
}

17
web/models/user.ts Normal file
View File

@@ -0,0 +1,17 @@
export type User = {
id: string
firstName: string
lastName: string
name: string
phone: string
username: string
email: string
avatar: string
}
export type UserResponse = {
users: User[]
}
export const fetchUsers = (url: string) =>
fetch(url).then<UserResponse>(r => r.json())