mirror of
https://github.com/wassname/Open-Assistant.git
synced 2026-07-04 17:20:19 +08:00
2a8d38f058
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
36 lines
954 B
TypeScript
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;
|