import type { LanguageModelV4, LanguageModelV4CallOptions, LanguageModelV4FinishReason, LanguageModelV4FunctionTool, LanguageModelV4GenerateResult, LanguageModelV4Message, LanguageModelV4StreamResult, LanguageModelV4ToolChoice, LanguageModelV4Usage } from "@ai-sdk/provider"; import { type ChatMessage } from "./native-binding.js"; import { type LlamaCppCacheConfig, type LlamaCppMemorySafetyConfig, type LlamaCppModelMemoryInfo, type LlamaCppReasoningEffort, type LlamaCppReasoningConfig } from "./llama-cpp-provider-config.js"; export interface LlamaCppModelConfig { modelPath: string; /** * Path to the multimodal projector GGUF file. * * Required when image/file parts are included in user messages. */ mmprojPath?: string; /** * Maximum context size. * * This setting is highly dependent on the model and the memory available on * the machine. Higher values can consume significant memory and may freeze * the machine if set too high. Monitor system memory when increasing this * value. */ contextSize?: number; memorySafety?: LlamaCppMemorySafetyConfig; memory?: LlamaCppModelMemoryInfo; gpuLayers?: number; threads?: number; /** * Enable verbose debug output from llama.cpp. * Default: false */ debug?: boolean; /** * Print the final chat-template-rendered prompt sent to llama.cpp to stderr. * * This may include private user data. Intended for local debugging only. * Default: false */ logPrompts?: boolean; /** * Chat template to use for formatting messages. * - "auto" (default): Use the template embedded in the GGUF model file * - Template name: Use a specific built-in template (e.g., "llama3", "chatml", "gemma") * * Available templates: chatml, llama2, llama2-sys, llama3, llama4, mistral-v1, * mistral-v3, mistral-v7, phi3, phi4, gemma, falcon3, zephyr, deepseek, deepseek2, * deepseek3, command-r, and more. */ chatTemplate?: string; /** * Extract model thinking into AI SDK reasoning parts. */ reasoning?: LlamaCppReasoningConfig; cache?: LlamaCppCacheConfig; } export interface LlamaCppGenerationConfig { maxTokens?: number; temperature?: number; topP?: number; topK?: number; stopSequences?: string[]; } interface ResolvedReasoningConfig { opening: string; closing: string; promptPrefix?: string; budgetTokens?: number; } export interface ParsedReasoningPart { type: "text" | "reasoning"; text: string; } export declare function resolveReasoningConfig(reasoning?: LlamaCppReasoningConfig, effort?: LlamaCppReasoningEffort): ResolvedReasoningConfig | undefined; export declare function splitReasoningContent(text: string, reasoning: Pick): ParsedReasoningPart[]; export declare function convertFinishReason(reason: string): LanguageModelV4FinishReason; export declare function convertUsage(promptTokens: number, completionTokens: number, cache?: { read?: number; write?: number; }): LanguageModelV4Usage; /** * Represents a parsed tool call from the model output. */ export interface ParsedToolCall { id: string; name: string; arguments: Record; } /** * Generate a GBNF grammar for tool calls based on the provided tool definitions. * This grammar constrains the model to produce valid JSON tool calls. */ export declare function generateToolCallGrammar(tools: LanguageModelV4FunctionTool[]): string; /** * Parse the model output to extract tool calls. * Supports multiple formats: * - Single tool call: {"name": "...", "arguments": {...}} * - Array of tool calls: [{"name": "...", "arguments": {...}}, ...] * - Legacy format with tool_calls wrapper: {"tool_calls": [...]} * Returns null if the output is not a valid tool call JSON. */ export declare function parseToolCalls(text: string): ParsedToolCall[] | null; /** * Build a system prompt that instructs the model to use tools. */ export declare function buildToolSystemPrompt(tools: LanguageModelV4FunctionTool[], toolChoice?: LanguageModelV4ToolChoice): string; /** * Convert AI SDK messages to simple role/content format for the native layer. * The native layer will apply the appropriate chat template. */ export declare function convertMessages(messages: LanguageModelV4Message[], reasoning?: Pick): ChatMessage[]; export declare class LlamaCppLanguageModel implements LanguageModelV4 { readonly specificationVersion: "v4"; readonly provider = "llama.cpp"; readonly modelId: string; readonly contextSize: number; /** * Supported URL patterns - empty since we only support local files */ readonly supportedUrls: Record; private modelHandle; private readonly config; private initPromise; private loadedContextSize; private readonly activeRequests; constructor(config: LlamaCppModelConfig); private ensureModelLoaded; dispose(): Promise; private prepareGenerationRequest; doGenerate(options: LanguageModelV4CallOptions): Promise; doStream(options: LanguageModelV4CallOptions): Promise; private runWithAbortSignal; } export {}; //# sourceMappingURL=llama-cpp-language-model.d.ts.map