Files
Open-Assistant/website/src/pages/api/set_label.ts
T
rjmacarthy 2a8d38f058 Refactor fetch and post to use axios
Fix set_label id missing in payload use frontend_message_id

pre-commit

Refactor api fetcher/poster to axios create

lint

Remove string literal for path

Revert oasst_api_client.ts

Fix warning httpStatusCode OasstError optional parameter

Refactor remove api base url for local api

Lint add blank line
2023-01-13 17:05:10 +00:00

36 lines
954 B
TypeScript

import { withoutRole } from "src/lib/auth";
/**
* Sets the Label in the Backend.
*
*/
const handler = withoutRole("banned", async (req, res, token) => {
// Parse out the local message_id, and the interaction contents.
const { message_id, label_map, text } = req.body;
const interactionRes = await fetch(`${process.env.FASTAPI_URL}/api/v1/text_labels`, {
method: "POST",
headers: {
"X-API-Key": process.env.FASTAPI_KEY,
"Content-Type": "application/json",
},
body: JSON.stringify({
type: "text_labels",
message_id: message_id,
labels: label_map,
text: text,
user: {
id: token.sub,
display_name: token.name || token.email,
auth_method: "local",
},
}),
});
if (interactionRes.status !== 204) {
const r = await interactionRes.json();
console.error(JSON.stringify(r));
}
res.status(interactionRes.status).end();
});
export default handler;