-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcheck_model_status.js
82 lines (75 loc) · 2.62 KB
/
check_model_status.js
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
const fs = require('fs');
const { ClarifaiStub, grpc } = require('clarifai-nodejs-grpc');
// Read API key directly from .env file
let apiKey;
try {
const envContents = fs.readFileSync('.env', 'utf8');
const matches = envContents.match(/CLARIFAI_API_KEY=([^\s]+)/);
if (matches && matches[1]) {
apiKey = matches[1].trim();
} else {
console.error('ERROR: Could not find CLARIFAI_API_KEY in .env file');
process.exit(1);
}
} catch (error) {
console.error('ERROR: Could not read .env file:', error);
process.exit(1);
}
const stub = ClarifaiStub.grpc();
const metadata = new grpc.Metadata();
metadata.set('authorization', `Key ${apiKey}`);
async function checkModelStatus() {
try {
const modelId = 'catsdogstest';
console.log('Checking model status...');
const response = await new Promise((resolve, reject) => {
stub.GetModel(
{ model_id: modelId },
metadata,
(err, response) => {
if (err) {
console.error('Error getting model:', err);
if (err.details) {
console.error('Error details:', err.details);
}
reject(err);
} else {
console.log('Model status:', JSON.stringify(response, null, 2));
resolve(response);
}
}
);
});
// Also list all models to verify our access
console.log('\nListing all models...');
const listResponse = await new Promise((resolve, reject) => {
stub.ListModels(
{
page: 1,
per_page: 5
},
metadata,
(err, response) => {
if (err) {
console.error('Error listing models:', err);
if (err.details) {
console.error('Error details:', err.details);
}
reject(err);
} else {
console.log('Models list:', JSON.stringify(response, null, 2));
resolve(response);
}
}
);
});
console.log('\nAPI access verification completed');
} catch (error) {
console.error('Status check failed:', error);
if (error.details) {
console.error('Error details:', error.details);
}
process.exit(1);
}
}
checkModelStatus();