"use client"; import { useState, useEffect } 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"; import { toast } from "sonner"; interface OllamaModel { label: string; value: string; size: string; } interface OllamaConfigProps { ollamaModel: string; ollamaUrl: string; useCustomUrl: boolean; onInputChange: (value: string | boolean, field: string) => void; } export default function OllamaConfig({ ollamaModel, ollamaUrl, useCustomUrl, onInputChange, }: OllamaConfigProps) { const [ollamaModels, setOllamaModels] = useState([]); const [ollamaModelsLoading, setOllamaModelsLoading] = useState(false); const [openModelSelect, setOpenModelSelect] = useState(false); const fetchOllamaModels = async () => { try { setOllamaModelsLoading(true); const response = await fetch('/api/v1/ppt/ollama/models/supported'); if (response.ok) { const data = await response.json(); console.log(data); setOllamaModels(data); } else { console.error('Failed to fetch Ollama models'); setOllamaModels([]); toast.error('Failed to fetch Ollama models'); } } catch (error) { console.error('Error fetching Ollama models:', error); toast.error('Error fetching Ollama models'); setOllamaModels([]); } finally { setOllamaModelsLoading(false); } }; useEffect(() => { fetchOllamaModels(); }, []); return (
{/* URL Configuration */}
onInputChange(checked, "use_custom_url")} />
{useCustomUrl && (
onInputChange(e.target.value, "ollama_url")} />

Change this if you are using a custom Ollama instance

)}
{/* Model Selection */}
{ollamaModelsLoading ? (
Loading models...
) : ollamaModels && ollamaModels.length > 0 ? ( No model found. {ollamaModels?.map((model, index) => ( { onInputChange(value, "ollama_model"); setOpenModelSelect(false); }} >
{model.label} {model.size}
))}
) : (
)}
{(!ollamaModels || ollamaModels.length === 0) && !ollamaModelsLoading && (

No models available. Please check your Ollama connection.

)}
); }