@providerprotocol/ai 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/anthropic/index.js +1 -24
- package/dist/anthropic/index.js.map +1 -1
- package/dist/google/index.js +3 -46
- package/dist/google/index.js.map +1 -1
- package/dist/ollama/index.js +13 -44
- package/dist/ollama/index.js.map +1 -1
- package/dist/openai/index.d.ts +46 -27
- package/dist/openai/index.js +2 -116
- package/dist/openai/index.js.map +1 -1
- package/dist/openrouter/index.d.ts +23 -10
- package/dist/openrouter/index.js +2 -85
- package/dist/openrouter/index.js.map +1 -1
- package/dist/xai/index.d.ts +59 -35
- package/dist/xai/index.js +3 -119
- package/dist/xai/index.js.map +1 -1
- package/package.json +1 -1
- package/src/openai/index.ts +2 -1
- package/src/openrouter/index.ts +2 -1
- package/src/providers/anthropic/transform.ts +7 -29
- package/src/providers/google/transform.ts +9 -49
- package/src/providers/ollama/transform.ts +27 -49
- package/src/providers/openai/index.ts +12 -8
- package/src/providers/openai/llm.completions.ts +9 -9
- package/src/providers/openai/llm.responses.ts +9 -9
- package/src/providers/openai/transform.completions.ts +12 -79
- package/src/providers/openai/transform.responses.ts +12 -54
- package/src/providers/openai/types.ts +54 -31
- package/src/providers/openrouter/index.ts +12 -8
- package/src/providers/openrouter/llm.completions.ts +9 -9
- package/src/providers/openrouter/llm.responses.ts +9 -9
- package/src/providers/openrouter/transform.completions.ts +12 -79
- package/src/providers/openrouter/transform.responses.ts +12 -25
- package/src/providers/openrouter/types.ts +22 -28
- package/src/providers/xai/index.ts +15 -10
- package/src/providers/xai/llm.completions.ts +9 -9
- package/src/providers/xai/llm.messages.ts +9 -9
- package/src/providers/xai/llm.responses.ts +9 -9
- package/src/providers/xai/transform.completions.ts +12 -64
- package/src/providers/xai/transform.messages.ts +11 -30
- package/src/providers/xai/transform.responses.ts +12 -51
- package/src/providers/xai/types.ts +68 -38
- package/src/xai/index.ts +3 -1
package/dist/ollama/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/providers/ollama/transform.ts","../../src/providers/ollama/llm.ts","../../src/providers/ollama/index.ts"],"sourcesContent":["import type { LLMRequest, LLMResponse } from '../../types/llm.ts';\nimport type { Message } from '../../types/messages.ts';\nimport type { StreamEvent } from '../../types/stream.ts';\nimport type { Tool, ToolCall } from '../../types/tool.ts';\nimport type { TokenUsage } from '../../types/turn.ts';\nimport type { ContentBlock, TextBlock, ImageBlock } from '../../types/content.ts';\nimport {\n AssistantMessage,\n isUserMessage,\n isAssistantMessage,\n isToolResultMessage,\n} from '../../types/messages.ts';\nimport type {\n OllamaLLMParams,\n OllamaRequest,\n OllamaMessage,\n OllamaTool,\n OllamaResponse,\n OllamaStreamChunk,\n OllamaToolCall,\n OllamaOptions,\n} from './types.ts';\n\n/**\n * Transform UPP request to Ollama format\n */\nexport function transformRequest<TParams extends OllamaLLMParams>(\n request: LLMRequest<TParams>,\n modelId: string\n): OllamaRequest {\n const params = (request.params ?? {}) as OllamaLLMParams;\n\n const ollamaRequest: OllamaRequest = {\n model: modelId,\n messages: transformMessages(request.messages, request.system),\n };\n\n // Build options object for runtime parameters\n const options: OllamaOptions = {};\n\n if (params.num_predict !== undefined) options.num_predict = params.num_predict;\n if (params.temperature !== undefined) options.temperature = params.temperature;\n if (params.top_p !== undefined) options.top_p = params.top_p;\n if (params.top_k !== undefined) options.top_k = params.top_k;\n if (params.min_p !== undefined) options.min_p = params.min_p;\n if (params.typical_p !== undefined) options.typical_p = params.typical_p;\n if (params.repeat_penalty !== undefined) options.repeat_penalty = params.repeat_penalty;\n if (params.repeat_last_n !== undefined) options.repeat_last_n = params.repeat_last_n;\n if (params.presence_penalty !== undefined) options.presence_penalty = params.presence_penalty;\n if (params.frequency_penalty !== undefined) options.frequency_penalty = params.frequency_penalty;\n if (params.mirostat !== undefined) options.mirostat = params.mirostat;\n if (params.mirostat_eta !== undefined) options.mirostat_eta = params.mirostat_eta;\n if (params.mirostat_tau !== undefined) options.mirostat_tau = params.mirostat_tau;\n if (params.penalize_newline !== undefined) options.penalize_newline = params.penalize_newline;\n if (params.stop !== undefined) options.stop = params.stop;\n if (params.seed !== undefined) options.seed = params.seed;\n if (params.num_keep !== undefined) options.num_keep = params.num_keep;\n if (params.num_ctx !== undefined) options.num_ctx = params.num_ctx;\n if (params.num_batch !== undefined) options.num_batch = params.num_batch;\n if (params.num_thread !== undefined) options.num_thread = params.num_thread;\n if (params.num_gpu !== undefined) options.num_gpu = params.num_gpu;\n if (params.main_gpu !== undefined) options.main_gpu = params.main_gpu;\n if (params.low_vram !== undefined) options.low_vram = params.low_vram;\n if (params.f16_kv !== undefined) options.f16_kv = params.f16_kv;\n if (params.use_mmap !== undefined) options.use_mmap = params.use_mmap;\n if (params.use_mlock !== undefined) options.use_mlock = params.use_mlock;\n if (params.vocab_only !== undefined) options.vocab_only = params.vocab_only;\n if (params.numa !== undefined) options.numa = params.numa;\n if (params.tfs_z !== undefined) options.tfs_z = params.tfs_z;\n\n if (Object.keys(options).length > 0) {\n ollamaRequest.options = options;\n }\n\n // Top-level parameters\n if (params.keep_alive !== undefined) {\n ollamaRequest.keep_alive = params.keep_alive;\n }\n if (params.think !== undefined) {\n ollamaRequest.think = params.think;\n }\n if (params.logprobs !== undefined) {\n ollamaRequest.logprobs = params.logprobs;\n }\n if (params.top_logprobs !== undefined) {\n ollamaRequest.top_logprobs = params.top_logprobs;\n }\n\n // Tools\n if (request.tools && request.tools.length > 0) {\n ollamaRequest.tools = request.tools.map(transformTool);\n }\n\n // Structured output via format field\n if (request.structure) {\n ollamaRequest.format = request.structure as unknown as Record<string, unknown>;\n }\n\n return ollamaRequest;\n}\n\n/**\n * Transform UPP Messages to Ollama messages\n */\nfunction transformMessages(messages: Message[], system?: string): OllamaMessage[] {\n const ollamaMessages: OllamaMessage[] = [];\n\n // System prompt as first message\n if (system) {\n ollamaMessages.push({\n role: 'system',\n content: system,\n });\n }\n\n for (const msg of messages) {\n if (isUserMessage(msg)) {\n const textContent: string[] = [];\n const images: string[] = [];\n\n for (const block of msg.content) {\n if (block.type === 'text') {\n textContent.push(block.text);\n } else if (block.type === 'image') {\n const imageBlock = block as ImageBlock;\n if (imageBlock.source.type === 'base64') {\n images.push(imageBlock.source.data);\n } else if (imageBlock.source.type === 'bytes') {\n // Convert bytes to base64\n const base64 = btoa(\n Array.from(imageBlock.source.data)\n .map((b) => String.fromCharCode(b))\n .join('')\n );\n images.push(base64);\n } else if (imageBlock.source.type === 'url') {\n // Ollama doesn't support URL images directly\n // Would need to fetch and convert, for now just add as text\n textContent.push(`[Image: ${imageBlock.source.url}]`);\n }\n }\n }\n\n const message: OllamaMessage = {\n role: 'user',\n content: textContent.join('\\n'),\n };\n\n if (images.length > 0) {\n message.images = images;\n }\n\n ollamaMessages.push(message);\n } else if (isAssistantMessage(msg)) {\n const textContent = msg.content\n .filter((block): block is TextBlock => block.type === 'text')\n .map((block) => block.text)\n .join('\\n');\n\n const message: OllamaMessage = {\n role: 'assistant',\n content: textContent,\n };\n\n // Add tool calls if present\n if (msg.toolCalls && msg.toolCalls.length > 0) {\n message.tool_calls = msg.toolCalls.map((call) => ({\n function: {\n name: call.toolName,\n arguments: call.arguments,\n },\n }));\n }\n\n ollamaMessages.push(message);\n } else if (isToolResultMessage(msg)) {\n // Tool results are sent as 'tool' role messages\n for (const result of msg.results) {\n ollamaMessages.push({\n role: 'tool',\n tool_name: result.toolCallId, // In our UPP, toolCallId maps to tool name for Ollama\n content:\n typeof result.result === 'string'\n ? result.result\n : JSON.stringify(result.result),\n });\n }\n }\n }\n\n return ollamaMessages;\n}\n\n/**\n * Transform a UPP Tool to Ollama format\n */\nfunction transformTool(tool: Tool): OllamaTool {\n return {\n type: 'function',\n function: {\n name: tool.name,\n description: tool.description,\n parameters: {\n type: 'object',\n properties: tool.parameters.properties,\n required: tool.parameters.required,\n },\n },\n };\n}\n\n/**\n * Transform Ollama response to UPP LLMResponse\n */\nexport function transformResponse(data: OllamaResponse): LLMResponse {\n const textContent: TextBlock[] = [];\n const toolCalls: ToolCall[] = [];\n let structuredData: unknown;\n\n // Add main content\n if (data.message.content) {\n textContent.push({ type: 'text', text: data.message.content });\n\n // Try to parse as JSON for structured output\n try {\n structuredData = JSON.parse(data.message.content);\n } catch {\n // Not valid JSON - that's fine, might not be structured output\n }\n }\n\n // Extract tool calls\n if (data.message.tool_calls) {\n for (const call of data.message.tool_calls) {\n toolCalls.push({\n toolCallId: call.function.name, // Ollama doesn't have separate IDs, use name\n toolName: call.function.name,\n arguments: call.function.arguments,\n });\n }\n }\n\n const message = new AssistantMessage(\n textContent,\n toolCalls.length > 0 ? toolCalls : undefined,\n {\n metadata: {\n ollama: {\n model: data.model,\n created_at: data.created_at,\n done_reason: data.done_reason,\n thinking: data.message.thinking,\n total_duration: data.total_duration,\n load_duration: data.load_duration,\n prompt_eval_duration: data.prompt_eval_duration,\n eval_duration: data.eval_duration,\n logprobs: data.logprobs,\n },\n },\n }\n );\n\n // Calculate token usage\n const usage: TokenUsage = {\n inputTokens: data.prompt_eval_count ?? 0,\n outputTokens: data.eval_count ?? 0,\n totalTokens: (data.prompt_eval_count ?? 0) + (data.eval_count ?? 0),\n };\n\n // Map done_reason to standard stop reason\n let stopReason = 'end_turn';\n if (data.done_reason === 'length') {\n stopReason = 'max_tokens';\n } else if (data.done_reason === 'stop') {\n stopReason = 'end_turn';\n } else if (toolCalls.length > 0) {\n stopReason = 'tool_use';\n }\n\n return {\n message,\n usage,\n stopReason,\n data: structuredData,\n };\n}\n\n/**\n * State for accumulating streaming response\n */\nexport interface StreamState {\n model: string;\n content: string;\n thinking: string;\n toolCalls: Array<{ name: string; args: Record<string, unknown> }>;\n doneReason: string | null;\n promptEvalCount: number;\n evalCount: number;\n totalDuration: number;\n isFirstChunk: boolean;\n createdAt: string;\n}\n\n/**\n * Create initial stream state\n */\nexport function createStreamState(): StreamState {\n return {\n model: '',\n content: '',\n thinking: '',\n toolCalls: [],\n doneReason: null,\n promptEvalCount: 0,\n evalCount: 0,\n totalDuration: 0,\n isFirstChunk: true,\n createdAt: '',\n };\n}\n\n/**\n * Transform Ollama stream chunk to UPP StreamEvents\n */\nexport function transformStreamChunk(\n chunk: OllamaStreamChunk,\n state: StreamState\n): StreamEvent[] {\n const events: StreamEvent[] = [];\n\n // First chunk - emit message start\n if (state.isFirstChunk) {\n state.model = chunk.model;\n state.createdAt = chunk.created_at;\n events.push({ type: 'message_start', index: 0, delta: {} });\n state.isFirstChunk = false;\n }\n\n // Process message content\n if (chunk.message) {\n // Text content delta\n if (chunk.message.content) {\n state.content += chunk.message.content;\n events.push({\n type: 'text_delta',\n index: 0,\n delta: { text: chunk.message.content },\n });\n }\n\n // Thinking content delta\n if (chunk.message.thinking) {\n state.thinking += chunk.message.thinking;\n events.push({\n type: 'reasoning_delta',\n index: 0,\n delta: { text: chunk.message.thinking },\n });\n }\n\n // Tool calls (typically come in final chunk)\n if (chunk.message.tool_calls) {\n for (const call of chunk.message.tool_calls) {\n state.toolCalls.push({\n name: call.function.name,\n args: call.function.arguments,\n });\n events.push({\n type: 'tool_call_delta',\n index: state.toolCalls.length - 1,\n delta: {\n toolCallId: call.function.name,\n toolName: call.function.name,\n argumentsJson: JSON.stringify(call.function.arguments),\n },\n });\n }\n }\n }\n\n // Final chunk with metrics\n if (chunk.done) {\n state.doneReason = chunk.done_reason ?? null;\n state.promptEvalCount = chunk.prompt_eval_count ?? 0;\n state.evalCount = chunk.eval_count ?? 0;\n state.totalDuration = chunk.total_duration ?? 0;\n events.push({ type: 'message_stop', index: 0, delta: {} });\n }\n\n return events;\n}\n\n/**\n * Build LLMResponse from accumulated stream state\n */\nexport function buildResponseFromState(state: StreamState): LLMResponse {\n const textContent: TextBlock[] = [];\n const toolCalls: ToolCall[] = [];\n let structuredData: unknown;\n\n if (state.content) {\n textContent.push({ type: 'text', text: state.content });\n\n // Try to parse as JSON for structured output\n try {\n structuredData = JSON.parse(state.content);\n } catch {\n // Not valid JSON - that's fine\n }\n }\n\n for (const tc of state.toolCalls) {\n toolCalls.push({\n toolCallId: tc.name,\n toolName: tc.name,\n arguments: tc.args,\n });\n }\n\n const message = new AssistantMessage(\n textContent,\n toolCalls.length > 0 ? toolCalls : undefined,\n {\n metadata: {\n ollama: {\n model: state.model,\n created_at: state.createdAt,\n done_reason: state.doneReason,\n thinking: state.thinking || undefined,\n total_duration: state.totalDuration,\n },\n },\n }\n );\n\n const usage: TokenUsage = {\n inputTokens: state.promptEvalCount,\n outputTokens: state.evalCount,\n totalTokens: state.promptEvalCount + state.evalCount,\n };\n\n // Map done_reason to standard stop reason\n let stopReason = 'end_turn';\n if (state.doneReason === 'length') {\n stopReason = 'max_tokens';\n } else if (toolCalls.length > 0) {\n stopReason = 'tool_use';\n }\n\n return {\n message,\n usage,\n stopReason,\n data: structuredData,\n };\n}\n","import type {\n LLMHandler,\n BoundLLMModel,\n LLMRequest,\n LLMResponse,\n LLMStreamResult,\n LLMCapabilities,\n} from '../../types/llm.ts';\nimport type { StreamEvent } from '../../types/stream.ts';\nimport type { LLMProvider } from '../../types/provider.ts';\nimport { UPPError } from '../../types/errors.ts';\nimport { resolveApiKey } from '../../http/keys.ts';\nimport { doFetch, doStreamFetch } from '../../http/fetch.ts';\nimport { normalizeHttpError } from '../../http/errors.ts';\nimport type { OllamaLLMParams, OllamaResponse, OllamaStreamChunk } from './types.ts';\nimport {\n transformRequest,\n transformResponse,\n transformStreamChunk,\n createStreamState,\n buildResponseFromState,\n} from './transform.ts';\n\nconst OLLAMA_DEFAULT_URL = 'http://localhost:11434';\n\n/**\n * Ollama API capabilities\n * Note: Tool calling is disabled - Ollama recommends using their\n * OpenAI-compatible API (/v1/chat/completions) for tool calling.\n * Use the OpenAI provider with baseUrl pointed to Ollama for tools.\n */\nconst OLLAMA_CAPABILITIES: LLMCapabilities = {\n streaming: true,\n tools: false,\n structuredOutput: true,\n imageInput: true,\n videoInput: false,\n audioInput: false,\n};\n\n/**\n * Parse Ollama's newline-delimited JSON stream\n */\nasync function* parseOllamaStream(\n body: ReadableStream<Uint8Array>\n): AsyncGenerator<OllamaStreamChunk, void, unknown> {\n const reader = body.getReader();\n const decoder = new TextDecoder();\n let buffer = '';\n\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n\n buffer += decoder.decode(value, { stream: true });\n\n // Process complete lines (Ollama uses newline-delimited JSON)\n const lines = buffer.split('\\n');\n buffer = lines.pop() ?? ''; // Keep incomplete line in buffer\n\n for (const line of lines) {\n const trimmed = line.trim();\n if (!trimmed) continue;\n\n try {\n const chunk = JSON.parse(trimmed) as OllamaStreamChunk;\n yield chunk;\n } catch {\n // Skip invalid JSON lines\n }\n }\n }\n\n // Process any remaining buffer\n if (buffer.trim()) {\n try {\n const chunk = JSON.parse(buffer.trim()) as OllamaStreamChunk;\n yield chunk;\n } catch {\n // Skip invalid JSON\n }\n }\n } finally {\n reader.releaseLock();\n }\n}\n\n/**\n * Create Ollama LLM handler\n */\nexport function createLLMHandler(): LLMHandler<OllamaLLMParams> {\n // Provider reference injected by createProvider() after construction\n let providerRef: LLMProvider<OllamaLLMParams> | null = null;\n\n return {\n _setProvider(provider: LLMProvider<OllamaLLMParams>) {\n providerRef = provider;\n },\n\n bind(modelId: string): BoundLLMModel<OllamaLLMParams> {\n // Use the injected provider reference (set by createProvider)\n if (!providerRef) {\n throw new UPPError(\n 'Provider reference not set. Handler must be used with createProvider().',\n 'INVALID_REQUEST',\n 'ollama',\n 'llm'\n );\n }\n\n const model: BoundLLMModel<OllamaLLMParams> = {\n modelId,\n capabilities: OLLAMA_CAPABILITIES,\n\n get provider(): LLMProvider<OllamaLLMParams> {\n return providerRef!;\n },\n\n async complete(request: LLMRequest<OllamaLLMParams>): Promise<LLMResponse> {\n // Ollama doesn't require an API key by default, but may use one for auth\n let apiKey: string | undefined;\n try {\n apiKey = await resolveApiKey(\n request.config,\n 'OLLAMA_API_KEY',\n 'ollama',\n 'llm'\n );\n } catch {\n // API key is optional for Ollama\n }\n\n const baseUrl = request.config.baseUrl ?? OLLAMA_DEFAULT_URL;\n const url = `${baseUrl}/api/chat`;\n const body = transformRequest(request, modelId);\n body.stream = false;\n\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n };\n\n if (apiKey) {\n headers['Authorization'] = `Bearer ${apiKey}`;\n }\n\n const response = await doFetch(\n url,\n {\n method: 'POST',\n headers,\n body: JSON.stringify(body),\n signal: request.signal,\n },\n request.config,\n 'ollama',\n 'llm'\n );\n\n const data = (await response.json()) as OllamaResponse;\n return transformResponse(data);\n },\n\n stream(request: LLMRequest<OllamaLLMParams>): LLMStreamResult {\n const state = createStreamState();\n let responseResolve: (value: LLMResponse) => void;\n let responseReject: (error: Error) => void;\n\n const responsePromise = new Promise<LLMResponse>((resolve, reject) => {\n responseResolve = resolve;\n responseReject = reject;\n });\n\n async function* generateEvents(): AsyncGenerator<StreamEvent, void, unknown> {\n try {\n // Ollama doesn't require an API key by default\n let apiKey: string | undefined;\n try {\n apiKey = await resolveApiKey(\n request.config,\n 'OLLAMA_API_KEY',\n 'ollama',\n 'llm'\n );\n } catch {\n // API key is optional for Ollama\n }\n\n const baseUrl = request.config.baseUrl ?? OLLAMA_DEFAULT_URL;\n const url = `${baseUrl}/api/chat`;\n const body = transformRequest(request, modelId);\n body.stream = true;\n\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n };\n\n if (apiKey) {\n headers['Authorization'] = `Bearer ${apiKey}`;\n }\n\n const response = await doStreamFetch(\n url,\n {\n method: 'POST',\n headers,\n body: JSON.stringify(body),\n signal: request.signal,\n },\n request.config,\n 'ollama',\n 'llm'\n );\n\n if (!response.ok) {\n const error = await normalizeHttpError(response, 'ollama', 'llm');\n responseReject(error);\n throw error;\n }\n\n if (!response.body) {\n const error = new UPPError(\n 'No response body for streaming request',\n 'PROVIDER_ERROR',\n 'ollama',\n 'llm'\n );\n responseReject(error);\n throw error;\n }\n\n // Parse Ollama's newline-delimited JSON stream\n for await (const chunk of parseOllamaStream(response.body)) {\n // Check for error in chunk\n if ('error' in chunk && typeof (chunk as Record<string, unknown>).error === 'string') {\n const error = new UPPError(\n (chunk as Record<string, unknown>).error as string,\n 'PROVIDER_ERROR',\n 'ollama',\n 'llm'\n );\n responseReject(error);\n throw error;\n }\n\n const events = transformStreamChunk(chunk, state);\n for (const event of events) {\n yield event;\n }\n }\n\n // Build final response\n responseResolve(buildResponseFromState(state));\n } catch (error) {\n responseReject(error as Error);\n throw error;\n }\n }\n\n return {\n [Symbol.asyncIterator]() {\n return generateEvents();\n },\n response: responsePromise,\n };\n },\n };\n\n return model;\n },\n };\n}\n","import { createProvider } from '../../core/provider.ts';\nimport { createLLMHandler } from './llm.ts';\n\n/**\n * Ollama provider\n * Supports LLM modality with local Ollama models\n *\n * Ollama is a local LLM server that supports many open-source models including:\n * - Llama 3.x\n * - Mistral\n * - Mixtral\n * - Gemma\n * - Qwen\n * - DeepSeek\n * - Phi\n * - And many more\n *\n * @example\n * ```ts\n * import { llm } from 'provider-protocol';\n * import { ollama } from 'provider-protocol/ollama';\n *\n * const model = llm(ollama('llama3.2'));\n * const result = await model.generate('Hello, how are you?');\n * ```\n *\n * @example Custom server URL\n * ```ts\n * const model = llm(ollama('llama3.2'), {\n * baseUrl: 'http://my-ollama-server:11434',\n * });\n * ```\n */\nexport const ollama = createProvider({\n name: 'ollama',\n version: '1.0.0',\n modalities: {\n llm: createLLMHandler(),\n },\n});\n\n// Re-export types\nexport type { OllamaLLMParams } from './types.ts';\n"],"mappings":";;;;;;;;;;;;;;;;;;AA0BO,SAAS,iBACd,SACA,SACe;AACf,QAAM,SAAU,QAAQ,UAAU,CAAC;AAEnC,QAAM,gBAA+B;AAAA,IACnC,OAAO;AAAA,IACP,UAAU,kBAAkB,QAAQ,UAAU,QAAQ,MAAM;AAAA,EAC9D;AAGA,QAAM,UAAyB,CAAC;AAEhC,MAAI,OAAO,gBAAgB,OAAW,SAAQ,cAAc,OAAO;AACnE,MAAI,OAAO,gBAAgB,OAAW,SAAQ,c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AM;AAAA,gBACR;AAEA,sBAAM,SAAS,qBAAqB,OAAO,KAAK;AAChD,2BAAW,SAAS,QAAQ;AAC1B,wBAAM;AAAA,gBACR;AAAA,cACF;AAGA,8BAAgB,uBAAuB,KAAK,CAAC;AAAA,YAC/C,SAAS,OAAO;AACd,6BAAe,KAAc;AAC7B,oBAAM;AAAA,YACR;AAAA,UACF;AAEA,iBAAO;AAAA,YACL,CAAC,OAAO,aAAa,IAAI;AACvB,qBAAO,eAAe;AAAA,YACxB;AAAA,YACA,UAAU;AAAA,UACZ;AAAA,QACF;AAAA,MACF;AAEA,aAAO;AAAA,IACT;AAAA,EACF;AACF;;;AC9OO,IAAM,SAAS,eAAe;AAAA,EACnC,MAAM;AAAA,EACN,SAAS;AAAA,EACT,YAAY;AAAA,IACV,KAAK,iBAAiB;AAAA,EACxB;AACF,CAAC;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/providers/ollama/transform.ts","../../src/providers/ollama/llm.ts","../../src/providers/ollama/index.ts"],"sourcesContent":["import type { LLMRequest, LLMResponse } from '../../types/llm.ts';\nimport type { Message } from '../../types/messages.ts';\nimport type { StreamEvent } from '../../types/stream.ts';\nimport type { Tool, ToolCall } from '../../types/tool.ts';\nimport type { TokenUsage } from '../../types/turn.ts';\nimport type { ContentBlock, TextBlock, ImageBlock } from '../../types/content.ts';\nimport {\n AssistantMessage,\n isUserMessage,\n isAssistantMessage,\n isToolResultMessage,\n} from '../../types/messages.ts';\nimport type {\n OllamaLLMParams,\n OllamaRequest,\n OllamaMessage,\n OllamaTool,\n OllamaResponse,\n OllamaStreamChunk,\n OllamaToolCall,\n OllamaOptions,\n} from './types.ts';\n\n/**\n * Transform UPP request to Ollama format\n *\n * Params are spread to allow pass-through of any Ollama API fields,\n * even those not explicitly defined in our type. This enables developers to\n * use new API features without waiting for library updates.\n *\n * Note: Ollama uses nested 'options' for model parameters. Params that belong\n * in options (like temperature, top_p, etc.) are spread into options, while\n * top-level params (like keep_alive, think) are spread at the request level.\n */\nexport function transformRequest<TParams extends OllamaLLMParams>(\n request: LLMRequest<TParams>,\n modelId: string\n): OllamaRequest {\n const params = (request.params ?? {}) as OllamaLLMParams;\n\n // Extract top-level params vs options params\n const {\n keep_alive,\n think,\n logprobs,\n top_logprobs,\n ...optionsParams\n } = params;\n\n // Spread params to pass through all fields, then set required fields\n const ollamaRequest: OllamaRequest = {\n model: modelId,\n messages: transformMessages(request.messages, request.system),\n };\n\n // Add top-level params if provided\n if (keep_alive !== undefined) ollamaRequest.keep_alive = keep_alive;\n if (think !== undefined) ollamaRequest.think = think;\n if (logprobs !== undefined) ollamaRequest.logprobs = logprobs;\n if (top_logprobs !== undefined) ollamaRequest.top_logprobs = top_logprobs;\n\n // Spread remaining params into options to pass through all model parameters\n if (Object.keys(optionsParams).length > 0) {\n ollamaRequest.options = optionsParams as OllamaOptions;\n }\n\n // Tools come from request, not params\n if (request.tools && request.tools.length > 0) {\n ollamaRequest.tools = request.tools.map(transformTool);\n }\n\n // Structured output via format field\n if (request.structure) {\n ollamaRequest.format = request.structure as unknown as Record<string, unknown>;\n }\n\n return ollamaRequest;\n}\n\n/**\n * Transform UPP Messages to Ollama messages\n */\nfunction transformMessages(messages: Message[], system?: string): OllamaMessage[] {\n const ollamaMessages: OllamaMessage[] = [];\n\n // System prompt as first message\n if (system) {\n ollamaMessages.push({\n role: 'system',\n content: system,\n });\n }\n\n for (const msg of messages) {\n if (isUserMessage(msg)) {\n const textContent: string[] = [];\n const images: string[] = [];\n\n for (const block of msg.content) {\n if (block.type === 'text') {\n textContent.push(block.text);\n } else if (block.type === 'image') {\n const imageBlock = block as ImageBlock;\n if (imageBlock.source.type === 'base64') {\n images.push(imageBlock.source.data);\n } else if (imageBlock.source.type === 'bytes') {\n // Convert bytes to base64\n const base64 = btoa(\n Array.from(imageBlock.source.data)\n .map((b) => String.fromCharCode(b))\n .join('')\n );\n images.push(base64);\n } else if (imageBlock.source.type === 'url') {\n // Ollama doesn't support URL images directly\n // Would need to fetch and convert, for now just add as text\n textContent.push(`[Image: ${imageBlock.source.url}]`);\n }\n }\n }\n\n const message: OllamaMessage = {\n role: 'user',\n content: textContent.join('\\n'),\n };\n\n if (images.length > 0) {\n message.images = images;\n }\n\n ollamaMessages.push(message);\n } else if (isAssistantMessage(msg)) {\n const textContent = msg.content\n .filter((block): block is TextBlock => block.type === 'text')\n .map((block) => block.text)\n .join('\\n');\n\n const message: OllamaMessage = {\n role: 'assistant',\n content: textContent,\n };\n\n // Add tool calls if present\n if (msg.toolCalls && msg.toolCalls.length > 0) {\n message.tool_calls = msg.toolCalls.map((call) => ({\n function: {\n name: call.toolName,\n arguments: call.arguments,\n },\n }));\n }\n\n ollamaMessages.push(message);\n } else if (isToolResultMessage(msg)) {\n // Tool results are sent as 'tool' role messages\n for (const result of msg.results) {\n ollamaMessages.push({\n role: 'tool',\n tool_name: result.toolCallId, // In our UPP, toolCallId maps to tool name for Ollama\n content:\n typeof result.result === 'string'\n ? result.result\n : JSON.stringify(result.result),\n });\n }\n }\n }\n\n return ollamaMessages;\n}\n\n/**\n * Transform a UPP Tool to Ollama format\n */\nfunction transformTool(tool: Tool): OllamaTool {\n return {\n type: 'function',\n function: {\n name: tool.name,\n description: tool.description,\n parameters: {\n type: 'object',\n properties: tool.parameters.properties,\n required: tool.parameters.required,\n },\n },\n };\n}\n\n/**\n * Transform Ollama response to UPP LLMResponse\n */\nexport function transformResponse(data: OllamaResponse): LLMResponse {\n const textContent: TextBlock[] = [];\n const toolCalls: ToolCall[] = [];\n let structuredData: unknown;\n\n // Add main content\n if (data.message.content) {\n textContent.push({ type: 'text', text: data.message.content });\n\n // Try to parse as JSON for structured output\n try {\n structuredData = JSON.parse(data.message.content);\n } catch {\n // Not valid JSON - that's fine, might not be structured output\n }\n }\n\n // Extract tool calls\n if (data.message.tool_calls) {\n for (const call of data.message.tool_calls) {\n toolCalls.push({\n toolCallId: call.function.name, // Ollama doesn't have separate IDs, use name\n toolName: call.function.name,\n arguments: call.function.arguments,\n });\n }\n }\n\n const message = new AssistantMessage(\n textContent,\n toolCalls.length > 0 ? toolCalls : undefined,\n {\n metadata: {\n ollama: {\n model: data.model,\n created_at: data.created_at,\n done_reason: data.done_reason,\n thinking: data.message.thinking,\n total_duration: data.total_duration,\n load_duration: data.load_duration,\n prompt_eval_duration: data.prompt_eval_duration,\n eval_duration: data.eval_duration,\n logprobs: data.logprobs,\n },\n },\n }\n );\n\n // Calculate token usage\n const usage: TokenUsage = {\n inputTokens: data.prompt_eval_count ?? 0,\n outputTokens: data.eval_count ?? 0,\n totalTokens: (data.prompt_eval_count ?? 0) + (data.eval_count ?? 0),\n };\n\n // Map done_reason to standard stop reason\n let stopReason = 'end_turn';\n if (data.done_reason === 'length') {\n stopReason = 'max_tokens';\n } else if (data.done_reason === 'stop') {\n stopReason = 'end_turn';\n } else if (toolCalls.length > 0) {\n stopReason = 'tool_use';\n }\n\n return {\n message,\n usage,\n stopReason,\n data: structuredData,\n };\n}\n\n/**\n * State for accumulating streaming response\n */\nexport interface StreamState {\n model: string;\n content: string;\n thinking: string;\n toolCalls: Array<{ name: string; args: Record<string, unknown> }>;\n doneReason: string | null;\n promptEvalCount: number;\n evalCount: number;\n totalDuration: number;\n isFirstChunk: boolean;\n createdAt: string;\n}\n\n/**\n * Create initial stream state\n */\nexport function createStreamState(): StreamState {\n return {\n model: '',\n content: '',\n thinking: '',\n toolCalls: [],\n doneReason: null,\n promptEvalCount: 0,\n evalCount: 0,\n totalDuration: 0,\n isFirstChunk: true,\n createdAt: '',\n };\n}\n\n/**\n * Transform Ollama stream chunk to UPP StreamEvents\n */\nexport function transformStreamChunk(\n chunk: OllamaStreamChunk,\n state: StreamState\n): StreamEvent[] {\n const events: StreamEvent[] = [];\n\n // First chunk - emit message start\n if (state.isFirstChunk) {\n state.model = chunk.model;\n state.createdAt = chunk.created_at;\n events.push({ type: 'message_start', index: 0, delta: {} });\n state.isFirstChunk = false;\n }\n\n // Process message content\n if (chunk.message) {\n // Text content delta\n if (chunk.message.content) {\n state.content += chunk.message.content;\n events.push({\n type: 'text_delta',\n index: 0,\n delta: { text: chunk.message.content },\n });\n }\n\n // Thinking content delta\n if (chunk.message.thinking) {\n state.thinking += chunk.message.thinking;\n events.push({\n type: 'reasoning_delta',\n index: 0,\n delta: { text: chunk.message.thinking },\n });\n }\n\n // Tool calls (typically come in final chunk)\n if (chunk.message.tool_calls) {\n for (const call of chunk.message.tool_calls) {\n state.toolCalls.push({\n name: call.function.name,\n args: call.function.arguments,\n });\n events.push({\n type: 'tool_call_delta',\n index: state.toolCalls.length - 1,\n delta: {\n toolCallId: call.function.name,\n toolName: call.function.name,\n argumentsJson: JSON.stringify(call.function.arguments),\n },\n });\n }\n }\n }\n\n // Final chunk with metrics\n if (chunk.done) {\n state.doneReason = chunk.done_reason ?? null;\n state.promptEvalCount = chunk.prompt_eval_count ?? 0;\n state.evalCount = chunk.eval_count ?? 0;\n state.totalDuration = chunk.total_duration ?? 0;\n events.push({ type: 'message_stop', index: 0, delta: {} });\n }\n\n return events;\n}\n\n/**\n * Build LLMResponse from accumulated stream state\n */\nexport function buildResponseFromState(state: StreamState): LLMResponse {\n const textContent: TextBlock[] = [];\n const toolCalls: ToolCall[] = [];\n let structuredData: unknown;\n\n if (state.content) {\n textContent.push({ type: 'text', text: state.content });\n\n // Try to parse as JSON for structured output\n try {\n structuredData = JSON.parse(state.content);\n } catch {\n // Not valid JSON - that's fine\n }\n }\n\n for (const tc of state.toolCalls) {\n toolCalls.push({\n toolCallId: tc.name,\n toolName: tc.name,\n arguments: tc.args,\n });\n }\n\n const message = new AssistantMessage(\n textContent,\n toolCalls.length > 0 ? toolCalls : undefined,\n {\n metadata: {\n ollama: {\n model: state.model,\n created_at: state.createdAt,\n done_reason: state.doneReason,\n thinking: state.thinking || undefined,\n total_duration: state.totalDuration,\n },\n },\n }\n );\n\n const usage: TokenUsage = {\n inputTokens: state.promptEvalCount,\n outputTokens: state.evalCount,\n totalTokens: state.promptEvalCount + state.evalCount,\n };\n\n // Map done_reason to standard stop reason\n let stopReason = 'end_turn';\n if (state.doneReason === 'length') {\n stopReason = 'max_tokens';\n } else if (toolCalls.length > 0) {\n stopReason = 'tool_use';\n }\n\n return {\n message,\n usage,\n stopReason,\n data: structuredData,\n };\n}\n","import type {\n LLMHandler,\n BoundLLMModel,\n LLMRequest,\n LLMResponse,\n LLMStreamResult,\n LLMCapabilities,\n} from '../../types/llm.ts';\nimport type { StreamEvent } from '../../types/stream.ts';\nimport type { LLMProvider } from '../../types/provider.ts';\nimport { UPPError } from '../../types/errors.ts';\nimport { resolveApiKey } from '../../http/keys.ts';\nimport { doFetch, doStreamFetch } from '../../http/fetch.ts';\nimport { normalizeHttpError } from '../../http/errors.ts';\nimport type { OllamaLLMParams, OllamaResponse, OllamaStreamChunk } from './types.ts';\nimport {\n transformRequest,\n transformResponse,\n transformStreamChunk,\n createStreamState,\n buildResponseFromState,\n} from './transform.ts';\n\nconst OLLAMA_DEFAULT_URL = 'http://localhost:11434';\n\n/**\n * Ollama API capabilities\n * Note: Tool calling is disabled - Ollama recommends using their\n * OpenAI-compatible API (/v1/chat/completions) for tool calling.\n * Use the OpenAI provider with baseUrl pointed to Ollama for tools.\n */\nconst OLLAMA_CAPABILITIES: LLMCapabilities = {\n streaming: true,\n tools: false,\n structuredOutput: true,\n imageInput: true,\n videoInput: false,\n audioInput: false,\n};\n\n/**\n * Parse Ollama's newline-delimited JSON stream\n */\nasync function* parseOllamaStream(\n body: ReadableStream<Uint8Array>\n): AsyncGenerator<OllamaStreamChunk, void, unknown> {\n const reader = body.getReader();\n const decoder = new TextDecoder();\n let buffer = '';\n\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n\n buffer += decoder.decode(value, { stream: true });\n\n // Process complete lines (Ollama uses newline-delimited JSON)\n const lines = buffer.split('\\n');\n buffer = lines.pop() ?? ''; // Keep incomplete line in buffer\n\n for (const line of lines) {\n const trimmed = line.trim();\n if (!trimmed) continue;\n\n try {\n const chunk = JSON.parse(trimmed) as OllamaStreamChunk;\n yield chunk;\n } catch {\n // Skip invalid JSON lines\n }\n }\n }\n\n // Process any remaining buffer\n if (buffer.trim()) {\n try {\n const chunk = JSON.parse(buffer.trim()) as OllamaStreamChunk;\n yield chunk;\n } catch {\n // Skip invalid JSON\n }\n }\n } finally {\n reader.releaseLock();\n }\n}\n\n/**\n * Create Ollama LLM handler\n */\nexport function createLLMHandler(): LLMHandler<OllamaLLMParams> {\n // Provider reference injected by createProvider() after construction\n let providerRef: LLMProvider<OllamaLLMParams> | null = null;\n\n return {\n _setProvider(provider: LLMProvider<OllamaLLMParams>) {\n providerRef = provider;\n },\n\n bind(modelId: string): BoundLLMModel<OllamaLLMParams> {\n // Use the injected provider reference (set by createProvider)\n if (!providerRef) {\n throw new UPPError(\n 'Provider reference not set. Handler must be used with createProvider().',\n 'INVALID_REQUEST',\n 'ollama',\n 'llm'\n );\n }\n\n const model: BoundLLMModel<OllamaLLMParams> = {\n modelId,\n capabilities: OLLAMA_CAPABILITIES,\n\n get provider(): LLMProvider<OllamaLLMParams> {\n return providerRef!;\n },\n\n async complete(request: LLMRequest<OllamaLLMParams>): Promise<LLMResponse> {\n // Ollama doesn't require an API key by default, but may use one for auth\n let apiKey: string | undefined;\n try {\n apiKey = await resolveApiKey(\n request.config,\n 'OLLAMA_API_KEY',\n 'ollama',\n 'llm'\n );\n } catch {\n // API key is optional for Ollama\n }\n\n const baseUrl = request.config.baseUrl ?? OLLAMA_DEFAULT_URL;\n const url = `${baseUrl}/api/chat`;\n const body = transformRequest(request, modelId);\n body.stream = false;\n\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n };\n\n if (apiKey) {\n headers['Authorization'] = `Bearer ${apiKey}`;\n }\n\n const response = await doFetch(\n url,\n {\n method: 'POST',\n headers,\n body: JSON.stringify(body),\n signal: request.signal,\n },\n request.config,\n 'ollama',\n 'llm'\n );\n\n const data = (await response.json()) as OllamaResponse;\n return transformResponse(data);\n },\n\n stream(request: LLMRequest<OllamaLLMParams>): LLMStreamResult {\n const state = createStreamState();\n let responseResolve: (value: LLMResponse) => void;\n let responseReject: (error: Error) => void;\n\n const responsePromise = new Promise<LLMResponse>((resolve, reject) => {\n responseResolve = resolve;\n responseReject = reject;\n });\n\n async function* generateEvents(): AsyncGenerator<StreamEvent, void, unknown> {\n try {\n // Ollama doesn't require an API key by default\n let apiKey: string | undefined;\n try {\n apiKey = await resolveApiKey(\n request.config,\n 'OLLAMA_API_KEY',\n 'ollama',\n 'llm'\n );\n } catch {\n // API key is optional for Ollama\n }\n\n const baseUrl = request.config.baseUrl ?? OLLAMA_DEFAULT_URL;\n const url = `${baseUrl}/api/chat`;\n const body = transformRequest(request, modelId);\n body.stream = true;\n\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n };\n\n if (apiKey) {\n headers['Authorization'] = `Bearer ${apiKey}`;\n }\n\n const response = await doStreamFetch(\n url,\n {\n method: 'POST',\n headers,\n body: JSON.stringify(body),\n signal: request.signal,\n },\n request.config,\n 'ollama',\n 'llm'\n );\n\n if (!response.ok) {\n const error = await normalizeHttpError(response, 'ollama', 'llm');\n responseReject(error);\n throw error;\n }\n\n if (!response.body) {\n const error = new UPPError(\n 'No response body for streaming request',\n 'PROVIDER_ERROR',\n 'ollama',\n 'llm'\n );\n responseReject(error);\n throw error;\n }\n\n // Parse Ollama's newline-delimited JSON stream\n for await (const chunk of parseOllamaStream(response.body)) {\n // Check for error in chunk\n if ('error' in chunk && typeof (chunk as Record<string, unknown>).error === 'string') {\n const error = new UPPError(\n (chunk as Record<string, unknown>).error as string,\n 'PROVIDER_ERROR',\n 'ollama',\n 'llm'\n );\n responseReject(error);\n throw error;\n }\n\n const events = transformStreamChunk(chunk, state);\n for (const event of events) {\n yield event;\n }\n }\n\n // Build final response\n responseResolve(buildResponseFromState(state));\n } catch (error) {\n responseReject(error as Error);\n throw error;\n }\n }\n\n return {\n [Symbol.asyncIterator]() {\n return generateEvents();\n },\n response: responsePromise,\n };\n },\n };\n\n return model;\n },\n };\n}\n","import { createProvider } from '../../core/provider.ts';\nimport { createLLMHandler } from './llm.ts';\n\n/**\n * Ollama provider\n * Supports LLM modality with local Ollama models\n *\n * Ollama is a local LLM server that supports many open-source models including:\n * - Llama 3.x\n * - Mistral\n * - Mixtral\n * - Gemma\n * - Qwen\n * - DeepSeek\n * - Phi\n * - And many more\n *\n * @example\n * ```ts\n * import { llm } from 'provider-protocol';\n * import { ollama } from 'provider-protocol/ollama';\n *\n * const model = llm(ollama('llama3.2'));\n * const result = await model.generate('Hello, how are you?');\n * ```\n *\n * @example Custom server URL\n * ```ts\n * const model = llm(ollama('llama3.2'), {\n * baseUrl: 'http://my-ollama-server:11434',\n * });\n * ```\n */\nexport const ollama = createProvider({\n name: 'ollama',\n version: '1.0.0',\n modalities: {\n llm: createLLMHandler(),\n },\n});\n\n// Re-export types\nexport type { OllamaLLMParams } from './types.ts';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAkCO,SAAS,iBACd,SACA,SACe;AACf,QAAM,SAAU,QAAQ,UAAU,CAAC;AAGnC,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EACL,IAAI;AAGJ,QAAM,gBAA+B;AAAA,IACnC,OAAO;AAAA,IACP,UAAU,kBAAkB,QAAQ,UAAU,QAAQ,MAAM;AAAA,EAC9D;AAGA,MAAI,eAAe,OAAW,eAAc,aAAa;AACzD,MAAI,UAAU,OAAW,eAAc,QAAQ;AAC/C,MAAI,aAAa,OAAW,eAAc,WAAW;AACrD,MAAI,iBAAiB,OAAW,eAAc,eAAe;AAG7D,MAAI,OAAO,KAAK,aAAa,EAAE,SAAS,GAAG;AACzC,kBAAc,UAAU;AAAA,EAC1B;AAGA,MAAI,QAAQ,SAAS,QAAQ,MAAM,SAAS,GAAG;AAC7C,kBAAc,QAAQ,QAAQ,MAAM,IAAI,aAAa;AAAA,EACvD;AAGA,MAAI,QAAQ,WAAW;AACrB,kBAAc,SAAS,QAAQ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,gBACA,QAAQ;AAAA,gBACR;AAAA,gBACA;AAAA,cACF;AAEA,kBAAI,CAAC,SAAS,IAAI;AAChB,sBAAM,QAAQ,MAAM,mBAAmB,UAAU,UAAU,KAAK;AAChE,+BAAe,KAAK;AACpB,sBAAM;AAAA,cACR;AAEA,kBAAI,CAAC,SAAS,MAAM;AAClB,sBAAM,QAAQ,IAAI;AAAA,kBAChB;AAAA,kBACA;AAAA,kBACA;AAAA,kBACA;AAAA,gBACF;AACA,+BAAe,KAAK;AACpB,sBAAM;AAAA,cACR;AAGA,+BAAiB,SAAS,kBAAkB,SAAS,IAAI,GAAG;AAE1D,oBAAI,WAAW,SAAS,OAAQ,MAAkC,UAAU,UAAU;AACpF,wBAAM,QAAQ,IAAI;AAAA,oBACf,MAAkC;AAAA,oBACnC;AAAA,oBACA;AAAA,oBACA;AAAA,kBACF;AACA,iCAAe,KAAK;AACpB,wBAAM;AAAA,gBACR;AAEA,sBAAM,SAAS,qBAAqB,OAAO,KAAK;AAChD,2BAAW,SAAS,QAAQ;AAC1B,wBAAM;AAAA,gBACR;AAAA,cACF;AAGA,8BAAgB,uBAAuB,KAAK,CAAC;AAAA,YAC/C,SAAS,OAAO;AACd,6BAAe,KAAc;AAC7B,oBAAM;AAAA,YACR;AAAA,UACF;AAEA,iBAAO;AAAA,YACL,CAAC,OAAO,aAAa,IAAI;AACvB,qBAAO,eAAe;AAAA,YACxB;AAAA,YACA,UAAU;AAAA,UACZ;AAAA,QACF;AAAA,MACF;AAEA,aAAO;AAAA,IACT;AAAA,EACF;AACF;;;AC9OO,IAAM,SAAS,eAAe;AAAA,EACnC,MAAM;AAAA,EACN,SAAS;AAAA,EACT,YAAY;AAAA,IACV,KAAK,iBAAiB;AAAA,EACxB;AACF,CAAC;","names":[]}
|
package/dist/openai/index.d.ts
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import { b as Provider, M as ModelReference, a as LLMHandler } from '../provider-CUJWjgNl.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* OpenAI
|
|
5
|
-
* These are passed through to the
|
|
4
|
+
* OpenAI Chat Completions API parameters
|
|
5
|
+
* These are passed through to the /v1/chat/completions endpoint
|
|
6
6
|
*/
|
|
7
|
-
interface
|
|
8
|
-
/** Maximum number of tokens to generate */
|
|
7
|
+
interface OpenAICompletionsParams {
|
|
8
|
+
/** Maximum number of tokens to generate (legacy, prefer max_completion_tokens) */
|
|
9
9
|
max_tokens?: number;
|
|
10
|
-
/** Maximum completion tokens (preferred
|
|
10
|
+
/** Maximum completion tokens (preferred for newer models) */
|
|
11
11
|
max_completion_tokens?: number;
|
|
12
|
-
/** Maximum output tokens (Responses API) */
|
|
13
|
-
max_output_tokens?: number;
|
|
14
12
|
/** Temperature for randomness (0.0 - 2.0) */
|
|
15
13
|
temperature?: number;
|
|
16
14
|
/** Top-p (nucleus) sampling (0.0 - 1.0) */
|
|
@@ -31,39 +29,25 @@ interface OpenAILLMParams {
|
|
|
31
29
|
seed?: number;
|
|
32
30
|
/** User identifier for abuse detection */
|
|
33
31
|
user?: string;
|
|
34
|
-
/** Logit bias map
|
|
32
|
+
/** Logit bias map */
|
|
35
33
|
logit_bias?: Record<string, number>;
|
|
36
|
-
/** Verbosity control
|
|
34
|
+
/** Verbosity control */
|
|
37
35
|
verbosity?: 'low' | 'medium' | 'high';
|
|
38
36
|
/** Whether to enable parallel tool calls */
|
|
39
37
|
parallel_tool_calls?: boolean;
|
|
40
38
|
/** Reasoning effort for reasoning models */
|
|
41
39
|
reasoning_effort?: 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh';
|
|
42
|
-
/** Reasoning configuration (Responses API) */
|
|
43
|
-
reasoning?: {
|
|
44
|
-
effort?: 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh';
|
|
45
|
-
summary?: string;
|
|
46
|
-
};
|
|
47
40
|
/** Service tier */
|
|
48
41
|
service_tier?: 'auto' | 'default' | 'flex' | 'priority';
|
|
49
|
-
/** Truncation strategy (Responses API) */
|
|
50
|
-
truncation?: 'auto' | 'disabled';
|
|
51
|
-
/** Fields to include in Responses API output */
|
|
52
|
-
include?: string[];
|
|
53
|
-
/** Background processing (Responses API) */
|
|
54
|
-
background?: boolean;
|
|
55
|
-
/** Continue from a previous response (Responses API) */
|
|
56
|
-
previous_response_id?: string;
|
|
57
42
|
/** Store completion for distillation */
|
|
58
43
|
store?: boolean;
|
|
59
44
|
/** Metadata key-value pairs */
|
|
60
45
|
metadata?: Record<string, string>;
|
|
61
|
-
/** Response format for structured output
|
|
46
|
+
/** Response format for structured output */
|
|
62
47
|
response_format?: OpenAIResponseFormat;
|
|
63
48
|
/**
|
|
64
49
|
* Predicted Output configuration for faster regeneration
|
|
65
50
|
* Improves response times when large parts of the response are known ahead of time
|
|
66
|
-
* Most useful when regenerating a file with only minor changes
|
|
67
51
|
*/
|
|
68
52
|
prediction?: {
|
|
69
53
|
type: 'content';
|
|
@@ -73,7 +57,7 @@ interface OpenAILLMParams {
|
|
|
73
57
|
}>;
|
|
74
58
|
};
|
|
75
59
|
/**
|
|
76
|
-
* Stable identifier for caching similar requests
|
|
60
|
+
* Stable identifier for caching similar requests
|
|
77
61
|
* Used to optimize cache hit rates
|
|
78
62
|
*/
|
|
79
63
|
prompt_cache_key?: string;
|
|
@@ -88,6 +72,39 @@ interface OpenAILLMParams {
|
|
|
88
72
|
*/
|
|
89
73
|
safety_identifier?: string;
|
|
90
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* OpenAI Responses API parameters
|
|
77
|
+
* These are passed through to the /v1/responses endpoint
|
|
78
|
+
*/
|
|
79
|
+
interface OpenAIResponsesParams {
|
|
80
|
+
/** Maximum output tokens */
|
|
81
|
+
max_output_tokens?: number;
|
|
82
|
+
/** Temperature for randomness (0.0 - 2.0) */
|
|
83
|
+
temperature?: number;
|
|
84
|
+
/** Top-p (nucleus) sampling (0.0 - 1.0) */
|
|
85
|
+
top_p?: number;
|
|
86
|
+
/** Whether to enable parallel tool calls */
|
|
87
|
+
parallel_tool_calls?: boolean;
|
|
88
|
+
/** Reasoning configuration */
|
|
89
|
+
reasoning?: {
|
|
90
|
+
effort?: 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh';
|
|
91
|
+
summary?: string;
|
|
92
|
+
};
|
|
93
|
+
/** Service tier */
|
|
94
|
+
service_tier?: 'auto' | 'default' | 'flex' | 'priority';
|
|
95
|
+
/** Truncation strategy */
|
|
96
|
+
truncation?: 'auto' | 'disabled';
|
|
97
|
+
/** Fields to include in output */
|
|
98
|
+
include?: string[];
|
|
99
|
+
/** Background processing */
|
|
100
|
+
background?: boolean;
|
|
101
|
+
/** Continue from a previous response */
|
|
102
|
+
previous_response_id?: string;
|
|
103
|
+
/** Store response for continuation */
|
|
104
|
+
store?: boolean;
|
|
105
|
+
/** Metadata key-value pairs */
|
|
106
|
+
metadata?: Record<string, string>;
|
|
107
|
+
}
|
|
91
108
|
/**
|
|
92
109
|
* API mode for OpenAI provider
|
|
93
110
|
*/
|
|
@@ -130,6 +147,8 @@ type OpenAIResponseFormat = {
|
|
|
130
147
|
};
|
|
131
148
|
};
|
|
132
149
|
|
|
150
|
+
/** Union type for modalities interface */
|
|
151
|
+
type OpenAILLMParamsUnion = OpenAICompletionsParams | OpenAIResponsesParams;
|
|
133
152
|
/**
|
|
134
153
|
* OpenAI provider options
|
|
135
154
|
*/
|
|
@@ -169,7 +188,7 @@ interface OpenAIProvider extends Provider<OpenAIProviderOptions> {
|
|
|
169
188
|
readonly version: string;
|
|
170
189
|
/** Supported modalities */
|
|
171
190
|
readonly modalities: {
|
|
172
|
-
llm: LLMHandler<
|
|
191
|
+
llm: LLMHandler<OpenAILLMParamsUnion>;
|
|
173
192
|
};
|
|
174
193
|
}
|
|
175
194
|
/**
|
|
@@ -201,4 +220,4 @@ interface OpenAIProvider extends Provider<OpenAIProviderOptions> {
|
|
|
201
220
|
*/
|
|
202
221
|
declare const openai: OpenAIProvider;
|
|
203
222
|
|
|
204
|
-
export { type OpenAIAPIMode, type
|
|
223
|
+
export { type OpenAIAPIMode, type OpenAICompletionsParams, type OpenAIConfig, type OpenAIModelOptions, type OpenAIModelReference, type OpenAIResponsesParams, openai };
|
package/dist/openai/index.js
CHANGED
|
@@ -19,79 +19,12 @@ import {
|
|
|
19
19
|
function transformRequest(request, modelId) {
|
|
20
20
|
const params = request.params ?? {};
|
|
21
21
|
const openaiRequest = {
|
|
22
|
+
...params,
|
|
22
23
|
model: modelId,
|
|
23
24
|
messages: transformMessages(request.messages, request.system)
|
|
24
25
|
};
|
|
25
|
-
if (params.temperature !== void 0) {
|
|
26
|
-
openaiRequest.temperature = params.temperature;
|
|
27
|
-
}
|
|
28
|
-
if (params.top_p !== void 0) {
|
|
29
|
-
openaiRequest.top_p = params.top_p;
|
|
30
|
-
}
|
|
31
|
-
if (params.max_completion_tokens !== void 0) {
|
|
32
|
-
openaiRequest.max_completion_tokens = params.max_completion_tokens;
|
|
33
|
-
} else if (params.max_tokens !== void 0) {
|
|
34
|
-
openaiRequest.max_tokens = params.max_tokens;
|
|
35
|
-
}
|
|
36
|
-
if (params.frequency_penalty !== void 0) {
|
|
37
|
-
openaiRequest.frequency_penalty = params.frequency_penalty;
|
|
38
|
-
}
|
|
39
|
-
if (params.presence_penalty !== void 0) {
|
|
40
|
-
openaiRequest.presence_penalty = params.presence_penalty;
|
|
41
|
-
}
|
|
42
|
-
if (params.stop !== void 0) {
|
|
43
|
-
openaiRequest.stop = params.stop;
|
|
44
|
-
}
|
|
45
|
-
if (params.n !== void 0) {
|
|
46
|
-
openaiRequest.n = params.n;
|
|
47
|
-
}
|
|
48
|
-
if (params.logprobs !== void 0) {
|
|
49
|
-
openaiRequest.logprobs = params.logprobs;
|
|
50
|
-
}
|
|
51
|
-
if (params.top_logprobs !== void 0) {
|
|
52
|
-
openaiRequest.top_logprobs = params.top_logprobs;
|
|
53
|
-
}
|
|
54
|
-
if (params.seed !== void 0) {
|
|
55
|
-
openaiRequest.seed = params.seed;
|
|
56
|
-
}
|
|
57
|
-
if (params.user !== void 0) {
|
|
58
|
-
openaiRequest.user = params.user;
|
|
59
|
-
}
|
|
60
|
-
if (params.logit_bias !== void 0) {
|
|
61
|
-
openaiRequest.logit_bias = params.logit_bias;
|
|
62
|
-
}
|
|
63
|
-
if (params.reasoning_effort !== void 0) {
|
|
64
|
-
openaiRequest.reasoning_effort = params.reasoning_effort;
|
|
65
|
-
}
|
|
66
|
-
if (params.verbosity !== void 0) {
|
|
67
|
-
openaiRequest.verbosity = params.verbosity;
|
|
68
|
-
}
|
|
69
|
-
if (params.service_tier !== void 0) {
|
|
70
|
-
openaiRequest.service_tier = params.service_tier;
|
|
71
|
-
}
|
|
72
|
-
if (params.store !== void 0) {
|
|
73
|
-
openaiRequest.store = params.store;
|
|
74
|
-
}
|
|
75
|
-
if (params.metadata !== void 0) {
|
|
76
|
-
openaiRequest.metadata = params.metadata;
|
|
77
|
-
}
|
|
78
|
-
if (params.prediction !== void 0) {
|
|
79
|
-
openaiRequest.prediction = params.prediction;
|
|
80
|
-
}
|
|
81
|
-
if (params.prompt_cache_key !== void 0) {
|
|
82
|
-
openaiRequest.prompt_cache_key = params.prompt_cache_key;
|
|
83
|
-
}
|
|
84
|
-
if (params.prompt_cache_retention !== void 0) {
|
|
85
|
-
openaiRequest.prompt_cache_retention = params.prompt_cache_retention;
|
|
86
|
-
}
|
|
87
|
-
if (params.safety_identifier !== void 0) {
|
|
88
|
-
openaiRequest.safety_identifier = params.safety_identifier;
|
|
89
|
-
}
|
|
90
26
|
if (request.tools && request.tools.length > 0) {
|
|
91
27
|
openaiRequest.tools = request.tools.map(transformTool);
|
|
92
|
-
if (params.parallel_tool_calls !== void 0) {
|
|
93
|
-
openaiRequest.parallel_tool_calls = params.parallel_tool_calls;
|
|
94
|
-
}
|
|
95
28
|
}
|
|
96
29
|
if (request.structure) {
|
|
97
30
|
const schema = {
|
|
@@ -112,8 +45,6 @@ function transformRequest(request, modelId) {
|
|
|
112
45
|
strict: true
|
|
113
46
|
}
|
|
114
47
|
};
|
|
115
|
-
} else if (params.response_format !== void 0) {
|
|
116
|
-
openaiRequest.response_format = params.response_format;
|
|
117
48
|
}
|
|
118
49
|
return openaiRequest;
|
|
119
50
|
}
|
|
@@ -619,57 +550,12 @@ function createCompletionsLLMHandler() {
|
|
|
619
550
|
function transformRequest2(request, modelId) {
|
|
620
551
|
const params = request.params ?? {};
|
|
621
552
|
const openaiRequest = {
|
|
553
|
+
...params,
|
|
622
554
|
model: modelId,
|
|
623
555
|
input: transformInputItems(request.messages, request.system)
|
|
624
556
|
};
|
|
625
|
-
if (params.temperature !== void 0) {
|
|
626
|
-
openaiRequest.temperature = params.temperature;
|
|
627
|
-
}
|
|
628
|
-
if (params.top_p !== void 0) {
|
|
629
|
-
openaiRequest.top_p = params.top_p;
|
|
630
|
-
}
|
|
631
|
-
if (params.max_output_tokens !== void 0) {
|
|
632
|
-
openaiRequest.max_output_tokens = params.max_output_tokens;
|
|
633
|
-
} else if (params.max_completion_tokens !== void 0) {
|
|
634
|
-
openaiRequest.max_output_tokens = params.max_completion_tokens;
|
|
635
|
-
} else if (params.max_tokens !== void 0) {
|
|
636
|
-
openaiRequest.max_output_tokens = params.max_tokens;
|
|
637
|
-
}
|
|
638
|
-
if (params.service_tier !== void 0) {
|
|
639
|
-
openaiRequest.service_tier = params.service_tier;
|
|
640
|
-
}
|
|
641
|
-
if (params.store !== void 0) {
|
|
642
|
-
openaiRequest.store = params.store;
|
|
643
|
-
}
|
|
644
|
-
if (params.metadata !== void 0) {
|
|
645
|
-
openaiRequest.metadata = params.metadata;
|
|
646
|
-
}
|
|
647
|
-
if (params.truncation !== void 0) {
|
|
648
|
-
openaiRequest.truncation = params.truncation;
|
|
649
|
-
}
|
|
650
|
-
if (params.include !== void 0) {
|
|
651
|
-
openaiRequest.include = params.include;
|
|
652
|
-
}
|
|
653
|
-
if (params.background !== void 0) {
|
|
654
|
-
openaiRequest.background = params.background;
|
|
655
|
-
}
|
|
656
|
-
if (params.previous_response_id !== void 0) {
|
|
657
|
-
openaiRequest.previous_response_id = params.previous_response_id;
|
|
658
|
-
}
|
|
659
|
-
if (params.reasoning !== void 0) {
|
|
660
|
-
openaiRequest.reasoning = { ...params.reasoning };
|
|
661
|
-
}
|
|
662
|
-
if (params.reasoning_effort !== void 0) {
|
|
663
|
-
openaiRequest.reasoning = {
|
|
664
|
-
...openaiRequest.reasoning ?? {},
|
|
665
|
-
effort: params.reasoning_effort
|
|
666
|
-
};
|
|
667
|
-
}
|
|
668
557
|
if (request.tools && request.tools.length > 0) {
|
|
669
558
|
openaiRequest.tools = request.tools.map(transformTool2);
|
|
670
|
-
if (params.parallel_tool_calls !== void 0) {
|
|
671
|
-
openaiRequest.parallel_tool_calls = params.parallel_tool_calls;
|
|
672
|
-
}
|
|
673
559
|
}
|
|
674
560
|
if (request.structure) {
|
|
675
561
|
const schema = {
|