- Add catalog metadata lookup for better error messages with hints (e.g., for missing manifests or tags) - Persist downloaded model references in saved remote models for future reuse - Replace searchRemoteModels import with getSavedRemoteModels in search route - Enhance pull progress UI to display download bytes, digest, and fallback message when data is unavailable - Improve error payload with model details, URL, and tags count to guide users toward valid tags or models
79 lines
1.8 KiB
TypeScript
79 lines
1.8 KiB
TypeScript
"use client";
|
|
|
|
import { useCallback, useEffect, useState } from "react";
|
|
|
|
export type DevicePref = "auto" | "cpu" | "gpu";
|
|
|
|
type Prefs = {
|
|
selectedModel: string | null; // NOVO
|
|
systemPrompt: string;
|
|
device: DevicePref;
|
|
gpuIndex: number;
|
|
numGpu: number;
|
|
// Preferências de design
|
|
chatLayout?: "compact" | "edge"; // compact = centralizado com max-width; edge = até as bordas
|
|
bubbleSize?: "sm" | "md" | "lg"; // tamanhos de bolha
|
|
};
|
|
|
|
const defaultPrefs: Prefs = {
|
|
selectedModel: null, // NOVO
|
|
systemPrompt: "",
|
|
device: "auto",
|
|
gpuIndex: 0,
|
|
numGpu: 1,
|
|
chatLayout: "compact",
|
|
bubbleSize: "md",
|
|
};
|
|
|
|
export function useUserPrefs() {
|
|
const [prefs, setPrefs] = useState<Prefs>(defaultPrefs);
|
|
const [ready, setReady] = useState(false);
|
|
|
|
// Carregar do Redis
|
|
useEffect(() => {
|
|
fetch("/api/preferences")
|
|
.then((res) => res.json())
|
|
.then((data) => {
|
|
setPrefs(data);
|
|
setReady(true);
|
|
})
|
|
.catch((err) => {
|
|
console.error("Erro ao carregar preferências:", err);
|
|
setReady(true);
|
|
});
|
|
}, []);
|
|
|
|
// Salvar no Redis
|
|
const update = useCallback((next: Partial<Prefs>) => {
|
|
setPrefs((prev) => {
|
|
const merged: Prefs = { ...prev, ...next };
|
|
|
|
// Salvar no Redis
|
|
fetch("/api/preferences", {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify(merged),
|
|
}).catch((err) =>
|
|
console.error("Erro ao salvar preferências:", err)
|
|
);
|
|
|
|
return merged;
|
|
});
|
|
}, []);
|
|
|
|
return { prefs, ready, update };
|
|
}
|
|
|
|
export function buildOllamaOptions(
|
|
device: DevicePref,
|
|
numGpu: number,
|
|
gpuIndex: number
|
|
) {
|
|
if (device === "auto") return undefined;
|
|
if (device === "cpu") return { num_gpu: 0 } as const;
|
|
// gpu
|
|
return {
|
|
num_gpu: Math.max(1, numGpu),
|
|
main_gpu: Math.max(0, gpuIndex),
|
|
} as const;
|
|
} |