mirror of
https://github.com/wassname/Open-Assistant.git
synced 2026-07-03 17:10:10 +08:00
Forwarding the real task id in backend interactions and ensure the labeling task works
This commit is contained in:
@@ -33,6 +33,7 @@ describe("Contract test for Oasst API", function () {
|
||||
await oasstApiClient.interactTask(
|
||||
"text_reply_to_message",
|
||||
task.id,
|
||||
"321",
|
||||
"1",
|
||||
{ text: "Test" },
|
||||
{
|
||||
|
||||
@@ -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" });
|
||||
|
||||
@@ -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 };
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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>;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user