import { Button, InputCheckbox, InputCheckboxList, InputSelect, InputSlider, InputTextarea, } from "@theme"; import { formatBytes } from "@utils/format.ts"; import { MODELS } from "@utils/models.ts"; import { TOOLS } from "@utils/tools.ts"; import { useEffect, useRef } from "react"; import { Controller, useForm } from "react-hook-form"; import type { ChatSettings } from "./types.ts"; export default function ChatSettingsModalForm({ defaultValues, onSubmit, downloadedModels, visible, }: { defaultValues: ChatSettings; onSubmit: (data: ChatSettings) => void; downloadedModels: Array; visible: boolean; }) { const selectModelRef = useRef(null); const { control, handleSubmit, formState: { errors }, } = useForm({ defaultValues, }); const modelOptions = Object.values( Object.entries(MODELS).reduce( (groups, [key, model]) => { const groupName = model.group; if (!groups[groupName]) { groups[groupName] = { label: groupName.charAt(0).toUpperCase() + groupName.slice(1), options: [], }; } groups[groupName].options.push({ value: key, label: `${model.title} - ${formatBytes(model.size)}${downloadedModels.includes(key) ? " *" : ""}`, title: model.title, }); return groups; }, {} as Record< string, { label: string; options: Array<{ value: string; label: string; title: string }>; } > ) ) .sort((a, b) => a.label.localeCompare(b.label)) .map((group) => ({ ...group, options: group.options .sort((a, b) => a.title.localeCompare(b.title)) .map(({ value, label }) => ({ value, label })), })); const toolOptions = TOOLS.map((tool) => ({ name: tool.name, label: tool.name, description: tool.description, })); useEffect(() => { if (visible && selectModelRef.current) { // Use setTimeout to ensure the element is rendered and ready for focus setTimeout(() => { selectModelRef.current?.focus(); }, 200); } }, [visible]); return (
( )} /> ( )} /> ( )} /> ( )} /> ( )} /> ); }