UNPKG

ai-sdk-ollama

Version:

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

63 lines 2.16 kB
/** * Repairing malformed JSON emitted by local models. * * Ollama models routinely produce JSON that is *nearly* valid: block comments, * Python literals (`True`/`None`), smart quotes from instruction tuning, or a * whole object wrapped in a quoted string. `jsonrepair` handles the common * cases; the passes here cover the Ollama-specific ones it does not, and every * one of them is careful to leave string contents alone. */ import type { JSONSchema7 } from '@ai-sdk/provider'; /** * A function that attempts to repair the raw output of the model * to enable JSON parsing and validation. * * Similar to AI SDK's RepairTextFunction but tailored for Ollama's output patterns. */ export type RepairTextFunction = (options: { text: string; error: Error; schema?: JSONSchema7 | unknown; }) => Promise<string | null>; /** * Handles common JSON issues from LLM outputs */ export declare function enhancedRepairText(options: { text: string; error: Error; schema?: JSONSchema7 | unknown; }): Promise<string | null>; /** * Tries jsonrepair first, then enhancedRepairText for Ollama-specific edge cases. */ export declare function cascadeRepairText(options: { text: string; error: Error; schema?: JSONSchema7 | unknown; }): Promise<string | null>; /** * Built-in text repair function for common JSON and Ollama output issues */ export declare function builtInRepairText(options: { text: string; error: Error; schema?: JSONSchema7 | unknown; }): Promise<string | null>; /** * Pick the repair function for a call: a caller-supplied one wins, `false` * opts out entirely, and otherwise the built-in cascade applies. */ export declare function getRepairFunction(options?: { repairText?: RepairTextFunction; enableTextRepair?: boolean; }): RepairTextFunction | undefined; /** * Parse JSON with repair functionality */ export declare function parseJSONWithRepair(text: string, repairFunction?: RepairTextFunction, schema?: JSONSchema7 | unknown): Promise<{ success: boolean; data?: unknown; error?: Error; repaired?: boolean; }>; //# sourceMappingURL=json-text-repair.d.ts.map