Add LabelPrompterReplyTask

This commit is contained in:
AbdBarho
2023-01-08 10:52:57 +01:00
parent a19e0fa085
commit f7dceee87a
6 changed files with 85 additions and 8 deletions
@@ -15,10 +15,7 @@ export const useLabelInitialPromptTask = () => {
const submit = (id: string, message_id: string, text: string, validLabels: string[], labelWeights: number[]) => {
console.assert(validLabels.length === labelWeights.length);
const labels = validLabels.reduce(
(obj, label, i) => ((obj[label] = labelWeights[i]), obj),
{} as Record<string, number>
);
const labels = Object.fromEntries(validLabels.map((label, i) => [label, labelWeights[i]]));
return trigger({ id, update_type: "text_labels", content: { labels, text, message_id } });
};
@@ -0,0 +1,30 @@
import { TaskResponse, useGenericTaskAPI } from "./useGenericTaskAPI";
export interface LabelPrompterReplyTask {
id: string;
type: "label_prompter_reply";
message_id: string;
valid_labels: string[];
reply: string;
conversation: {
messages: Array<{
text: string;
is_assistant: boolean;
}>;
};
}
export type LabelPrompterReplyTaskResponse = TaskResponse<LabelPrompterReplyTask>;
export const useLabelPrompterReplyTask = () => {
const { tasks, isLoading, trigger, reset, error } = useGenericTaskAPI<LabelPrompterReplyTask>("label_prompter_reply");
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 };
};