add custom API models to refresh: fetch /v1/models from custom endpoint when configured

This commit is contained in:
Russell Ballestrini 2025-07-11 00:09:05 -04:00
parent dc95e4c535
commit c96a09c1f1

View file

@ -1,5 +1,5 @@
// Model registry and selection functionality
import { VLLM_ENDPOINTS } from "./config.js";
import { VLLM_ENDPOINTS, getAPIConfig } from "./config.js";
// This registry maps a model's ID to the endpoint where it resides.
export const modelRegistry = {};
@ -28,10 +28,31 @@ export async function fetchModelsFromEndpoints() {
}
}
// Collect endpoints to fetch from
const endpointsToFetch = [...VLLM_ENDPOINTS];
// Add custom API endpoint if configured
const apiConfig = getAPIConfig();
if (apiConfig.isCustom) {
endpointsToFetch.push({
id: "custom-api",
url: apiConfig.endpoint
});
}
// If no valid cache, fetch models from all endpoints
const fetchPromises = VLLM_ENDPOINTS.map(async (endpoint) => {
const fetchPromises = endpointsToFetch.map(async (endpoint) => {
try {
const res = await fetch(`${endpoint.url}/models`);
const headers = {
"Content-Type": "application/json"
};
// Add authorization for custom API
if (endpoint.id === "custom-api" && apiConfig.isCustom) {
headers["Authorization"] = `Bearer ${apiConfig.apiKey}`;
}
const res = await fetch(`${endpoint.url}/models`, { headers });
if (!res.ok)
throw new Error(
`HTTP error! status: ${res.status} from ${endpoint.url}`,