File size: 3,015 Bytes
dcd5e1d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// 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));