feat: add admin usage statistics and LLM configuration management
This commit is contained in:
@@ -226,6 +226,61 @@ export const authApi = {
|
||||
|
||||
}
|
||||
|
||||
export interface BackendStats {
|
||||
backend_type: string
|
||||
job_count: number
|
||||
char_count: number
|
||||
}
|
||||
|
||||
export interface UserUsageStats {
|
||||
user_id: number
|
||||
username: string
|
||||
email: string
|
||||
llm_prompt_tokens: number
|
||||
llm_completion_tokens: number
|
||||
tts_backends: BackendStats[]
|
||||
}
|
||||
|
||||
export const adminApi = {
|
||||
setAliyunKey: async (apiKey: string): Promise<void> => {
|
||||
await apiClient.post(API_ENDPOINTS.ADMIN.SET_ALIYUN_KEY, { api_key: apiKey })
|
||||
},
|
||||
|
||||
deleteAliyunKey: async (): Promise<void> => {
|
||||
await apiClient.delete(API_ENDPOINTS.ADMIN.SET_ALIYUN_KEY)
|
||||
},
|
||||
|
||||
verifyAliyunKey: async (): Promise<{ valid: boolean; message: string }> => {
|
||||
const response = await apiClient.get<{ valid: boolean; message: string }>(
|
||||
API_ENDPOINTS.ADMIN.VERIFY_ALIYUN_KEY
|
||||
)
|
||||
return response.data
|
||||
},
|
||||
|
||||
getLLMConfig: async (): Promise<{ base_url?: string; model?: string; has_key: boolean }> => {
|
||||
const response = await apiClient.get<{ base_url?: string; model?: string; has_key: boolean }>(
|
||||
API_ENDPOINTS.ADMIN.LLM_CONFIG
|
||||
)
|
||||
return response.data
|
||||
},
|
||||
|
||||
setLLMConfig: async (config: { base_url: string; api_key: string; model: string }): Promise<void> => {
|
||||
await apiClient.put(API_ENDPOINTS.ADMIN.LLM_CONFIG, config)
|
||||
},
|
||||
|
||||
deleteLLMConfig: async (): Promise<void> => {
|
||||
await apiClient.delete(API_ENDPOINTS.ADMIN.LLM_CONFIG)
|
||||
},
|
||||
|
||||
getUsage: async (dateFrom?: string, dateTo?: string): Promise<UserUsageStats[]> => {
|
||||
const params: Record<string, string> = {}
|
||||
if (dateFrom) params.date_from = dateFrom
|
||||
if (dateTo) params.date_to = dateTo
|
||||
const response = await apiClient.get<UserUsageStats[]>('/admin/usage', { params })
|
||||
return response.data
|
||||
},
|
||||
}
|
||||
|
||||
export const ttsApi = {
|
||||
getLanguages: async (): Promise<Language[]> => {
|
||||
const response = await apiClient.get<string[]>(API_ENDPOINTS.TTS.LANGUAGES)
|
||||
|
||||
@@ -28,6 +28,11 @@ export const API_ENDPOINTS = {
|
||||
UPDATE: (id: number) => `/users/${id}`,
|
||||
DELETE: (id: number) => `/users/${id}`,
|
||||
},
|
||||
ADMIN: {
|
||||
SET_ALIYUN_KEY: '/users/system/aliyun-key',
|
||||
VERIFY_ALIYUN_KEY: '/users/system/aliyun-key/verify',
|
||||
LLM_CONFIG: '/users/system/llm-config',
|
||||
},
|
||||
VOICE_DESIGNS: {
|
||||
LIST: '/voice-designs',
|
||||
CREATE: '/voice-designs',
|
||||
|
||||
Reference in New Issue
Block a user