2023-05-15 08:51:32 +08:00
|
|
|
import type { Fetcher } from 'swr'
|
2023-06-16 21:47:51 +08:00
|
|
|
import { del, get, patch, post, put } from './base'
|
2023-05-15 08:51:32 +08:00
|
|
|
import type {
|
2023-11-06 19:36:32 +08:00
|
|
|
AccountIntegrate,
|
|
|
|
ApiBasedExtension,
|
|
|
|
CodeBasedExtension,
|
|
|
|
CommonResponse,
|
|
|
|
DataSourceNotion,
|
2023-08-16 23:14:27 +08:00
|
|
|
FileUploadConfigResponse,
|
2023-08-15 13:35:47 +08:00
|
|
|
ICurrentWorkspace,
|
2023-11-06 19:36:32 +08:00
|
|
|
IWorkspace,
|
2024-02-01 15:03:56 +08:00
|
|
|
InitValidateStatusResponse,
|
2023-11-06 19:36:32 +08:00
|
|
|
InvitationResponse,
|
|
|
|
LangGeniusVersionResponse,
|
|
|
|
Member,
|
|
|
|
ModerateResponse,
|
|
|
|
OauthResponse,
|
|
|
|
PluginProvider,
|
|
|
|
Provider,
|
|
|
|
ProviderAnthropicToken,
|
|
|
|
ProviderAzureToken,
|
|
|
|
SetupStatusResponse,
|
|
|
|
UserProfileOriginResponse,
|
2023-05-15 08:51:32 +08:00
|
|
|
} from '@/models/common'
|
|
|
|
import type {
|
2023-06-06 11:22:00 +08:00
|
|
|
UpdateOpenAIKeyResponse,
|
2023-05-15 08:51:32 +08:00
|
|
|
ValidateOpenAIKeyResponse,
|
|
|
|
} from '@/models/app'
|
2024-01-02 23:42:00 +08:00
|
|
|
import type {
|
|
|
|
DefaultModelResponse,
|
|
|
|
Model,
|
|
|
|
ModelItem,
|
2024-06-05 00:13:29 +08:00
|
|
|
ModelLoadBalancingConfig,
|
2024-01-02 23:42:00 +08:00
|
|
|
ModelParameterRule,
|
|
|
|
ModelProvider,
|
2024-06-05 00:13:29 +08:00
|
|
|
ModelTypeEnum,
|
2024-01-02 23:42:00 +08:00
|
|
|
} from '@/app/components/header/account-setting/model-provider-page/declarations'
|
2023-11-18 11:53:35 +08:00
|
|
|
import type { RETRIEVE_METHOD } from '@/types/app'
|
2024-05-15 16:14:49 +08:00
|
|
|
import type { SystemFeatures } from '@/types/feature'
|
2023-05-15 08:51:32 +08:00
|
|
|
|
2023-09-25 12:49:16 +08:00
|
|
|
export const login: Fetcher<CommonResponse & { data: string }, { url: string; body: Record<string, any> }> = ({ url, body }) => {
|
|
|
|
return post(url, { body }) as Promise<CommonResponse & { data: string }>
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const setup: Fetcher<CommonResponse, { body: Record<string, any> }> = ({ body }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return post<CommonResponse>('/setup', { body })
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
|
|
|
|
2024-02-01 15:03:56 +08:00
|
|
|
export const initValidate: Fetcher<CommonResponse, { body: Record<string, any> }> = ({ body }) => {
|
|
|
|
return post<CommonResponse>('/init', { body })
|
|
|
|
}
|
|
|
|
|
|
|
|
export const fetchInitValidateStatus = () => {
|
|
|
|
return get<InitValidateStatusResponse>('/init')
|
|
|
|
}
|
|
|
|
|
2023-08-07 13:19:47 +08:00
|
|
|
export const fetchSetupStatus = () => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return get<SetupStatusResponse>('/setup')
|
2023-08-07 13:19:47 +08:00
|
|
|
}
|
|
|
|
|
2023-05-15 08:51:32 +08:00
|
|
|
export const fetchUserProfile: Fetcher<UserProfileOriginResponse, { url: string; params: Record<string, any> }> = ({ url, params }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return get<UserProfileOriginResponse>(url, params, { needAllResponseContent: true })
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const updateUserProfile: Fetcher<CommonResponse, { url: string; body: Record<string, any> }> = ({ url, body }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return post<CommonResponse>(url, { body })
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const logout: Fetcher<CommonResponse, { url: string; params: Record<string, any> }> = ({ url, params }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return get<CommonResponse>(url, params)
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const fetchLanggeniusVersion: Fetcher<LangGeniusVersionResponse, { url: string; params: Record<string, any> }> = ({ url, params }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return get<LangGeniusVersionResponse>(url, { params })
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const oauth: Fetcher<OauthResponse, { url: string; params: Record<string, any> }> = ({ url, params }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return get<OauthResponse>(url, { params })
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const oneMoreStep: Fetcher<CommonResponse, { url: string; body: Record<string, any> }> = ({ url, body }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return post<CommonResponse>(url, { body })
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const fetchMembers: Fetcher<{ accounts: Member[] | null }, { url: string; params: Record<string, any> }> = ({ url, params }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return get<{ accounts: Member[] | null }>(url, { params })
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const fetchProviders: Fetcher<Provider[] | null, { url: string; params: Record<string, any> }> = ({ url, params }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return get<Provider[] | null>(url, { params })
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const validateProviderKey: Fetcher<ValidateOpenAIKeyResponse, { url: string; body: { token: string } }> = ({ url, body }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return post<ValidateOpenAIKeyResponse>(url, { body })
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
2023-07-17 00:14:32 +08:00
|
|
|
export const updateProviderAIKey: Fetcher<UpdateOpenAIKeyResponse, { url: string; body: { token: string | ProviderAzureToken | ProviderAnthropicToken } }> = ({ url, body }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return post<UpdateOpenAIKeyResponse>(url, { body })
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const fetchAccountIntegrates: Fetcher<{ data: AccountIntegrate[] | null }, { url: string; params: Record<string, any> }> = ({ url, params }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return get<{ data: AccountIntegrate[] | null }>(url, { params })
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
|
|
|
|
2023-08-31 01:18:31 +08:00
|
|
|
export const inviteMember: Fetcher<InvitationResponse, { url: string; body: Record<string, any> }> = ({ url, body }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return post<InvitationResponse>(url, { body })
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const updateMemberRole: Fetcher<CommonResponse, { url: string; body: Record<string, any> }> = ({ url, body }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return put<CommonResponse>(url, { body })
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
|
|
|
|
2023-06-06 11:22:00 +08:00
|
|
|
export const deleteMemberOrCancelInvitation: Fetcher<CommonResponse, { url: string }> = ({ url }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return del<CommonResponse>(url)
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const fetchFilePreview: Fetcher<{ content: string }, { fileID: string }> = ({ fileID }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return get<{ content: string }>(`/files/${fileID}/preview`)
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
|
|
|
|
2023-08-15 13:35:47 +08:00
|
|
|
export const fetchCurrentWorkspace: Fetcher<ICurrentWorkspace, { url: string; params: Record<string, any> }> = ({ url, params }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return get<ICurrentWorkspace>(url, { params })
|
2023-08-15 13:35:47 +08:00
|
|
|
}
|
|
|
|
|
2023-12-18 16:25:37 +08:00
|
|
|
export const updateCurrentWorkspace: Fetcher<ICurrentWorkspace, { url: string; body: Record<string, any> }> = ({ url, body }) => {
|
|
|
|
return post<ICurrentWorkspace>(url, { body })
|
|
|
|
}
|
|
|
|
|
2023-05-15 08:51:32 +08:00
|
|
|
export const fetchWorkspaces: Fetcher<{ workspaces: IWorkspace[] }, { url: string; params: Record<string, any> }> = ({ url, params }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return get<{ workspaces: IWorkspace[] }>(url, { params })
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const switchWorkspace: Fetcher<CommonResponse & { new_tenant: IWorkspace }, { url: string; body: Record<string, any> }> = ({ url, body }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return post<CommonResponse & { new_tenant: IWorkspace }>(url, { body })
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
2023-06-16 21:47:51 +08:00
|
|
|
|
|
|
|
export const fetchDataSource: Fetcher<{ data: DataSourceNotion[] }, { url: string }> = ({ url }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return get<{ data: DataSourceNotion[] }>(url)
|
2023-06-16 21:47:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const syncDataSourceNotion: Fetcher<CommonResponse, { url: string }> = ({ url }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return get<CommonResponse>(url)
|
2023-06-16 21:47:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const updateDataSourceNotionAction: Fetcher<CommonResponse, { url: string }> = ({ url }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return patch<CommonResponse>(url)
|
2023-06-16 21:47:51 +08:00
|
|
|
}
|
2023-07-14 11:19:26 +08:00
|
|
|
|
2023-07-27 13:27:34 +08:00
|
|
|
export const fetchPluginProviders: Fetcher<PluginProvider[] | null, string> = (url) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return get<PluginProvider[] | null>(url)
|
2023-07-27 13:27:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const validatePluginProviderKey: Fetcher<ValidateOpenAIKeyResponse, { url: string; body: { credentials: any } }> = ({ url, body }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return post<ValidateOpenAIKeyResponse>(url, { body })
|
2023-07-27 13:27:34 +08:00
|
|
|
}
|
|
|
|
export const updatePluginProviderAIKey: Fetcher<UpdateOpenAIKeyResponse, { url: string; body: { credentials: any } }> = ({ url, body }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return post<UpdateOpenAIKeyResponse>(url, { body })
|
2023-07-27 13:27:34 +08:00
|
|
|
}
|
|
|
|
|
2023-07-14 11:19:26 +08:00
|
|
|
export const invitationCheck: Fetcher<CommonResponse & { is_valid: boolean; workspace_name: string }, { url: string; params: { workspace_id: string; email: string; token: string } }> = ({ url, params }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return get<CommonResponse & { is_valid: boolean; workspace_name: string }>(url, { params })
|
2023-07-14 11:19:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const activateMember: Fetcher<CommonResponse, { url: string; body: any }> = ({ url, body }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return post<CommonResponse>(url, { body })
|
2023-07-14 11:19:26 +08:00
|
|
|
}
|
2023-08-12 00:57:13 +08:00
|
|
|
|
2024-01-02 23:42:00 +08:00
|
|
|
export const fetchModelProviders: Fetcher<{ data: ModelProvider[] }, string> = (url) => {
|
|
|
|
return get<{ data: ModelProvider[] }>(url)
|
|
|
|
}
|
|
|
|
|
2024-06-05 00:13:29 +08:00
|
|
|
export type ModelProviderCredentials = {
|
|
|
|
credentials?: Record<string, string | undefined | boolean>
|
|
|
|
load_balancing: ModelLoadBalancingConfig
|
|
|
|
}
|
|
|
|
export const fetchModelProviderCredentials: Fetcher<ModelProviderCredentials, string> = (url) => {
|
|
|
|
return get<ModelProviderCredentials>(url)
|
|
|
|
}
|
|
|
|
|
|
|
|
export const fetchModelLoadBalancingConfig: Fetcher<{
|
|
|
|
credentials?: Record<string, string | undefined | boolean>
|
|
|
|
load_balancing: ModelLoadBalancingConfig
|
|
|
|
}, string> = (url) => {
|
|
|
|
return get<{
|
|
|
|
credentials?: Record<string, string | undefined | boolean>
|
|
|
|
load_balancing: ModelLoadBalancingConfig
|
|
|
|
}>(url)
|
2024-01-02 23:42:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const fetchModelProviderModelList: Fetcher<{ data: ModelItem[] }, string> = (url) => {
|
|
|
|
return get<{ data: ModelItem[] }>(url)
|
2023-08-12 00:57:13 +08:00
|
|
|
}
|
|
|
|
|
2024-01-02 23:42:00 +08:00
|
|
|
export const fetchModelList: Fetcher<{ data: Model[] }, string> = (url) => {
|
|
|
|
return get<{ data: Model[] }>(url)
|
2023-08-12 00:57:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const validateModelProvider: Fetcher<ValidateOpenAIKeyResponse, { url: string; body: any }> = ({ url, body }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return post<ValidateOpenAIKeyResponse>(url, { body })
|
2023-08-12 00:57:13 +08:00
|
|
|
}
|
|
|
|
|
2024-06-05 00:13:29 +08:00
|
|
|
export const validateModelLoadBalancingCredentials: Fetcher<ValidateOpenAIKeyResponse, { url: string; body: any }> = ({ url, body }) => {
|
|
|
|
return post<ValidateOpenAIKeyResponse>(url, { body })
|
|
|
|
}
|
|
|
|
|
2023-08-12 00:57:13 +08:00
|
|
|
export const setModelProvider: Fetcher<CommonResponse, { url: string; body: any }> = ({ url, body }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return post<CommonResponse>(url, { body })
|
2023-08-12 00:57:13 +08:00
|
|
|
}
|
|
|
|
|
2024-01-02 23:42:00 +08:00
|
|
|
export const deleteModelProvider: Fetcher<CommonResponse, { url: string; body?: any }> = ({ url, body }) => {
|
|
|
|
return del<CommonResponse>(url, { body })
|
2023-08-12 00:57:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const changeModelProviderPriority: Fetcher<CommonResponse, { url: string; body: any }> = ({ url, body }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return post<CommonResponse>(url, { body })
|
2023-08-12 00:57:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const setModelProviderModel: Fetcher<CommonResponse, { url: string; body: any }> = ({ url, body }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return post<CommonResponse>(url, { body })
|
2023-08-12 00:57:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const deleteModelProviderModel: Fetcher<CommonResponse, { url: string }> = ({ url }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return del<CommonResponse>(url)
|
2023-08-12 00:57:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const getPayUrl: Fetcher<{ url: string }, string> = (url) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return get<{ url: string }>(url)
|
2023-08-12 00:57:13 +08:00
|
|
|
}
|
|
|
|
|
2024-01-02 23:42:00 +08:00
|
|
|
export const fetchDefaultModal: Fetcher<{ data: DefaultModelResponse }, string> = (url) => {
|
|
|
|
return get<{ data: DefaultModelResponse }>(url)
|
2023-08-12 00:57:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const updateDefaultModel: Fetcher<CommonResponse, { url: string; body: any }> = ({ url, body }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return post<CommonResponse>(url, { body })
|
2023-08-12 00:57:13 +08:00
|
|
|
}
|
2023-08-14 12:46:28 +08:00
|
|
|
|
2024-01-02 23:42:00 +08:00
|
|
|
export const fetchModelParameterRules: Fetcher<{ data: ModelParameterRule[] }, string> = (url) => {
|
|
|
|
return get<{ data: ModelParameterRule[] }>(url)
|
|
|
|
}
|
|
|
|
|
2023-08-16 23:14:27 +08:00
|
|
|
export const fetchFileUploadConfig: Fetcher<FileUploadConfigResponse, { url: string }> = ({ url }) => {
|
2023-09-15 20:54:20 +08:00
|
|
|
return get<FileUploadConfigResponse>(url)
|
2023-08-16 23:14:27 +08:00
|
|
|
}
|
2023-08-28 10:53:45 +08:00
|
|
|
|
2023-09-18 18:02:05 +08:00
|
|
|
export const fetchFreeQuotaVerify: Fetcher<{ result: string; flag: boolean; reason: string }, string> = (url) => {
|
2023-09-11 17:30:54 +08:00
|
|
|
return get(url) as Promise<{ result: string; flag: boolean; reason: string }>
|
|
|
|
}
|
2023-09-28 14:39:13 +08:00
|
|
|
|
|
|
|
export const fetchNotionConnection: Fetcher<{ data: string }, string> = (url) => {
|
|
|
|
return get(url) as Promise<{ data: string }>
|
|
|
|
}
|
|
|
|
|
|
|
|
export const fetchDataSourceNotionBinding: Fetcher<{ result: string }, string> = (url) => {
|
|
|
|
return get(url) as Promise<{ result: string }>
|
|
|
|
}
|
2023-11-06 19:36:32 +08:00
|
|
|
|
|
|
|
export const fetchApiBasedExtensionList: Fetcher<ApiBasedExtension[], string> = (url) => {
|
|
|
|
return get(url) as Promise<ApiBasedExtension[]>
|
|
|
|
}
|
|
|
|
|
|
|
|
export const fetchApiBasedExtensionDetail: Fetcher<ApiBasedExtension, string> = (url) => {
|
|
|
|
return get(url) as Promise<ApiBasedExtension>
|
|
|
|
}
|
|
|
|
|
|
|
|
export const addApiBasedExtension: Fetcher<ApiBasedExtension, { url: string; body: ApiBasedExtension }> = ({ url, body }) => {
|
|
|
|
return post(url, { body }) as Promise<ApiBasedExtension>
|
|
|
|
}
|
|
|
|
|
|
|
|
export const updateApiBasedExtension: Fetcher<ApiBasedExtension, { url: string; body: ApiBasedExtension }> = ({ url, body }) => {
|
|
|
|
return post(url, { body }) as Promise<ApiBasedExtension>
|
|
|
|
}
|
|
|
|
|
|
|
|
export const deleteApiBasedExtension: Fetcher<{ result: string }, string> = (url) => {
|
|
|
|
return del(url) as Promise<{ result: string }>
|
|
|
|
}
|
|
|
|
|
|
|
|
export const fetchCodeBasedExtensionList: Fetcher<CodeBasedExtension, string> = (url) => {
|
|
|
|
return get(url) as Promise<CodeBasedExtension>
|
|
|
|
}
|
|
|
|
|
|
|
|
export const moderate = (url: string, body: { app_id: string; text: string }) => {
|
|
|
|
return post(url, { body }) as Promise<ModerateResponse>
|
|
|
|
}
|
2023-11-18 11:53:35 +08:00
|
|
|
|
|
|
|
type RetrievalMethodsRes = {
|
|
|
|
'retrieval_method': RETRIEVE_METHOD[]
|
|
|
|
}
|
|
|
|
export const fetchSupportRetrievalMethods: Fetcher<RetrievalMethodsRes, string> = (url) => {
|
|
|
|
return get<RetrievalMethodsRes>(url)
|
|
|
|
}
|
2024-05-15 16:14:49 +08:00
|
|
|
|
|
|
|
export const getSystemFeatures = () => {
|
|
|
|
return get<SystemFeatures>('/system-features')
|
|
|
|
}
|
2024-06-05 00:13:29 +08:00
|
|
|
|
|
|
|
export const enableModel = (url: string, body: { model: string; model_type: ModelTypeEnum }) =>
|
|
|
|
patch<CommonResponse>(url, { body })
|
|
|
|
|
|
|
|
export const disableModel = (url: string, body: { model: string; model_type: ModelTypeEnum }) =>
|
|
|
|
patch<CommonResponse>(url, { body })
|