"use client" import { ChatbotUIContext } from "@/context/context" import { CHAT_SETTING_LIMITS } from "@/lib/chat-setting-limits" import { ChatSettings } from "@/types" import { IconInfoCircle } from "@tabler/icons-react" import { FC, useContext } from "react" import { ModelSelect } from "../models/model-select" import { AdvancedSettings } from "./advanced-settings" import { Checkbox } from "./checkbox" import { Label } from "./label" import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "./select" import { Slider } from "./slider" import { TextareaAutosize } from "./textarea-autosize" import { WithTooltip } from "./with-tooltip" import { useTranslation } from 'react-i18next' interface ChatSettingsFormProps { chatSettings: ChatSettings onChangeChatSettings: (value: ChatSettings) => void useAdvancedDropdown?: boolean showTooltip?: boolean } export const ChatSettingsForm: FC = ({ chatSettings, onChangeChatSettings, useAdvancedDropdown = true, showTooltip = true }) => { const { t } = useTranslation() const { profile, models } = useContext(ChatbotUIContext) if (!profile) return null return (
{ onChangeChatSettings({ ...chatSettings, model }) }} />
{ onChangeChatSettings({ ...chatSettings, prompt }) }} value={chatSettings.prompt} minRows={3} maxRows={6} />
{useAdvancedDropdown ? ( ) : (
)}
) } interface AdvancedContentProps { chatSettings: ChatSettings onChangeChatSettings: (value: ChatSettings) => void showTooltip: boolean } const AdvancedContent: FC = ({ chatSettings, onChangeChatSettings, showTooltip }) => { const { t } = useTranslation() const { profile, selectedWorkspace, availableOpenRouterModels, models } = useContext(ChatbotUIContext) const isCustomModel = models.some( model => model.model_id === chatSettings.model ) function findOpenRouterModel(modelId: string) { return availableOpenRouterModels.find(model => model.modelId === modelId) } const MODEL_LIMITS = CHAT_SETTING_LIMITS[chatSettings.model] || { MIN_TEMPERATURE: 0, MAX_TEMPERATURE: 1, MAX_CONTEXT_LENGTH: findOpenRouterModel(chatSettings.model)?.maxContext || 4096 } return (
{ onChangeChatSettings({ ...chatSettings, temperature: temperature[0] }) }} min={MODEL_LIMITS.MIN_TEMPERATURE} max={MODEL_LIMITS.MAX_TEMPERATURE} step={0.01} />
{ onChangeChatSettings({ ...chatSettings, contextLength: contextLength[0] }) }} min={0} max={ isCustomModel ? models.find(model => model.model_id === chatSettings.model) ?.context_length : MODEL_LIMITS.MAX_CONTEXT_LENGTH } step={1} />
onChangeChatSettings({ ...chatSettings, includeProfileContext: value }) } /> {showTooltip && ( {profile?.profile_context || t("chat.noProfileContext")}
} trigger={ } /> )}
onChangeChatSettings({ ...chatSettings, includeWorkspaceInstructions: value }) } /> {showTooltip && ( {selectedWorkspace?.instructions || "No workspace instructions."}
} trigger={ } /> )}
) }