"use client"; import { useState } from "react"; import { Check, ChevronsUpDown, Loader2 } from "lucide-react"; import { Button } from "./ui/button"; import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, } from "./ui/command"; import { Popover, PopoverContent, PopoverTrigger } from "./ui/popover"; import { cn } from "@/lib/utils"; import { Switch } from "./ui/switch"; interface OllamaModel { label: string; value: string; description: string; size: string; icon: string; } interface OllamaConfigProps { ollamaModel: string; ollamaUrl: string; useCustomUrl: boolean; ollamaModels: OllamaModel[]; ollamaModelsLoading?: boolean; onInputChange: (value: string, field: string) => void; onUseCustomUrlChange: (checked: boolean) => void; openModelSelect: boolean; onOpenModelSelectChange: (open: boolean) => void; onModelSelect?: (modelName: string) => void; } export default function OllamaConfig({ ollamaModel, ollamaUrl, useCustomUrl, ollamaModels, ollamaModelsLoading = false, onInputChange, onUseCustomUrlChange, openModelSelect, onOpenModelSelectChange, onModelSelect, }: OllamaConfigProps) { return ( <>
{ollamaModelsLoading ? (
Loading models...
) : ollamaModels && ollamaModels.length > 0 ? ( No model found. {ollamaModels?.map((model, index) => ( { if (onModelSelect) { onModelSelect(value); } else { onInputChange(value, "ollama_model"); } onOpenModelSelectChange(false); }} >
{`${model.label}
{model.label} {model.size}
{model.description}
))}
) : (
)}
{(!ollamaModels || ollamaModels.length === 0) && !ollamaModelsLoading && (

No models available. Please check your Ollama connection.

)}
{useCustomUrl && ( <>
onInputChange(e.target.value, "ollama_url") } />

Change this if you are using a custom Ollama instance

)}
); }