UNPKG

ai-sdk-ollama

Version:

Vercel AI SDK Provider for Ollama using official ollama-js library

85 lines 3.67 kB
import { LanguageModelV4CallOptions, LanguageModelV4Prompt, SharedV4Warning } from '@ai-sdk/provider'; import { Message as OllamaMessage, Tool } from 'ollama'; import { OllamaChatSettings } from '../provider.js'; /** * The effective Ollama `think` value for a request, derived from the canonical * Ollama `ChatRequest['think']` contract (`boolean | 'high' | 'medium' | 'low'`). */ export type OllamaThink = OllamaChatSettings['think']; export type OllamaCallOptions = { messages: OllamaMessage[]; options: Record<string, unknown>; format?: string | Record<string, unknown>; tools?: Tool[]; warnings: SharedV4Warning[]; keep_alive?: string | number; }; /** * Whether structured outputs should be enabled for this call. * * A JSON schema always forces them on, so `generateObject` / `Output.object()` * work without the caller opting in; otherwise the model setting decides. */ export declare function shouldEnableStructuredOutputs(settings: OllamaChatSettings, options: LanguageModelV4CallOptions): boolean; /** * Map AI SDK call options onto Ollama's request shape. * * Precedence: AI SDK parameters are mapped to their Ollama equivalents first, * then the model's own `options` win, so callers can reach settings the AI SDK * does not model. */ export declare function getCallOptions(settings: OllamaChatSettings, options: LanguageModelV4CallOptions): OllamaCallOptions; /** * The most recent user turn, as already-converted Ollama messages. */ export declare function getLatestUserMessage(messages: OllamaMessage[]): string; /** * The most recent user turn, read from the original AI SDK prompt. */ export declare function getLatestUserPromptText(prompt: LanguageModelV4Prompt | undefined): string; /** * Resolve the effective Ollama `think` value for a request. * * AI SDK v7 adds a per-call `reasoning` effort option to * `LanguageModelV4CallOptions`. We map it onto Ollama's `think` parameter * (`boolean | 'high' | 'medium' | 'low'`): * * - `'none'` -> `false` * - `'minimal'` / `'low'` -> `'low'` * - `'medium'` -> `'medium'` * - `'high'` / `'xhigh'` -> `'high'` * - `'provider-default'` / unset -> fall back to the `think` provider setting * * The per-call `reasoning` option takes precedence over the model-level * `think` setting, so reasoning effort can vary per request. */ export declare function resolveThink(settings: OllamaChatSettings, options: LanguageModelV4CallOptions): OllamaThink; /** * Assemble the common Ollama chat request envelope shared by every * `client.chat()` call (generate, streaming, tool/object reliability, * forced completion). Callers add the `stream: true | false` literal at the * call site so the Ollama client's streaming overload still resolves. */ export declare function buildChatRequest(parameters: { modelId: string; messages: OllamaMessage[]; options: Record<string, unknown>; format?: string | Record<string, unknown>; tools?: Tool[]; keep_alive?: string | number; think?: OllamaThink; }): { model: string; messages: OllamaMessage[]; options: Record<string, unknown>; format: string | Record<string, unknown> | undefined; tools?: Tool[] | undefined; keep_alive?: string | number | undefined; think?: "high" | "low" | "medium" | boolean | undefined; }; /** * Strip regex patterns Ollama's schema engine cannot compile — they surface as * opaque "fetch failed" errors. Everything else is preserved. */ export declare function cleanSchemaForOllama(schema: Record<string, unknown>): Record<string, unknown>; //# sourceMappingURL=chat-request.d.ts.map