mirror of
https://github.com/wassname/Open-Assistant.git
synced 2026-07-08 00:10:24 +08:00
60 lines
1.3 KiB
JavaScript
60 lines
1.3 KiB
JavaScript
import { unstable_getServerSession } from "next-auth/next";
|
|
import { authOptions } from "./auth/[...nextauth]";
|
|
|
|
/**
|
|
* Returns a list of prompts from the Labeler Backend.
|
|
*/
|
|
export default async (req, res) => {
|
|
const session = await unstable_getServerSession(req, res, authOptions);
|
|
|
|
if (!session) {
|
|
res.status(401).end();
|
|
return;
|
|
}
|
|
|
|
const taskRes = await fetch(`${process.env.FASTAPI_URL}/api/v1/tasks/`, {
|
|
method: "POST",
|
|
headers: {
|
|
"X-API-Key": process.env.FASTAPI_KEY,
|
|
"Content-Type": "application/json",
|
|
},
|
|
body: JSON.stringify({
|
|
type: "rate_summary",
|
|
user: {
|
|
id: session.user.id,
|
|
display_name: session.user.name,
|
|
auth_method: "local",
|
|
},
|
|
}),
|
|
});
|
|
const task = await taskRes.json();
|
|
|
|
const registeredTask = await prisma.registeredTask.create({
|
|
data: {
|
|
task,
|
|
user: {
|
|
connect: {
|
|
id: session.user.id,
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
const ackRes = await fetch(
|
|
`${process.env.FASTAPI_URL}/api/v1/tasks/${task.id}/ack`,
|
|
{
|
|
method: "POST",
|
|
headers: {
|
|
"X-API-Key": process.env.FASTAPI_KEY,
|
|
"Content-Type": "application/json",
|
|
},
|
|
body: JSON.stringify({
|
|
post_id: registeredTask.id,
|
|
}),
|
|
}
|
|
);
|
|
const ack = await ackRes.json();
|
|
|
|
res.status(200).json(registeredTask);
|
|
};
|