An AI-powered search engine with a generative UI
TypeScript generative-aigenerative-uinextjsollamareactsearxngshadcn-uitailwindcsstavilytypescriptupstashvercel-ai-sdk
run bun format to align code styling.
Daniel Andersenb1f650833d7e
diff --git a/app/api/config/models/route.ts b/app/api/config/models/route.tsindex fad5dd27..7d648de7 100644--- a/app/api/config/models/route.ts+++ b/app/api/config/models/route.ts@@ -5,17 +5,20 @@ import { getModels } from '@/lib/config/models'export async function GET() {try {const models = await getModels()-- return NextResponse.json({ models }, {- headers: {- 'Cache-Control': 'public, max-age=60, s-maxage=60', // Cache for 1 minute- 'Content-Type': 'application/json'++ return NextResponse.json(+ { models },+ {+ headers: {+ 'Cache-Control': 'public, max-age=60, s-maxage=60', // Cache for 1 minute+ 'Content-Type': 'application/json'+ }}- })+ )} catch (error) {console.error('Failed to fetch models from /api/config/models:', error)return NextResponse.json(- { error: 'Failed to fetch models' },+ { error: 'Failed to fetch models' },{ status: 500 })}diff --git a/app/api/ollama/models/route.ts b/app/api/ollama/models/route.tsindex 1e9aaad4..bb793dde 100644--- a/app/api/ollama/models/route.ts+++ b/app/api/ollama/models/route.ts@@ -12,7 +12,7 @@ export async function GET() {try {const client = new OllamaClient(ollamaUrl)const ollamaModels = await client.getModels()-+const models = []for (const ollamaModel of ollamaModels) {try {@@ -26,7 +26,7 @@ export async function GET() {continue}}-+return NextResponse.json({ models })} catch {return NextResponse.json({ models: [] })diff --git a/lib/config/models.ts b/lib/config/models.tsindex 9a041d48..561dfd65 100644--- a/lib/config/models.ts+++ b/lib/config/models.ts@@ -73,11 +73,13 @@ export async function getModels(): Promise<Model[]> {// Fetch Ollama modelsconst ollamaModels = await fetchOllamaModels(baseUrlObj)-+// Combine static and Ollama modelsconst allModels = [...staticModels, ...ollamaModels]-- console.log(`Loaded ${staticModels.length} static models and ${ollamaModels.length} Ollama models`)++ console.log(+ `Loaded ${staticModels.length} static models and ${ollamaModels.length} Ollama models`+ )return allModels} catch (error) {console.warn('Failed to load models:', error)@@ -100,7 +102,10 @@ async function fetchOllamaModels(baseUrl: URL): Promise<Model[]> {}const ollamaApiUrl = new URL('/api/ollama/models', baseUrl)- console.log('Attempting to fetch Ollama models from:', ollamaApiUrl.toString())+ console.log(+ 'Attempting to fetch Ollama models from:',+ ollamaApiUrl.toString()+ )const response = await fetch(ollamaApiUrl, {cache: 'no-store',@@ -110,7 +115,9 @@ async function fetchOllamaModels(baseUrl: URL): Promise<Model[]> {})if (!response.ok) {- console.warn(`HTTP error when fetching Ollama models: ${response.status} ${response.statusText}`)+ console.warn(+ `HTTP error when fetching Ollama models: ${response.status} ${response.statusText}`+ )return []}@@ -126,4 +133,3 @@ async function fetchOllamaModels(baseUrl: URL): Promise<Model[]> {return []}}-diff --git a/lib/ollama/client.ts b/lib/ollama/client.tsindex 8d1e0396..1a76ec91 100644--- a/lib/ollama/client.ts+++ b/lib/ollama/client.ts@@ -1,12 +1,17 @@-import { OllamaModel, OllamaModelCapabilities, OllamaModelsResponse, OllamaShowResponse } from './types'+import {+ OllamaModel,+ OllamaModelCapabilities,+ OllamaModelsResponse,+ OllamaShowResponse+} from './types'export class OllamaClient {private baseUrl: string-+constructor(baseUrl: string) {this.baseUrl = baseUrl}-+/*** Get all available models from Ollama instance* Uses GET /api/models endpoint for fast model listing@@ -16,14 +21,16 @@ export class OllamaClient {const response = await fetch(`${this.baseUrl}/api/tags`, {cache: 'no-store',headers: {- 'Accept': 'application/json'+ Accept: 'application/json'}})-+if (!response.ok) {- throw new Error(`Ollama API error: ${response.status} ${response.statusText}`)+ throw new Error(+ `Ollama API error: ${response.status} ${response.statusText}`+ )}-+const data: OllamaModelsResponse = await response.json()return data.models || []} catch (error) {@@ -31,26 +38,30 @@ export class OllamaClient {throw error}}-+/*** Get detailed model capabilities from Ollama instance* Uses POST /api/show endpoint for detailed model information*/- async getModelCapabilities(modelName: string): Promise<OllamaModelCapabilities> {+ async getModelCapabilities(+ modelName: string+ ): Promise<OllamaModelCapabilities> {try {const response = await fetch(`${this.baseUrl}/api/show`, {method: 'POST',headers: {'Content-Type': 'application/json',- 'Accept': 'application/json'+ Accept: 'application/json'},body: JSON.stringify({ name: modelName })})-+if (!response.ok) {- throw new Error(`Ollama API error: ${response.status} ${response.statusText}`)+ throw new Error(+ `Ollama API error: ${response.status} ${response.statusText}`+ )}-+const data: OllamaShowResponse = await response.json()return {name: data.name,@@ -63,7 +74,7 @@ export class OllamaClient {throw error}}-+/*** Check if Ollama instance is available*/diff --git a/lib/ollama/transformer.ts b/lib/ollama/transformer.tsindex a6bbc0d9..3d3016be 100644--- a/lib/ollama/transformer.ts+++ b/lib/ollama/transformer.ts@@ -11,7 +11,7 @@ export function transformOllamaModel(capabilities?: OllamaModelCapabilities): Model | null {const hasTools = capabilities?.capabilities.includes('tools') || false-+if (!hasTools) {return null}diff --git a/lib/utils/registry.ts b/lib/utils/registry.tsindex 297de434..8b29625c 100644--- a/lib/utils/registry.ts+++ b/lib/utils/registry.ts@@ -7,9 +7,9 @@ import { groq } from '@ai-sdk/groq'import { createOpenAI, openai } from '@ai-sdk/openai'import { xai } from '@ai-sdk/xai'import {- createProviderRegistry,- extractReasoningMiddleware,- wrapLanguageModel+ createProviderRegistry,+ extractReasoningMiddleware,+ wrapLanguageModel} from 'ai'import { createOllama } from 'ollama-ai-provider'