-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify-hf-models.js
More file actions
executable file
·106 lines (92 loc) · 3.34 KB
/
verify-hf-models.js
File metadata and controls
executable file
·106 lines (92 loc) · 3.34 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env node
/**
* Verify which Hugging Face models are accessible with your API key
* Usage: node verify-hf-models.js [model-id]
*/
const HUGGINGFACE_API_KEY = process.env.HUGGINGFACE_API_KEY;
if (!HUGGINGFACE_API_KEY) {
console.error('❌ Error: HUGGINGFACE_API_KEY environment variable not set');
console.error('Set it with: export HUGGINGFACE_API_KEY="hf_your_token_here"');
process.exit(1);
}
// Popular models to test (or use command line arg)
const DEFAULT_MODELS = [
'meta-llama/Llama-3.3-70B-Instruct',
'Qwen/Qwen2.5-72B-Instruct',
'mistralai/Mixtral-8x22B-Instruct-v0.1',
'mistralai/Mistral-7B-Instruct-v0.2',
'TroyDoesAI/BlackSheep-24B',
];
async function testModel(modelId) {
const url = `https://api-inference.huggingface.co/models/${modelId}`;
try {
const response = await fetch(url, {
method: 'POST',
headers: {
'Authorization': `Bearer ${HUGGINGFACE_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
inputs: 'Hello, which model are you?',
parameters: {
max_new_tokens: 50,
return_full_text: false,
}
})
});
const result = {
model: modelId,
status: response.status,
accessible: false,
message: '',
};
if (response.status === 200) {
const data = await response.json();
result.accessible = true;
result.message = '✅ Model is accessible and working!';
result.response = data[0]?.generated_text?.substring(0, 100);
} else if (response.status === 503) {
result.message = '⏳ Model is loading (cold start). Retry in 30 seconds.';
} else if (response.status === 401) {
result.message = '❌ Authentication failed. Check your API key.';
} else if (response.status === 403) {
result.message = '❌ Access forbidden. May need to request access for gated model.';
} else if (response.status === 404) {
result.message = '❌ Model not found or not accessible.';
} else {
const text = await response.text();
result.message = `❌ Error ${response.status}: ${text.substring(0, 100)}`;
}
return result;
} catch (error) {
return {
model: modelId,
status: 'error',
accessible: false,
message: `❌ Network error: ${error.message}`,
};
}
}
async function main() {
const modelsToTest = process.argv.slice(2);
const models = modelsToTest.length > 0 ? modelsToTest : DEFAULT_MODELS;
console.log('🔍 Testing Hugging Face Inference API access...\n');
console.log(`Using API key: ${HUGGINGFACE_API_KEY.substring(0, 10)}...${HUGGINGFACE_API_KEY.slice(-4)}\n`);
for (const model of models) {
console.log(`Testing: ${model}`);
const result = await testModel(model);
console.log(` Status: ${result.status}`);
console.log(` ${result.message}`);
if (result.response) {
console.log(` Response preview: "${result.response}..."`);
}
console.log('');
}
console.log('\n💡 Tips:');
console.log(' - 503 errors are normal for first request (cold start)');
console.log(' - For gated models (Llama), request access on HuggingFace.co');
console.log(' - Use format: huggingface/org/model in OpenCode');
console.log('\nTo test a specific model:');
console.log(' node verify-hf-models.js meta-llama/Llama-3.3-70B-Instruct');
}
main().catch(console.error);