import { FC, useState } from "react"; import { Controller, useForm } from "react-hook-form"; // ui import { Button, Input } from "@plane/ui"; // types import { IFormattedInstanceConfiguration } from "types/instance"; // hooks import useToast from "hooks/use-toast"; // mobx store import { useMobxStore } from "lib/mobx/store-provider"; // icons import { Eye, EyeOff } from "lucide-react"; export interface IInstanceAIForm { config: IFormattedInstanceConfiguration; } export interface AIFormValues { OPENAI_API_KEY: string; GPT_ENGINE: string; } export const InstanceAIForm: FC = (props) => { const { config } = props; // states const [showPassword, setShowPassword] = useState(false); // store const { instance: instanceStore } = useMobxStore(); // toast const { setToastAlert } = useToast(); // form data const { handleSubmit, control, formState: { errors, isSubmitting }, } = useForm({ defaultValues: { OPENAI_API_KEY: config["OPENAI_API_KEY"], GPT_ENGINE: config["GPT_ENGINE"], }, }); const onSubmit = async (formData: AIFormValues) => { const payload: Partial = { ...formData }; await instanceStore .updateInstanceConfigurations(payload) .then(() => setToastAlert({ title: "Success", type: "success", message: "AI Settings updated successfully", }) ) .catch((err) => console.error(err)); }; return ( <>

GPT_ENGINE

( )} />

Choose an OpenAI engine.{" "} Learn more

API key

( )} /> {showPassword ? ( ) : ( )}

You will find your API key{" "} here.

); };