import { Notice } from "obsidian"; import * as React from "react"; import Context from "../../core/autocomplete/context-detection"; import { FewShotExample } from "../versions"; type IProps = { name: string; description: string; errorMessages: Map; fewShotExamples: FewShotExample[]; setFewShotExamples(fewShotExamples: FewShotExample[]): void; } export default function FewShotExampleSettings( props: IProps ): React.JSX.Element { const onClickRemoveButton = (index: number) => { return () => { const newFewShotExamples = props.fewShotExamples .slice(0, index) .concat(props.fewShotExamples.slice(index + 1)); props.setFewShotExamples(newFewShotExamples); }; }; const onClickAddButton = () => { const newFewShotExamples = [ { context: Context.Text, input: "TODO", answer: "Thought: TODO\nAnswer: TODO", }, ...props.fewShotExamples, ]; props.setFewShotExamples(newFewShotExamples); }; const onChangeContext = (index: number) => { return (e: React.ChangeEvent) => { const newFewShotExamples = [...props.fewShotExamples]; const context = Context.get(e.target.value); if (context === undefined) { new Notice("Invalid context"); return; } newFewShotExamples[index] = { ...newFewShotExamples[index], context, }; props.setFewShotExamples(newFewShotExamples); }; }; const onChangeInput = (index: number) => { return (e: React.ChangeEvent) => { const newFewShotExamples = [...props.fewShotExamples]; newFewShotExamples[index] = { ...newFewShotExamples[index], input: e.target.value, }; props.setFewShotExamples(newFewShotExamples); }; }; const onAnswerInput = (index: number) => { return (e: React.ChangeEvent) => { const newFewShotExamples = [...props.fewShotExamples]; newFewShotExamples[index] = { ...newFewShotExamples[index], answer: e.target.value, }; props.setFewShotExamples(newFewShotExamples); }; }; return (
{props.name}
{props.description}
{props.errorMessages.get("fewShotExamples") !== undefined && (
{props.errorMessages.get("fewShotExamples")}
)}
{props.fewShotExamples.map((example, index) => (
Example {index + 1}
Context
Human Message
{props.errorMessages.get(`fewShotExamples.${index}.input`) !== undefined && (
{props.errorMessages.get(`fewShotExamples.${index}.input`)}
)}