deepsite / test-detection.js
dr-data
Fix preview component: eliminate blinking, ensure HTML updates, add smooth transitions
dcd5e1d
// Test script to verify model detection logic
const MODELS = [
{
value: "deepseek-ai/DeepSeek-V3-0324",
label: "DeepSeek V3 O324",
providers: ["fireworks-ai", "nebius", "sambanova", "novita", "hyperbolic"],
autoProvider: "novita",
},
{
value: "deepseek-ai/DeepSeek-R1-0528",
label: "DeepSeek R1 0528",
providers: ["fireworks-ai", "novita", "hyperbolic", "nebius", "together", "sambanova"],
autoProvider: "novita",
isNew: true,
isThinker: true,
},
];
// Model ID mapping from HuggingFace format to OpenRouter format
const HF_TO_OPENROUTER_MODEL_MAP = {
"deepseek-ai/DeepSeek-V3-0324": "deepseek/deepseek-v3",
"deepseek-ai/DeepSeek-R1-0528": "deepseek/deepseek-r1",
};
function getOpenRouterModelId(hfModelId) {
return HF_TO_OPENROUTER_MODEL_MAP[hfModelId] || hfModelId;
}
function testModelDetection(model, provider, openrouterApiKey) {
// Enhanced OpenRouter detection logic
const isExplicitOpenRouter = provider === "openrouter" || !!openrouterApiKey;
const modelExistsInHF = MODELS.find((m) => m.value === model || m.label === model);
const isOpenRouterRequest = isExplicitOpenRouter || (!modelExistsInHF && model);
const selectedModel = !isOpenRouterRequest
? MODELS.find((m) => m.value === model || m.label === model)
: null;
const finalModelId = isOpenRouterRequest ? getOpenRouterModelId(model) : (selectedModel?.value || null);
return {
input: { model, provider, hasApiKey: !!openrouterApiKey },
detection: {
isExplicitOpenRouter,
modelExistsInHF: !!modelExistsInHF,
isOpenRouterRequest,
selectedModel: selectedModel?.value || null,
finalModelId,
originalModelId: model,
modelWasMapped: isOpenRouterRequest && finalModelId !== model
}
};
}
console.log("Testing model detection scenarios:\n");
// Test 1: HuggingFace model with auto provider
console.log("1. HuggingFace model with auto provider:");
console.log(JSON.stringify(testModelDetection("deepseek-ai/DeepSeek-V3-0324", "auto"), null, 2));
// Test 2: OpenRouter model with explicit provider
console.log("\n2. OpenRouter model with explicit provider:");
console.log(JSON.stringify(testModelDetection("anthropic/claude-3.5-sonnet", "openrouter", "sk-test"), null, 2));
// Test 3: OpenRouter model without explicit provider (auto-detection)
console.log("\n3. OpenRouter model without explicit provider (auto-detection):");
console.log(JSON.stringify(testModelDetection("anthropic/claude-3.5-sonnet", "auto"), null, 2));
// Test 4: The FAILING scenario - OpenRouter model stored as HF format
console.log("\n4. The FAILING scenario - HF model ID with OpenRouter provider:");
console.log(JSON.stringify(testModelDetection("deepseek-ai/DeepSeek-V3-0324", "openrouter", "sk-test"), null, 2));
// Test 5: Edge case - Unknown model with no explicit provider
console.log("\n5. Edge case - Unknown model with auto provider:");
console.log(JSON.stringify(testModelDetection("unknown/model-id", "auto"), null, 2));