forked from LAION-AI/Open-Assistant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEvaluateTask.tsx
82 lines (78 loc) · 3 KB
/
EvaluateTask.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import { Box, Checkbox, useColorModeValue } from "@chakra-ui/react";
import { useTranslation } from "next-i18next";
import { ChangeEvent, useCallback, useEffect, useState } from "react";
import { MessageConversation } from "src/components/Messages/MessageConversation";
import { Sortable } from "src/components/Sortable/Sortable";
import { SurveyCard } from "src/components/Survey/SurveyCard";
import { TaskSurveyProps } from "src/components/Tasks/Task";
import { TaskHeader } from "src/components/Tasks/TaskHeader";
import { Message } from "src/types/Conversation";
import { TaskType } from "src/types/Task";
import { EvaluateTaskReply } from "src/types/TaskResponses";
import { RankTaskType } from "src/types/Tasks";
export const EvaluateTask = ({
task,
taskType,
isEditable,
isDisabled,
onReplyChanged,
onValidityChanged,
}: TaskSurveyProps<RankTaskType, EvaluateTaskReply>) => {
const cardColor = useColorModeValue("gray.50", "gray.800");
const [ranking, setRanking] = useState<number[] | null>(null);
const [notRankable, setNotRankable] = useState(false);
let messages: Message[] = [];
if (task.type !== TaskType.rank_initial_prompts) {
messages = task.conversation.messages;
}
useEffect(() => {
if (ranking === null) {
if (task.type === TaskType.rank_initial_prompts) {
onReplyChanged({ ranking: task.prompts.map((_, idx) => idx), not_rankable: notRankable });
} else {
onReplyChanged({ ranking: task.replies.map((_, idx) => idx), not_rankable: notRankable });
}
onValidityChanged(notRankable ? "VALID" : "DEFAULT");
} else {
onReplyChanged({ ranking, not_rankable: notRankable });
onValidityChanged("VALID");
}
}, [task, ranking, onReplyChanged, onValidityChanged, notRankable]);
const handleNotRankableChange = useCallback((e: ChangeEvent<HTMLInputElement>) => {
setNotRankable(e.target.checked);
}, []);
const { t } = useTranslation("tasks");
// @notmd: I haven't test `rank_initial_prompts` type yet
const sortableItems =
task.type === TaskType.rank_initial_prompts ? (task.prompts as unknown as Message[]) : task.reply_messages;
return (
<div data-cy="task" data-task-type="evaluate-task">
<Box mb="4">
<SurveyCard>
<TaskHeader taskType={taskType} />
<Box mt="4" p="6" borderRadius="lg" bg={cardColor}>
<MessageConversation messages={messages} highlightLastMessage />
</Box>
<Box mt="8">
<Sortable
items={sortableItems}
isDisabled={isDisabled}
isEditable={isEditable}
revealSynthetic={task.reveal_synthetic}
onChange={setRanking}
/>
<Checkbox
size="lg"
mt="4"
checked={notRankable}
isDisabled={isDisabled || !isEditable}
onChange={handleNotRankableChange}
>
{t("not_rankable")}
</Checkbox>
</Box>
</SurveyCard>
</Box>
</div>
);
};