This repository was archived by the owner on Oct 19, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmodelVerification.js
More file actions
73 lines (63 loc) · 2.1 KB
/
modelVerification.js
File metadata and controls
73 lines (63 loc) · 2.1 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
// Define the list of acceptable models
const acceptableModels = [
{
id: "sakura-14b-qwen2.5-v1.0-iq4xs",
meta: {
vocab_type: 2,
n_vocab: 152064,
n_ctx_train: 131072,
n_embd: 5120,
n_params: 14770033664,
size: 8180228096
}
},
// Add more acceptable models here as needed
];
export async function verifyModel(nodeUrl) {
try {
const response = await fetch(`${nodeUrl}/v1/models`);
if (!response.ok) {
return false;
}
let data;
try {
data = await response.json();
} catch (parseError) {
console.error('Failed to parse JSON response:', parseError.message);
return false;
}
// Verify the response structure
if (data.object !== 'list' || !Array.isArray(data.data) || data.data.length === 0) {
return false;
}
// Get the single model object
const model = data.data[0];
let isModelAcceptable = false;
for (const acceptableModel of acceptableModels) {
if ((model.id === acceptableModel.id || model.id === acceptableModel.id + '.gguf') && model.meta) {
let allMetaMatch = true;
for (const [key, value] of Object.entries(acceptableModel.meta)) {
if (key in model.meta) {
if (model.meta[key] !== value) {
allMetaMatch = false;
break;
}
} else {
// Key not found in model.meta, consider it a mismatch
allMetaMatch = false;
break;
}
}
if (allMetaMatch) {
isModelAcceptable = true;
break;
}
}
}
return isModelAcceptable;
} catch (error) {
// Any unexpected error
console.error('Model verification failed:', error.message);
return false;
}
}