From 54a042d002b3ac34384a8e3d2d1e8e73c171af16 Mon Sep 17 00:00:00 2001 From: AbdBarho Date: Mon, 9 Jan 2023 20:08:26 +0100 Subject: [PATCH] Centralize task types --- website/src/components/Buttons/Skip.tsx | 5 -- website/src/components/Messages.tsx | 7 +-- website/src/components/Tasks/CreateTask.tsx | 4 +- website/src/components/Tasks/TaskTypes.tsx | 4 +- .../tasks/create/useCreateInitialPrompt.ts | 9 --- .../src/hooks/tasks/create/useCreateReply.ts | 24 -------- .../tasks/evaluate/useRankInitialPrompts.ts | 9 --- .../hooks/tasks/evaluate/useRankReplies.ts | 25 -------- .../tasks/labeling/useLabelAssistantReply.ts | 22 ------- .../tasks/labeling/useLabelInitialPrompt.tsx | 15 ----- .../tasks/labeling/useLabelPrompterReply.ts | 22 ------- .../hooks/tasks/labeling/useLabelingTask.ts | 20 ------- website/src/hooks/tasks/useCreateReply.ts | 8 +++ website/src/hooks/tasks/useGenericTaskAPI.tsx | 11 +--- website/src/hooks/tasks/useLabelingTask.ts | 32 +++++++++++ website/src/hooks/tasks/useRankReplies.ts | 12 ++++ website/src/pages/create/assistant_reply.tsx | 2 +- website/src/pages/create/initial_prompt.tsx | 2 +- website/src/pages/create/user_reply.tsx | 2 +- .../pages/evaluate/rank_assistant_replies.tsx | 2 +- .../pages/evaluate/rank_initial_prompts.tsx | 2 +- .../src/pages/evaluate/rank_user_replies.tsx | 2 +- .../src/pages/label/label_assistant_reply.tsx | 7 +-- .../src/pages/label/label_initial_prompt.tsx | 5 +- .../src/pages/label/label_prompter_reply.tsx | 7 +-- website/src/pages/messages/index.tsx | 4 +- website/src/types/Conversation.ts | 9 +++ website/src/types/Task.ts | 24 ++++++++ website/src/types/Tasks.ts | 57 +++++++++++++++++++ 29 files changed, 162 insertions(+), 192 deletions(-) delete mode 100644 website/src/hooks/tasks/create/useCreateInitialPrompt.ts delete mode 100644 website/src/hooks/tasks/create/useCreateReply.ts delete mode 100644 website/src/hooks/tasks/evaluate/useRankInitialPrompts.ts delete mode 100644 website/src/hooks/tasks/evaluate/useRankReplies.ts delete mode 100644 website/src/hooks/tasks/labeling/useLabelAssistantReply.ts delete mode 100644 website/src/hooks/tasks/labeling/useLabelInitialPrompt.tsx delete mode 100644 website/src/hooks/tasks/labeling/useLabelPrompterReply.ts delete mode 100644 website/src/hooks/tasks/labeling/useLabelingTask.ts create mode 100644 website/src/hooks/tasks/useCreateReply.ts create mode 100644 website/src/hooks/tasks/useLabelingTask.ts create mode 100644 website/src/hooks/tasks/useRankReplies.ts create mode 100644 website/src/types/Conversation.ts create mode 100644 website/src/types/Task.ts create mode 100644 website/src/types/Tasks.ts diff --git a/website/src/components/Buttons/Skip.tsx b/website/src/components/Buttons/Skip.tsx index 8440e348f8..bcd0eb79ab 100644 --- a/website/src/components/Buttons/Skip.tsx +++ b/website/src/components/Buttons/Skip.tsx @@ -1,10 +1,6 @@ import { Button, ButtonProps, - Menu, - MenuButton, - MenuItem, - MenuList, Modal, ModalBody, ModalCloseButton, @@ -16,7 +12,6 @@ import { useDisclosure, } from "@chakra-ui/react"; import { useState } from "react"; -import { FaChevronDown } from "react-icons/fa"; interface SkipButtonProps extends ButtonProps { onSkip: (reason: string) => void; diff --git a/website/src/components/Messages.tsx b/website/src/components/Messages.tsx index 71ff237b75..20d26808af 100644 --- a/website/src/components/Messages.tsx +++ b/website/src/components/Messages.tsx @@ -1,15 +1,10 @@ import { Grid } from "@chakra-ui/react"; import { useColorMode } from "@chakra-ui/react"; import { useMemo } from "react"; +import { Message } from "src/types/Conversation"; import { FlaggableElement } from "./FlaggableElement"; -export interface Message { - text: string; - is_assistant: boolean; - message_id: string; -} - export interface ValidLabel { name: string; display_text: string; diff --git a/website/src/components/Tasks/CreateTask.tsx b/website/src/components/Tasks/CreateTask.tsx index 7af262e13d..2c11cb01ff 100644 --- a/website/src/components/Tasks/CreateTask.tsx +++ b/website/src/components/Tasks/CreateTask.tsx @@ -4,13 +4,13 @@ import { Messages } from "src/components/Messages"; import { TaskControls } from "src/components/Survey/TaskControls"; import { TrackedTextarea } from "src/components/Survey/TrackedTextarea"; import { TwoColumnsWithCards } from "src/components/Survey/TwoColumnsWithCards"; -import { TaskType } from "./TaskTypes"; +import { TaskInfo } from "./TaskTypes"; export interface CreateTaskProps { // we need a task type // eslint-disable-next-line @typescript-eslint/no-explicit-any tasks: any[]; - taskType: TaskType; + taskType: TaskInfo; trigger: (update: { id: string; update_type: string; content: { text: string } }) => void; onSkipTask: (task: { id: string }, reason: string) => void; onNextTask: () => void; diff --git a/website/src/components/Tasks/TaskTypes.tsx b/website/src/components/Tasks/TaskTypes.tsx index 409e7038e5..d255756a35 100644 --- a/website/src/components/Tasks/TaskTypes.tsx +++ b/website/src/components/Tasks/TaskTypes.tsx @@ -4,7 +4,7 @@ export enum TaskCategory { Label = "Label", } -export interface TaskType { +export interface TaskInfo { label: string; desc: string; category: TaskCategory; @@ -14,7 +14,7 @@ export interface TaskType { instruction?: string; } -export const TaskTypes: TaskType[] = [ +export const TaskTypes: TaskInfo[] = [ // create { label: "Create Initial Prompts", diff --git a/website/src/hooks/tasks/create/useCreateInitialPrompt.ts b/website/src/hooks/tasks/create/useCreateInitialPrompt.ts deleted file mode 100644 index cf0193e848..0000000000 --- a/website/src/hooks/tasks/create/useCreateInitialPrompt.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { useGenericTaskAPI } from "../useGenericTaskAPI"; - -interface CreateInitialPromptTask { - id: string; - type: "initial_prompt"; - hint: string; -} - -export const useCreateInitialPrompt = () => useGenericTaskAPI("initial_prompt"); diff --git a/website/src/hooks/tasks/create/useCreateReply.ts b/website/src/hooks/tasks/create/useCreateReply.ts deleted file mode 100644 index 0bc78319f5..0000000000 --- a/website/src/hooks/tasks/create/useCreateReply.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { useGenericTaskAPI } from "../useGenericTaskAPI"; - -interface BaseCreateReplyTask { - id: string; - conversation: { - messages: Array<{ - text: string; - is_assistant: boolean; - message_id: string; - }>; - }; -} - -export interface CreateAssistantReplyTask extends BaseCreateReplyTask { - type: "assistant_reply"; -} - -export interface CreatePrompterReplyTask extends BaseCreateReplyTask { - type: "prompter_reply"; -} - -export const useCreateAssistantReply = () => useGenericTaskAPI("assistant_reply"); - -export const useCreatePrompterReply = () => useGenericTaskAPI("prompter_reply"); diff --git a/website/src/hooks/tasks/evaluate/useRankInitialPrompts.ts b/website/src/hooks/tasks/evaluate/useRankInitialPrompts.ts deleted file mode 100644 index da772c8030..0000000000 --- a/website/src/hooks/tasks/evaluate/useRankInitialPrompts.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { useGenericTaskAPI } from "../useGenericTaskAPI"; - -interface RankInitialPromptsTask { - id: string; - type: "rank_initial_prompts"; - prompts: string[]; -} - -export const useRankInitialPromptsTask = () => useGenericTaskAPI("rank_initial_prompts"); diff --git a/website/src/hooks/tasks/evaluate/useRankReplies.ts b/website/src/hooks/tasks/evaluate/useRankReplies.ts deleted file mode 100644 index 2d8d513f54..0000000000 --- a/website/src/hooks/tasks/evaluate/useRankReplies.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { useGenericTaskAPI } from "../useGenericTaskAPI"; - -interface BaseRankRepliesTask { - id: string; - replies: string[]; - conversation: { - messages: Array<{ - text: string; - is_assistant: boolean; - message_id: string; - }>; - }; -} - -interface RankAssistantRepliesTask extends BaseRankRepliesTask { - type: "rank_assistant_replies"; -} - -interface RankPrompterRepliesTask extends BaseRankRepliesTask { - type: "rank_prompter_replies"; -} - -export const useRankAssistantRepliesTask = () => useGenericTaskAPI("rank_assistant_replies"); - -export const useRankPrompterRepliesTask = () => useGenericTaskAPI("rank_prompter_replies"); diff --git a/website/src/hooks/tasks/labeling/useLabelAssistantReply.ts b/website/src/hooks/tasks/labeling/useLabelAssistantReply.ts deleted file mode 100644 index 3c44046e6f..0000000000 --- a/website/src/hooks/tasks/labeling/useLabelAssistantReply.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { TaskResponse } from "../useGenericTaskAPI"; -import { LabelingTaskType, useLabelingTask } from "./useLabelingTask"; - -export interface LabelAssistantReplyTask { - id: string; - type: LabelingTaskType.label_assistant_reply; - message_id: string; - valid_labels: string[]; - reply: string; - conversation: { - messages: Array<{ - text: string; - is_assistant: boolean; - message_id: string; - }>; - }; -} - -export type LabelAssistantReplyTaskResponse = TaskResponse; - -export const useLabelAssistantReplyTask = () => - useLabelingTask(LabelingTaskType.label_assistant_reply); diff --git a/website/src/hooks/tasks/labeling/useLabelInitialPrompt.tsx b/website/src/hooks/tasks/labeling/useLabelInitialPrompt.tsx deleted file mode 100644 index f7ba8ab5b9..0000000000 --- a/website/src/hooks/tasks/labeling/useLabelInitialPrompt.tsx +++ /dev/null @@ -1,15 +0,0 @@ -import { TaskResponse } from "../useGenericTaskAPI"; -import { LabelingTaskType, useLabelingTask } from "./useLabelingTask"; - -export interface LabelInitialPromptTask { - id: string; - type: LabelingTaskType.label_initial_prompt; - message_id: string; - valid_labels: string[]; - prompt: string; -} - -export type LabelInitialPromptTaskResponse = TaskResponse; - -export const useLabelInitialPromptTask = () => - useLabelingTask(LabelingTaskType.label_initial_prompt); diff --git a/website/src/hooks/tasks/labeling/useLabelPrompterReply.ts b/website/src/hooks/tasks/labeling/useLabelPrompterReply.ts deleted file mode 100644 index 9de2057f4b..0000000000 --- a/website/src/hooks/tasks/labeling/useLabelPrompterReply.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { TaskResponse } from "../useGenericTaskAPI"; -import { LabelingTaskType, useLabelingTask } from "./useLabelingTask"; - -export interface LabelPrompterReplyTask { - id: string; - type: LabelingTaskType.label_prompter_reply; - message_id: string; - valid_labels: string[]; - reply: string; - conversation: { - messages: Array<{ - text: string; - is_assistant: boolean; - message_id: string; - }>; - }; -} - -export type LabelPrompterReplyTaskResponse = TaskResponse; - -export const useLabelPrompterReplyTask = () => - useLabelingTask(LabelingTaskType.label_prompter_reply); diff --git a/website/src/hooks/tasks/labeling/useLabelingTask.ts b/website/src/hooks/tasks/labeling/useLabelingTask.ts deleted file mode 100644 index 2755528493..0000000000 --- a/website/src/hooks/tasks/labeling/useLabelingTask.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { useGenericTaskAPI } from "../useGenericTaskAPI"; - -export const enum LabelingTaskType { - label_initial_prompt = "label_initial_prompt", - label_prompter_reply = "label_prompter_reply", - label_assistant_reply = "label_assistant_reply", -} - -export const useLabelingTask = (endpoint: LabelingTaskType) => { - const { tasks, isLoading, trigger, reset, error } = useGenericTaskAPI(endpoint); - - const submit = (id: string, message_id: string, text: string, validLabels: string[], labelWeights: number[]) => { - console.assert(validLabels.length === labelWeights.length); - const labels = Object.fromEntries(validLabels.map((label, i) => [label, labelWeights[i]])); - - return trigger({ id, update_type: "text_labels", content: { labels, text, message_id } }); - }; - - return { tasks, isLoading, submit, reset, error }; -}; diff --git a/website/src/hooks/tasks/useCreateReply.ts b/website/src/hooks/tasks/useCreateReply.ts new file mode 100644 index 0000000000..23bc041d39 --- /dev/null +++ b/website/src/hooks/tasks/useCreateReply.ts @@ -0,0 +1,8 @@ +import { TaskType } from "src/types/Task"; +import { CreateAssistantReplyTask, CreateInitialPromptTask, CreatePrompterReplyTask } from "src/types/Tasks"; + +import { useGenericTaskAPI } from "./useGenericTaskAPI"; + +export const useCreateAssistantReply = () => useGenericTaskAPI(TaskType.assistant_reply); +export const useCreatePrompterReply = () => useGenericTaskAPI(TaskType.prompter_reply); +export const useCreateInitialPrompt = () => useGenericTaskAPI(TaskType.initial_prompt); diff --git a/website/src/hooks/tasks/useGenericTaskAPI.tsx b/website/src/hooks/tasks/useGenericTaskAPI.tsx index a57c9da43b..a456cbf16b 100644 --- a/website/src/hooks/tasks/useGenericTaskAPI.tsx +++ b/website/src/hooks/tasks/useGenericTaskAPI.tsx @@ -1,18 +1,11 @@ import { useState } from "react"; import fetcher from "src/lib/fetcher"; import poster from "src/lib/poster"; +import { BaseTask, TaskResponse } from "src/types/Task"; import useSWRImmutable from "swr/immutable"; import useSWRMutation from "swr/mutation"; -// TODO: type & centralize types for all tasks - -export interface TaskResponse { - id: string; - userId: string; - task: TaskType; -} - -export const useGenericTaskAPI = (taskApiEndpoint: string) => { +export const useGenericTaskAPI = (taskApiEndpoint: string) => { type ConcreteTaskResponse = TaskResponse; const [tasks, setTasks] = useState([]); diff --git a/website/src/hooks/tasks/useLabelingTask.ts b/website/src/hooks/tasks/useLabelingTask.ts new file mode 100644 index 0000000000..5e5050ab51 --- /dev/null +++ b/website/src/hooks/tasks/useLabelingTask.ts @@ -0,0 +1,32 @@ +import { BaseTask, TaskResponse, TaskType } from "src/types/Task"; +import { LabelAssistantReplyTask, LabelInitialPromptTask, LabelPrompterReplyTask } from "src/types/Tasks"; + +import { useGenericTaskAPI } from "./useGenericTaskAPI"; + +const useLabelingTask = ( + endpoint: TaskType.label_assistant_reply | TaskType.label_prompter_reply | TaskType.label_initial_prompt +) => { + const { tasks, isLoading, trigger, reset, error } = useGenericTaskAPI(endpoint); + + const submit = (id: string, message_id: string, text: string, validLabels: string[], labelWeights: number[]) => { + console.assert(validLabels.length === labelWeights.length); + const labels = Object.fromEntries(validLabels.map((label, i) => [label, labelWeights[i]])); + + return trigger({ id, update_type: "text_labels", content: { labels, text, message_id } }); + }; + + return { tasks, isLoading, submit, reset, error }; +}; + +export type LabelAssistantReplyTaskResponse = TaskResponse; + +export const useLabelAssistantReplyTask = () => + useLabelingTask(TaskType.label_assistant_reply); + +export type LabelInitialPromptTaskResponse = TaskResponse; + +export const useLabelInitialPromptTask = () => useLabelingTask(TaskType.label_initial_prompt); + +export type LabelPrompterReplyTaskResponse = TaskResponse; + +export const useLabelPrompterReplyTask = () => useLabelingTask(TaskType.label_prompter_reply); diff --git a/website/src/hooks/tasks/useRankReplies.ts b/website/src/hooks/tasks/useRankReplies.ts new file mode 100644 index 0000000000..d4accda00b --- /dev/null +++ b/website/src/hooks/tasks/useRankReplies.ts @@ -0,0 +1,12 @@ +import { TaskType } from "src/types/Task"; +import { RankAssistantRepliesTask, RankInitialPromptsTask, RankPrompterRepliesTask } from "src/types/Tasks"; + +import { useGenericTaskAPI } from "./useGenericTaskAPI"; + +export const useRankAssistantRepliesTask = () => + useGenericTaskAPI(TaskType.rank_assistant_replies); + +export const useRankPrompterRepliesTask = () => + useGenericTaskAPI(TaskType.rank_prompter_replies); + +export const useRankInitialPromptsTask = () => useGenericTaskAPI(TaskType.rank_initial_prompts); diff --git a/website/src/pages/create/assistant_reply.tsx b/website/src/pages/create/assistant_reply.tsx index e9aee226bd..17facd5dbe 100644 --- a/website/src/pages/create/assistant_reply.tsx +++ b/website/src/pages/create/assistant_reply.tsx @@ -3,7 +3,7 @@ import { useColorMode } from "@chakra-ui/react"; import Head from "next/head"; import { LoadingScreen } from "src/components/Loading/LoadingScreen"; import { Task } from "src/components/Tasks/Task"; -import { useCreateAssistantReply } from "src/hooks/tasks/create/useCreateReply"; +import { useCreateAssistantReply } from "src/hooks/tasks/useCreateReply"; const AssistantReply = () => { const { tasks, isLoading, reset, trigger } = useCreateAssistantReply(); diff --git a/website/src/pages/create/initial_prompt.tsx b/website/src/pages/create/initial_prompt.tsx index efea647405..57f0dabd09 100644 --- a/website/src/pages/create/initial_prompt.tsx +++ b/website/src/pages/create/initial_prompt.tsx @@ -3,7 +3,7 @@ import { useColorMode } from "@chakra-ui/react"; import Head from "next/head"; import { LoadingScreen } from "src/components/Loading/LoadingScreen"; import { Task } from "src/components/Tasks/Task"; -import { useCreateInitialPrompt } from "src/hooks/tasks/create/useCreateInitialPrompt"; +import { useCreateInitialPrompt } from "src/hooks/tasks/useCreateReply"; const InitialPrompt = () => { const { tasks, isLoading, reset, trigger } = useCreateInitialPrompt(); diff --git a/website/src/pages/create/user_reply.tsx b/website/src/pages/create/user_reply.tsx index 2394bd6313..a0af0e9564 100644 --- a/website/src/pages/create/user_reply.tsx +++ b/website/src/pages/create/user_reply.tsx @@ -3,7 +3,7 @@ import Head from "next/head"; import { Container } from "src/components/Container"; import { LoadingScreen } from "src/components/Loading/LoadingScreen"; import { Task } from "src/components/Tasks/Task"; -import { useCreatePrompterReply } from "src/hooks/tasks/create/useCreateReply"; +import { useCreatePrompterReply } from "src/hooks/tasks/useCreateReply"; const UserReply = () => { const { tasks, isLoading, reset, trigger } = useCreatePrompterReply(); diff --git a/website/src/pages/evaluate/rank_assistant_replies.tsx b/website/src/pages/evaluate/rank_assistant_replies.tsx index 931c919472..8546e7a6d6 100644 --- a/website/src/pages/evaluate/rank_assistant_replies.tsx +++ b/website/src/pages/evaluate/rank_assistant_replies.tsx @@ -3,7 +3,7 @@ import Head from "next/head"; import { Container } from "src/components/Container"; import { LoadingScreen } from "src/components/Loading/LoadingScreen"; import { Task } from "src/components/Tasks/Task"; -import { useRankAssistantRepliesTask } from "src/hooks/tasks/evaluate/useRankReplies"; +import { useRankAssistantRepliesTask } from "src/hooks/tasks/useRankReplies"; const RankAssistantReplies = () => { const { tasks, isLoading, reset, trigger } = useRankAssistantRepliesTask(); diff --git a/website/src/pages/evaluate/rank_initial_prompts.tsx b/website/src/pages/evaluate/rank_initial_prompts.tsx index 4b717143b8..1898a93afe 100644 --- a/website/src/pages/evaluate/rank_initial_prompts.tsx +++ b/website/src/pages/evaluate/rank_initial_prompts.tsx @@ -3,7 +3,7 @@ import Head from "next/head"; import { Container } from "src/components/Container"; import { LoadingScreen } from "src/components/Loading/LoadingScreen"; import { Task } from "src/components/Tasks/Task"; -import { useRankInitialPromptsTask } from "src/hooks/tasks/evaluate/useRankInitialPrompts"; +import { useRankInitialPromptsTask } from "src/hooks/tasks/useRankReplies"; const RankInitialPrompts = () => { const { tasks, isLoading, reset, trigger } = useRankInitialPromptsTask(); diff --git a/website/src/pages/evaluate/rank_user_replies.tsx b/website/src/pages/evaluate/rank_user_replies.tsx index 659874a2d6..e2a399771f 100644 --- a/website/src/pages/evaluate/rank_user_replies.tsx +++ b/website/src/pages/evaluate/rank_user_replies.tsx @@ -3,7 +3,7 @@ import Head from "next/head"; import { Container } from "src/components/Container"; import { LoadingScreen } from "src/components/Loading/LoadingScreen"; import { Task } from "src/components/Tasks/Task"; -import { useRankPrompterRepliesTask } from "src/hooks/tasks/evaluate/useRankReplies"; +import { useRankPrompterRepliesTask } from "src/hooks/tasks/useRankReplies"; const RankUserReplies = () => { const { tasks, isLoading, reset, trigger } = useRankPrompterRepliesTask(); diff --git a/website/src/pages/label/label_assistant_reply.tsx b/website/src/pages/label/label_assistant_reply.tsx index a0f961f784..59a7bbcca0 100644 --- a/website/src/pages/label/label_assistant_reply.tsx +++ b/website/src/pages/label/label_assistant_reply.tsx @@ -1,13 +1,10 @@ import { useState } from "react"; import { LoadingScreen } from "src/components/Loading/LoadingScreen"; -import { Message } from "src/components/Messages"; import { MessageTable } from "src/components/Messages/MessageTable"; import { TaskControls } from "src/components/Survey/TaskControls"; import { LabelSliderGroup, LabelTask } from "src/components/Tasks/LabelTask"; -import { - LabelAssistantReplyTaskResponse, - useLabelAssistantReplyTask, -} from "src/hooks/tasks/labeling/useLabelAssistantReply"; +import { LabelAssistantReplyTaskResponse, useLabelAssistantReplyTask } from "src/hooks/tasks/useLabelingTask"; +import { Message } from "src/types/Conversation"; const LabelAssistantReply = () => { const [sliderValues, setSliderValues] = useState([]); diff --git a/website/src/pages/label/label_initial_prompt.tsx b/website/src/pages/label/label_initial_prompt.tsx index 3c791f230b..4cd4343bcb 100644 --- a/website/src/pages/label/label_initial_prompt.tsx +++ b/website/src/pages/label/label_initial_prompt.tsx @@ -3,10 +3,7 @@ import { LoadingScreen } from "src/components/Loading/LoadingScreen"; import { MessageView } from "src/components/Messages"; import { TaskControls } from "src/components/Survey/TaskControls"; import { LabelSliderGroup, LabelTask } from "src/components/Tasks/LabelTask"; -import { - LabelInitialPromptTaskResponse, - useLabelInitialPromptTask, -} from "src/hooks/tasks/labeling/useLabelInitialPrompt"; +import { LabelInitialPromptTaskResponse, useLabelInitialPromptTask } from "src/hooks/tasks/useLabelingTask"; const LabelInitialPrompt = () => { const [sliderValues, setSliderValues] = useState([]); diff --git a/website/src/pages/label/label_prompter_reply.tsx b/website/src/pages/label/label_prompter_reply.tsx index 2fd3d76ac6..e11e801df6 100644 --- a/website/src/pages/label/label_prompter_reply.tsx +++ b/website/src/pages/label/label_prompter_reply.tsx @@ -1,13 +1,10 @@ import { useState } from "react"; import { LoadingScreen } from "src/components/Loading/LoadingScreen"; -import { Message } from "src/components/Messages"; import { MessageTable } from "src/components/Messages/MessageTable"; import { TaskControls } from "src/components/Survey/TaskControls"; import { LabelSliderGroup, LabelTask } from "src/components/Tasks/LabelTask"; -import { - LabelPrompterReplyTaskResponse, - useLabelPrompterReplyTask, -} from "src/hooks/tasks/labeling/useLabelPrompterReply"; +import { LabelPrompterReplyTaskResponse, useLabelPrompterReplyTask } from "src/hooks/tasks/useLabelingTask"; +import { Message } from "src/types/Conversation"; const LabelPrompterReply = () => { const [sliderValues, setSliderValues] = useState([]); diff --git a/website/src/pages/messages/index.tsx b/website/src/pages/messages/index.tsx index 2809ba5c07..9cdc2ac5c8 100644 --- a/website/src/pages/messages/index.tsx +++ b/website/src/pages/messages/index.tsx @@ -2,9 +2,9 @@ import { Box, CircularProgress, SimpleGrid, Text, useColorModeValue } from "@cha import Head from "next/head"; import { useEffect, useState } from "react"; import { getDashboardLayout } from "src/components/Layout"; -import { Message } from "src/components/Messages"; import { MessageTable } from "src/components/Messages/MessageTable"; import fetcher from "src/lib/fetcher"; +import { Message } from "src/types/Conversation"; import useSWRImmutable from "swr/immutable"; const MessagesDashboard = () => { @@ -74,6 +74,6 @@ const MessagesDashboard = () => { ); }; -MessagesDashboard.getLayout = (page) => getDashboardLayout(page); +MessagesDashboard.getLayout = getDashboardLayout; export default MessagesDashboard; diff --git a/website/src/types/Conversation.ts b/website/src/types/Conversation.ts new file mode 100644 index 0000000000..f12b278155 --- /dev/null +++ b/website/src/types/Conversation.ts @@ -0,0 +1,9 @@ +export interface Message { + text: string; + is_assistant: boolean; + message_id: string; +} + +export interface Conversation { + messages: Message[]; +} diff --git a/website/src/types/Task.ts b/website/src/types/Task.ts new file mode 100644 index 0000000000..0dca6a5b0e --- /dev/null +++ b/website/src/types/Task.ts @@ -0,0 +1,24 @@ +export const enum TaskType { + initial_prompt = "initial_prompt", + assistant_reply = "assistant_reply", + prompter_reply = "prompter_reply", + + rank_initial_prompts = "rank_initial_prompts", + rank_assistant_replies = "rank_assistant_replies", + rank_prompter_replies = "rank_prompter_replies", + + label_initial_prompt = "label_initial_prompt", + label_prompter_reply = "label_prompter_reply", + label_assistant_reply = "label_assistant_reply", +} + +export interface BaseTask { + id: string; + type: TaskType; +} + +export interface TaskResponse { + id: string; + userId: string; + task: Task; +} diff --git a/website/src/types/Tasks.ts b/website/src/types/Tasks.ts new file mode 100644 index 0000000000..50c251bbb0 --- /dev/null +++ b/website/src/types/Tasks.ts @@ -0,0 +1,57 @@ +import { Conversation } from "./Conversation"; +import { BaseTask, TaskType } from "./Task"; + +export interface CreateInitialPromptTask extends BaseTask { + type: TaskType.initial_prompt; + hint: string; +} + +export interface CreateAssistantReplyTask extends BaseTask { + type: TaskType.assistant_reply; + conversation: Conversation; +} + +export interface CreatePrompterReplyTask extends BaseTask { + type: TaskType.prompter_reply; + conversation: Conversation; +} + +export interface RankInitialPromptsTask extends BaseTask { + type: TaskType.rank_initial_prompts; + prompts: string[]; +} + +export interface RankAssistantRepliesTask extends BaseTask { + type: TaskType.rank_assistant_replies; + conversation: Conversation; + replies: string[]; +} + +export interface RankPrompterRepliesTask extends BaseTask { + type: TaskType.rank_prompter_replies; + conversation: Conversation; + replies: string[]; +} + +export interface LabelAssistantReplyTask extends BaseTask { + type: TaskType.label_assistant_reply; + message_id: string; + conversation: Conversation; + reply: string; + valid_labels: string[]; +} + +export interface LabelInitialPromptTask extends BaseTask { + type: TaskType.label_initial_prompt; + message_id: string; + valid_labels: string[]; + prompt: string; +} + +export interface LabelPrompterReplyTask extends BaseTask { + type: TaskType.label_prompter_reply; + message_id: string; + conversation: Conversation; + reply: string; + valid_labels: string[]; +}