Forwarding the real task id in backend interactions and ensure the labeling task works

This commit is contained in:
Keith Stevens
2023-01-11 19:32:52 +09:00
parent 14fa08e2e7
commit 268cd7d7b5
5 changed files with 14 additions and 18 deletions
@@ -33,6 +33,7 @@ describe("Contract test for Oasst API", function () {
await oasstApiClient.interactTask(
"text_reply_to_message",
task.id,
"321",
"1",
{ text: "Test" },
{
+1 -2
View File
@@ -13,9 +13,8 @@ export const LabelTask = ({
taskType,
onReplyChanged,
}: TaskSurveyProps<{ text: string; labels: { [k: string]: number }; message_id: string }>) => {
const [sliderValues, setSliderValues] = useState<number[]>([]);
const valid_labels = task.valid_labels;
const [sliderValues, setSliderValues] = useState<number[]>(new Array(valid_labels.length).fill(0));
useEffect(() => {
onReplyChanged({ content: { labels: {}, text: task.reply, message_id: task.message_id }, state: "DEFAULT" });
+5 -10
View File
@@ -1,10 +1,5 @@
import { JWT } from "next-auth/jwt";
declare global {
// eslint-disable-next-line no-var
var oasstApiClient: OasstApiClient | undefined;
}
export class OasstError {
message: string;
errorCode: number;
@@ -106,6 +101,7 @@ export class OasstApiClient {
// This is a raw Json type, so we can't use it to strongly type the task.
async interactTask(
updateType: string,
taskId: string,
messageId: string,
userMessageId: string,
content: object,
@@ -118,6 +114,7 @@ export class OasstApiClient {
display_name: userToken.name || userToken.email,
auth_method: "local",
},
task_id: taskId,
message_id: messageId,
user_message_id: userMessageId,
...content,
@@ -131,8 +128,6 @@ export class OasstApiClient {
}
}
export const oasstApiClient =
globalThis.oasstApiClient || new OasstApiClient(process.env.FASTAPI_URL, process.env.FASTAPI_KEY);
if (process.env.NODE_ENV !== "production") {
globalThis.oasstApiClient = oasstApiClient;
}
const oasstApiClient = new OasstApiClient(process.env.FASTAPI_URL, process.env.FASTAPI_KEY);
export { oasstApiClient };
+4 -3
View File
@@ -20,8 +20,8 @@ const handler = withoutRole("banned", async (req, res, token) => {
// Accept the task so that we can complete it, this will probably go away soon.
const registeredTask = await prisma.registeredTask.findUniqueOrThrow({ where: { id: frontendId } });
const task = registeredTask.task as Prisma.JsonObject;
const id = task.id as string;
await oasstApiClient.ackTask(id, registeredTask.id);
const taskId = task.id as string;
await oasstApiClient.ackTask(taskId, registeredTask.id);
// Log the interaction locally to create our user_post_id needed by the Task
// Backend.
@@ -38,8 +38,9 @@ const handler = withoutRole("banned", async (req, res, token) => {
let newTask;
try {
newTask = await oasstApiClient.interactTask(update_type, frontendId, interaction.id, content, token);
newTask = await oasstApiClient.interactTask(update_type, taskId, frontendId, interaction.id, content, token);
} catch (err) {
console.error(JSON.stringify(err));
return res.status(500).json(err);
}
+3 -3
View File
@@ -9,16 +9,16 @@ const RandomTask = () => {
const { tasks, isLoading, trigger, reset } = useGenericTaskAPI("random");
useEffect(() => {
if (tasks.length == 0) {
if (tasks.length === 0) {
reset();
}
}, [tasks]);
}, [tasks, reset]);
if (isLoading) {
return <LoadingScreen text="Loading..." />;
}
if (tasks.length == 0) {
if (tasks.length === 0) {
return <Container className="p-6 text-center text-gray-800">No tasks found...</Container>;
}