forked from danny-avila/LibreChat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-preset.js
More file actions
56 lines (46 loc) · 1.25 KB
/
create-preset.js
File metadata and controls
56 lines (46 loc) · 1.25 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
const fs = require('fs');
const preset = JSON.parse(fs.readFileSync('preset.json', 'utf8'));
const getJWT = async () => {
try {
const response = await fetch('http://localhost:3090/api/auth/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
email: 'cosmo@example.com',
password: 'W3LoveCosmo'
})
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
return data.token;
} catch (error) {
console.error('Error getting JWT:', error);
throw error;
}
};
const createPreset = async () => {
const jwt = await getJWT();
try {
const response = await fetch('http://localhost:3090/api/presets', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${jwt}`
},
body: JSON.stringify(preset)
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
console.log(data?.presetId ?? "");
} catch (error) {
console.error('Error creating preset:', error);
throw error;
}
};
createPreset();