add detailed console logging for model fetching and processing

This commit is contained in:
Russell Ballestrini 2025-10-11 09:41:11 -04:00
parent 9ba6ef8522
commit ca03398bb3

View file

@ -62,10 +62,11 @@ export async function fetchModelsFromEndpoints() {
// If no valid cache, fetch models from all endpoints
const fetchPromises = endpointsToFetch.map(async (endpoint) => {
try {
console.log(`🔍 Fetching models from ${endpoint.url}...`);
const headers = {
"Content-Type": "application/json"
};
// Add authorization for custom API
if (endpoint.id === customBaseURL && useCustomAPI) {
const customAPIKey = localStorage.getItem("customAPIKey");
@ -73,25 +74,30 @@ export async function fetchModelsFromEndpoints() {
headers["Authorization"] = `Bearer ${customAPIKey}`;
}
}
const res = await fetch(`${endpoint.url}/models`, { headers });
if (!res.ok)
if (!res.ok) {
console.error(`❌ HTTP error fetching from ${endpoint.url}: status ${res.status}`);
throw new Error(
`HTTP error! status: ${res.status} from ${endpoint.url}`,
);
}
const jsonResponse = await res.json();
console.log(`📦 Raw response from ${endpoint.url}:`, jsonResponse);
// Expected JSON structure: { data: [ { id, ... }, ... ], object: "list" }
const models = jsonResponse.data || [];
console.log(`✅ Fetched ${models.length} models from ${endpoint.url}:`, models.map(m => m.id));
// Map each model to include its endpoint ID, unique ID, and model name
return models.map((model) => {
console.log(`🔧 Processing model ${model.id} from ${endpoint.id}`);
// Get context window size from API or use known values for Groq models
let maxTokens = model.max_tokens || model.context_length || model.max_context_length || model.max_model_len;
console.log(`📊 Model ${model.id} - detected maxTokens from API: ${maxTokens}`);
// Check if endpoint has modelContextWindows config (for Ollama/other endpoints without API max_model_len)
if (endpoint.modelContextWindows && endpoint.modelContextWindows[model.id]) {
maxTokens = endpoint.modelContextWindows[model.id];
console.log(`Using configured context window for model ${model.id}: ${maxTokens} tokens`);
console.log(`✏️ Using configured context window for model ${model.id}: ${maxTokens} tokens`);
}
// Hardcoded context windows for known Groq models (since API doesn't return them)