mirror of
https://github.com/router-for-me/Cli-Proxy-API-Management-Center.git
synced 2026-02-03 11:20:50 +08:00
feat: initialize new React application structure with TypeScript, ESLint, and Prettier configurations, while removing legacy files and adding new components and pages for enhanced functionality
This commit is contained in:
31
src/services/api/models.ts
Normal file
31
src/services/api/models.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* 可用模型获取
|
||||
*/
|
||||
|
||||
import axios from 'axios';
|
||||
import { normalizeModelList } from '@/utils/models';
|
||||
|
||||
const buildModelsEndpoint = (baseUrl: string): string => {
|
||||
if (!baseUrl) return '';
|
||||
const trimmed = String(baseUrl).trim().replace(/\/+$/g, '');
|
||||
if (!trimmed) return '';
|
||||
if (trimmed.endsWith('/v1')) {
|
||||
return `${trimmed}/models`;
|
||||
}
|
||||
return `${trimmed}/v1/models`;
|
||||
};
|
||||
|
||||
export const modelsApi = {
|
||||
async fetchModels(baseUrl: string, apiKey?: string) {
|
||||
const endpoint = buildModelsEndpoint(baseUrl);
|
||||
if (!endpoint) {
|
||||
throw new Error('Invalid base url');
|
||||
}
|
||||
|
||||
const response = await axios.get(endpoint, {
|
||||
headers: apiKey ? { Authorization: `Bearer ${apiKey}` } : undefined
|
||||
});
|
||||
const payload = response.data?.data ?? response.data?.models ?? response.data;
|
||||
return normalizeModelList(payload, { dedupe: true });
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user