import { LLMBaseBackend, ChatMessage, ChatCompletionResponse } from "./llm-base.js"; import { LLMBackendConfig } from "./types.js"; import { ModelProfile } from "../types/config.js"; import { ToolRegistry } from "./tool-registry.js"; export abstract class OllamaBaseBackend extends LLMBaseBackend { constructor(config: LLMBackendConfig | undefined) { super(config || { base_url: "http://localhost:11434", model_profile: "balanced" }); } protected modelProfileToModel(profile: ModelProfile, availableModels: string[]): string { if (availableModels.length === 0) return "llama3.1"; const sorted = [...availableModels].sort((a, b) => a.length - b.length); switch (profile) { case "speed": return sorted[0]; case "quality": return sorted[sorted.length - 1]; case "balanced": default: return sorted[Math.floor(sorted.length / 2)] || sorted[0]; } } protected async fetchAvailableModels(): Promise { try { const response = await fetch(`${this.config.base_url}/api/tags`); if (!response.ok) return []; const data = await response.json() as { models?: Array<{ name: string }> }; return (data.models || []).map((m) => m.name); } catch { return []; } } } export { ChatMessage as OllamaMessage, ChatCompletionResponse as OllamaChatResponse };