Merge branch 'release' into staging
This commit is contained in:
commit
02f9aded4b
14
server.js
14
server.js
|
@ -3808,7 +3808,7 @@ async function sendAI21Request(request, response) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
app.post("/tokenize_ai21", jsonParser, function (request, response_tokenize_ai21) {
|
app.post("/tokenize_ai21", jsonParser, async function (request, response_tokenize_ai21) {
|
||||||
if (!request.body) return response_tokenize_ai21.sendStatus(400);
|
if (!request.body) return response_tokenize_ai21.sendStatus(400);
|
||||||
const options = {
|
const options = {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
@ -3820,10 +3820,14 @@ app.post("/tokenize_ai21", jsonParser, function (request, response_tokenize_ai21
|
||||||
body: JSON.stringify({ text: request.body[0].content })
|
body: JSON.stringify({ text: request.body[0].content })
|
||||||
};
|
};
|
||||||
|
|
||||||
fetch('https://api.ai21.com/studio/v1/tokenize', options)
|
try {
|
||||||
.then(response => response.json())
|
const response = await fetch('https://api.ai21.com/studio/v1/tokenize', options);
|
||||||
.then(response => response_tokenize_ai21.send({ "token_count": response.tokens.length }))
|
const data = await response.json();
|
||||||
.catch(err => console.error(err));
|
return response_tokenize_ai21.send({ "token_count": data?.tokens?.length || 0 });
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
return response_tokenize_ai21.send({ "token_count": 0 });
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
app.post("/save_preset", jsonParser, function (request, response) {
|
app.post("/save_preset", jsonParser, function (request, response) {
|
||||||
|
|
Loading…
Reference in New Issue