mirror of
https://github.com/wassname/Open-Assistant.git
synced 2026-07-14 01:00:05 +08:00
fix: new web route to update text_labels
fix: minimum changes to textFlagLabels to keep it coherent with the backend
This commit is contained in:
@@ -29,7 +29,7 @@ import { colors } from "styles/Theme/colors";
|
||||
|
||||
export const FlaggableElement = (props) => {
|
||||
const [isEditing, setIsEditing] = useBoolean();
|
||||
const { trigger } = useSWRMutation("/api/v1/text_labels", poster, {
|
||||
const { trigger } = useSWRMutation("/api/set_label", poster, {
|
||||
onSuccess: () => {
|
||||
setIsEditing.off;
|
||||
},
|
||||
@@ -183,40 +183,40 @@ interface textFlagLabels {
|
||||
const TEXT_LABEL_FLAGS: textFlagLabels[] = [
|
||||
// For the time being this list is configured on the FE.
|
||||
// In the future it may be provided by the API.
|
||||
// {
|
||||
// attributeName: "fails_task",
|
||||
// labelText: "Fails to follow the correct instruction / task",
|
||||
// additionalExplanation: "__TODO__",
|
||||
// },
|
||||
// {
|
||||
// attributeName: "not_customer_assistant_appropriate",
|
||||
// labelText: "Inappropriate for customer assistant",
|
||||
// additionalExplanation: "__TODO__",
|
||||
// },
|
||||
{
|
||||
attributeName: "fails_task",
|
||||
labelText: "Fails to follow the correct instruction / task",
|
||||
additionalExplanation: "__TODO__",
|
||||
},
|
||||
{
|
||||
attributeName: "not_customer_assistant_appropriate",
|
||||
labelText: "Inappropriate for customer assistant",
|
||||
additionalExplanation: "__TODO__",
|
||||
},
|
||||
{
|
||||
attributeName: "contains_sexual_content",
|
||||
attributeName: "sexual_content",
|
||||
labelText: "Contains sexual content",
|
||||
},
|
||||
{
|
||||
attributeName: "contains_violent_content",
|
||||
attributeName: "violence",
|
||||
labelText: "Contains violent content",
|
||||
},
|
||||
{
|
||||
attributeName: "encourages_violence",
|
||||
labelText: "Encourages or fails to discourage violence/abuse/terrorism/self-harm",
|
||||
},
|
||||
{
|
||||
attributeName: "denigrates_a_protected_class",
|
||||
labelText: "Denigrates a protected class",
|
||||
},
|
||||
{
|
||||
attributeName: "gives_harmful_advice",
|
||||
labelText: "Fails to follow the correct instruction / task",
|
||||
additionalExplanation:
|
||||
"The advice given in the output is harmful or counter-productive. This may be in addition to, but is distinct from the question about encouraging violence/abuse/terrorism/self-harm.",
|
||||
},
|
||||
{
|
||||
attributeName: "expresses_moral_judgement",
|
||||
labelText: "Expresses moral judgement",
|
||||
},
|
||||
// {
|
||||
// attributeName: "encourages_violence",
|
||||
// labelText: "Encourages or fails to discourage violence/abuse/terrorism/self-harm",
|
||||
// },
|
||||
// {
|
||||
// attributeName: "denigrates_a_protected_class",
|
||||
// labelText: "Denigrates a protected class",
|
||||
// },
|
||||
// {
|
||||
// attributeName: "gives_harmful_advice",
|
||||
// labelText: "Fails to follow the correct instruction / task",
|
||||
// additionalExplanation:
|
||||
// "The advice given in the output is harmful or counter-productive. This may be in addition to, but is distinct from the question about encouraging violence/abuse/terrorism/self-harm.",
|
||||
// },
|
||||
// {
|
||||
// attributeName: "expresses_moral_judgement",
|
||||
// labelText: "Expresses moral judgement",
|
||||
// },
|
||||
];
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
import { getToken } from "next-auth/jwt";
|
||||
import prisma from "src/lib/prismadb";
|
||||
|
||||
/**
|
||||
* Sets the Label in the Backend.
|
||||
*
|
||||
*/
|
||||
const handler = async (req, res) => {
|
||||
const token = await getToken({ req });
|
||||
|
||||
// Return nothing if the user isn't registered.
|
||||
if (!token) {
|
||||
res.status(401).end();
|
||||
return;
|
||||
}
|
||||
console.log(JSON.parse(req.body));
|
||||
// Parse out the local task ID and the interaction contents.
|
||||
const { post_id, label_map, text } = await JSON.parse(req.body);
|
||||
console.log(JSON.stringify(
|
||||
{
|
||||
"type": "text_labels",
|
||||
"message_id": post_id,
|
||||
"labels": label_map,
|
||||
"text": text,
|
||||
"user": {
|
||||
"id": token.sub,
|
||||
"display_name": token.name || token.email,
|
||||
"auth_method": "local",
|
||||
}}));
|
||||
console.log("Here sending text_labels1...");
|
||||
// Send the interaction to the Text Label to the Backend.
|
||||
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": post_id,
|
||||
"labels": label_map,
|
||||
"text": text,
|
||||
"user": {
|
||||
"id": token.sub,
|
||||
"display_name": token.name || token.email,
|
||||
"auth_method": "local",
|
||||
}
|
||||
|
||||
}),
|
||||
});
|
||||
console.log(interactionRes);
|
||||
res.status(interactionRes.status).json(interactionRes.json());
|
||||
};
|
||||
|
||||
export default handler;
|
||||
Reference in New Issue
Block a user