2023-05-15 08:51:32 +08:00
|
|
|
import type { Fetcher } from 'swr'
|
|
|
|
import { del, get, post } from './base'
|
2023-05-31 11:21:30 +08:00
|
|
|
import type { ApikeysListResponse, AppDailyConversationsResponse, AppDailyEndUsersResponse, AppDetailResponse, AppListResponse, AppStatisticsResponse, AppTemplatesResponse, AppTokenCostsResponse, CreateApiKeyResponse, GenerationIntroductionResponse, UpdateAppModelConfigResponse, UpdateAppNameResponse, UpdateAppSiteCodeResponse, UpdateOpenAIKeyResponse, ValidateOpenAIKeyResponse } from '@/models/app'
|
2023-05-15 08:51:32 +08:00
|
|
|
import type { CommonResponse } from '@/models/common'
|
|
|
|
import type { AppMode, ModelConfig } from '@/types/app'
|
|
|
|
|
2023-05-20 21:55:47 +08:00
|
|
|
export const fetchAppList: Fetcher<AppListResponse, { url: string; params?: Record<string, any> }> = ({ url, params }) => {
|
|
|
|
return get(url, { params }) as Promise<AppListResponse>
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const fetchAppDetail: Fetcher<AppDetailResponse, { url: string; id: string }> = ({ url, id }) => {
|
|
|
|
return get(`${url}/${id}`) as Promise<AppDetailResponse>
|
|
|
|
}
|
|
|
|
|
|
|
|
export const fetchAppTemplates: Fetcher<AppTemplatesResponse, { url: string }> = ({ url }) => {
|
|
|
|
return get(url) as Promise<AppTemplatesResponse>
|
|
|
|
}
|
|
|
|
|
2023-05-31 11:21:30 +08:00
|
|
|
export const createApp: Fetcher<AppDetailResponse, { name: string; icon: string; icon_background: string; mode: AppMode; config?: ModelConfig }> = ({ name, icon, icon_background, mode, config }) => {
|
2023-05-19 17:36:44 +08:00
|
|
|
return post('apps', { body: { name, icon, icon_background, mode, model_config: config } }) as Promise<AppDetailResponse>
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const deleteApp: Fetcher<CommonResponse, string> = (appID) => {
|
|
|
|
return del(`apps/${appID}`) as Promise<CommonResponse>
|
|
|
|
}
|
|
|
|
|
|
|
|
// path: /apps/{appId}/name
|
|
|
|
export const updateAppName: Fetcher<UpdateAppNameResponse, { url: string; body: Record<string, any> }> = ({ url, body }) => {
|
|
|
|
return post(url, { body }) as Promise<UpdateAppNameResponse>
|
|
|
|
}
|
|
|
|
|
|
|
|
export const updateAppSiteStatus: Fetcher<AppDetailResponse, { url: string; body: Record<string, any> }> = ({ url, body }) => {
|
|
|
|
return post(url, { body }) as Promise<AppDetailResponse>
|
|
|
|
}
|
|
|
|
|
|
|
|
export const updateAppApiStatus: Fetcher<AppDetailResponse, { url: string; body: Record<string, any> }> = ({ url, body }) => {
|
|
|
|
return post(url, { body }) as Promise<AppDetailResponse>
|
|
|
|
}
|
|
|
|
|
|
|
|
// path: /apps/{appId}/rate-limit
|
|
|
|
export const updateAppRateLimit: Fetcher<AppDetailResponse, { url: string; body: Record<string, any> }> = ({ url, body }) => {
|
|
|
|
return post(url, { body }) as Promise<AppDetailResponse>
|
|
|
|
}
|
|
|
|
|
|
|
|
export const updateAppSiteAccessToken: Fetcher<UpdateAppSiteCodeResponse, { url: string }> = ({ url }) => {
|
|
|
|
return post(url) as Promise<UpdateAppSiteCodeResponse>
|
|
|
|
}
|
|
|
|
|
|
|
|
export const updateAppSiteConfig: Fetcher<AppDetailResponse, { url: string; body: Record<string, any> }> = ({ url, body }) => {
|
|
|
|
return post(url, { body }) as Promise<AppDetailResponse>
|
|
|
|
}
|
|
|
|
|
|
|
|
export const getAppDailyConversations: Fetcher<AppDailyConversationsResponse, { url: string; params: Record<string, any> }> = ({ url, params }) => {
|
|
|
|
return get(url, { params }) as Promise<AppDailyConversationsResponse>
|
|
|
|
}
|
|
|
|
|
2023-05-31 11:21:30 +08:00
|
|
|
export const getAppStatistics: Fetcher<AppStatisticsResponse, { url: string; params: Record<string, any> }> = ({ url, params }) => {
|
|
|
|
return get(url, { params }) as Promise<AppStatisticsResponse>
|
|
|
|
}
|
|
|
|
|
2023-05-15 08:51:32 +08:00
|
|
|
export const getAppDailyEndUsers: Fetcher<AppDailyEndUsersResponse, { url: string; params: Record<string, any> }> = ({ url, params }) => {
|
|
|
|
return get(url, { params }) as Promise<AppDailyEndUsersResponse>
|
|
|
|
}
|
|
|
|
|
|
|
|
export const getAppTokenCosts: Fetcher<AppTokenCostsResponse, { url: string; params: Record<string, any> }> = ({ url, params }) => {
|
|
|
|
return get(url, { params }) as Promise<AppTokenCostsResponse>
|
|
|
|
}
|
|
|
|
|
|
|
|
export const updateAppModelConfig: Fetcher<UpdateAppModelConfigResponse, { url: string; body: Record<string, any> }> = ({ url, body }) => {
|
|
|
|
return post(url, { body }) as Promise<UpdateAppModelConfigResponse>
|
|
|
|
}
|
|
|
|
|
|
|
|
// For temp testing
|
|
|
|
export const fetchAppListNoMock: Fetcher<AppListResponse, { url: string; params: Record<string, any> }> = ({ url, params }) => {
|
|
|
|
return get(url, params) as Promise<AppListResponse>
|
|
|
|
}
|
|
|
|
|
|
|
|
export const fetchApiKeysList: Fetcher<ApikeysListResponse, { url: string; params: Record<string, any> }> = ({ url, params }) => {
|
|
|
|
return get(url, params) as Promise<ApikeysListResponse>
|
|
|
|
}
|
|
|
|
|
|
|
|
export const delApikey: Fetcher<CommonResponse, { url: string; params: Record<string, any> }> = ({ url, params }) => {
|
|
|
|
return del(url, params) as Promise<CommonResponse>
|
|
|
|
}
|
|
|
|
|
|
|
|
export const createApikey: Fetcher<CreateApiKeyResponse, { url: string; body: Record<string, any> }> = ({ url, body }) => {
|
|
|
|
return post(url, body) as Promise<CreateApiKeyResponse>
|
|
|
|
}
|
|
|
|
|
|
|
|
export const validateOpenAIKey: Fetcher<ValidateOpenAIKeyResponse, { url: string; body: { token: string } }> = ({ url, body }) => {
|
|
|
|
return post(url, { body }) as Promise<ValidateOpenAIKeyResponse>
|
|
|
|
}
|
|
|
|
|
|
|
|
export const updateOpenAIKey: Fetcher<UpdateOpenAIKeyResponse, { url: string; body: { token: string } }> = ({ url, body }) => {
|
|
|
|
return post(url, { body }) as Promise<UpdateOpenAIKeyResponse>
|
|
|
|
}
|
|
|
|
|
|
|
|
export const generationIntroduction: Fetcher<GenerationIntroductionResponse, { url: string; body: { prompt_template: string } }> = ({ url, body }) => {
|
|
|
|
return post(url, { body }) as Promise<GenerationIntroductionResponse>
|
|
|
|
}
|