-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtest_clarifai_app.js
105 lines (94 loc) · 3.62 KB
/
test_clarifai_app.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
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 createAndTestApp() {
try {
// First, create a new application
console.log('Creating new Clarifai application...');
const createAppResponse = await new Promise((resolve, reject) => {
stub.PostApps(
{
apps: [{
id: 'cognimates-vision-' + Date.now(),
name: 'Cognimates Vision Training',
description: 'Application for vision model training in Cognimates'
}]
},
metadata,
(err, response) => {
if (err) {
reject(err);
} else {
resolve(response);
}
}
);
});
console.log('Create app response:', JSON.stringify(createAppResponse, null, 2));
if (createAppResponse.status.code === 10000) {
const appId = createAppResponse.apps[0].id;
console.log('Application created successfully with ID:', appId);
// Now test model creation in the new app
const modelRequest = {
user_app_id: {
app_id: appId
},
model: {
id: 'test-model-' + Date.now(),
name: 'Test Model',
model_type_id: 'embedding-classifier',
concepts: [
{ id: 'cat', name: 'cat' },
{ id: 'dog', name: 'dog' }
],
output_info: {
data: {
concepts: [
{ id: 'cat', name: 'cat' },
{ id: 'dog', name: 'dog' }
]
},
output_config: {
concepts_mutually_exclusive: false,
closed_environment: false,
max_concepts: 2
}
}
}
};
console.log('Testing model creation in new app...');
console.log('Model request:', JSON.stringify(modelRequest, null, 2));
const createResponse = await new Promise((resolve, reject) => {
stub.PostModels(
{
user_app_id: modelRequest.user_app_id,
models: [modelRequest.model]
},
metadata,
(err, response) => {
if (err) {
reject(err);
} else {
resolve(response);
}
}
);
});
console.log('Model creation response:', JSON.stringify(createResponse, null, 2));
}
} catch (error) {
console.error('Error:', error);
if (error.details) {
console.error('Error details:', error.details);
}
}
}
createAndTestApp();