-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtest_model_creation.js
58 lines (50 loc) · 1.73 KB
/
test_model_creation.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
const { ClarifaiStub, grpc } = require('clarifai-nodejs-grpc');
const stub = ClarifaiStub.grpc();
const metadata = new grpc.Metadata();
// Check if API key is available
if (!process.env.CLARIFAI_API_KEY) {
console.error('Error: CLARIFAI_API_KEY environment variable is not set');
process.exit(1);
}
// Set up authorization with API key
metadata.set('authorization', `Key ${process.env.CLARIFAI_API_KEY}`);
console.log('Using API key:', process.env.CLARIFAI_API_KEY.substring(0, 8) + '...');
async function testModelCreation() {
try {
const modelRequest = {
model: {
id: 'test-model',
name: 'Test Model',
model_type_id: 'embedding-classifier',
concepts: [
{ id: 'cat', name: 'cat' },
{ id: 'dog', name: 'dog' }
]
}
};
console.log('Sending model creation request:', JSON.stringify(modelRequest, null, 2));
const response = await new Promise((resolve, reject) => {
stub.PostModels(
{
user_app_id: {
user_id: 'clarifai',
app_id: 'main'
},
models: [modelRequest]
},
metadata,
(err, response) => {
if (err) {
reject(err);
} else {
resolve(response);
}
}
);
});
console.log('Model creation response:', JSON.stringify(response, null, 2));
} catch (error) {
console.error('Error creating model:', error);
}
}
testModelCreation();