UNPKG

simple-ai-provider

Version:

A simple and extensible AI provider package for easy integration of multiple AI services

47 lines (46 loc) 1.96 kB
/** * OpenWebUI Provider Implementation * * Integrates with OpenWebUI instances supporting both its native * chat-completions API (OpenAI-compatible) and the Ollama proxy. The * actual HTTP plumbing lives in two strategy classes; this file picks * one at construction based on `useOllamaProxy`. * * @author Jan-Marlon Leibl * @see https://docs.openwebui.com/ */ import type { AIProviderConfig, CompletionParams, CompletionResponse, CompletionChunk, ProviderInfo } from '../types/index.js'; import { BaseAIProvider } from './base.js'; import { AIProviderError } from '../types/index.js'; export interface OpenWebUIConfig extends AIProviderConfig { /** Default model to use for requests. @default 'llama3.1:latest' */ defaultModel?: string; /** Base URL for the OpenWebUI instance. @default 'http://localhost:3000' */ baseUrl?: string; /** * Use the Ollama proxy endpoint (`/ollama/api/generate`) instead of the * OpenAI-compatible chat completions endpoint. @default false */ useOllamaProxy?: boolean; /** * Allow connections to instances with self-signed certs or plain HTTP. * @default true */ dangerouslyAllowInsecureConnections?: boolean; } export declare class OpenWebUIProvider extends BaseAIProvider { private readonly defaultModel; private readonly baseUrl; private readonly strategy; constructor(config: OpenWebUIConfig); getInfo(): ProviderInfo; protected doInitialize(): Promise<void>; protected doComplete(params: CompletionParams): Promise<CompletionResponse<string>>; protected doStream<T = any>(params: CompletionParams<T>): AsyncIterable<CompletionChunk>; protected validateConnection(): Promise<void>; protected providerErrorMessages(): Partial<Record<number, string>>; protected mapProviderError(error: any): AIProviderError | null; private normalizeBaseUrl; private validateBaseUrl; private warnOnInsecureMix; }