feat(ollama): add availability check before model operations
Add `ensureOllamaAvailable` function to lib/ollama.ts for checking and waiting for Ollama server health with configurable timeout. Integrate the check in GET /api/ollama/models route with 3s timeout to prevent UI blocking, and in POST /api/ollama/pull route with 20s timeout to ensure availability before pulling models. Update ChatContainer to always render ModelDropdown for better UX when no model is selected.
This commit is contained in:
1 parent
f96d4ed696
commit
7b2386876a
12 files changed
+211
-20
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { listModelsViaSdk, listModelsViaHttp } from "@/lib/ollama";
|
||||
import { listModelsViaSdk, listModelsViaHttp, ensureOllamaAvailable } from "@/lib/ollama";
|
||||
import {
|
||||
estimateCpuVram,
|
||||
inferDevice,
|
||||
@@ -31,6 +31,8 @@ function normalizeModel(model: any): ModelInfo {
|
||||
export async function GET() {
|
||||
try {
|
||||
let models: any[] = [];
|
||||
// Tentar garantir disponibilidade rapidamente (não bloquear longamente a UI)
|
||||
await ensureOllamaAvailable({ timeoutMs: 3000 }).catch(() => {});
|
||||
try {
|
||||
models = await listModelsViaSdk();
|
||||
} catch {
|
||||
|
||||
Reference in new issue
Block a user