@molecule/api-ocr-llm
Provider bond · ocr · API (Node) · v1.1.0 · Apache-2.0
Language-model OCR provider for molecule.dev — extracts text from images through any vision-capable @molecule/api-ai model
npm install @molecule/api-ocr-llmnpm · Source on GitHub · Implements @molecule/api-ocr
How it works
@molecule/api-ocr-llm is a provider bond on the API (Node) side: it implements the ocr core interface (@molecule/api-ocr) with a concrete vendor or library behind it.
Your code calls the core; you wire this provider once at startup. Swapping vendors later is one line in that wiring, not a rewrite.
Works with: @molecule/api-ai, @molecule/api-ocr
Reference
Language-model OCR provider for molecule.dev — extracts text from images through any vision-capable @molecule/api-ai model
Type
provider
Installation
npm install @molecule/api-ocr-llm @molecule/api-ai @molecule/api-ocr
API
Interfaces
LlmOcrConfig
Options for createProvider. ai falls back to the bonded ai
provider; every other field has a prompt-level default.
interface LlmOcrConfig {
/**
* The AI provider to recognize with. Defaults to the provider bonded as
* `ai` (`@molecule/api-ai` `requireProvider()`), which must support image
* input (check the model catalog's `supportsVision`).
*/
ai?: AIProvider
/** The model id to pass to the provider. Omit to use the provider's default. */
model?: string
/** Default language hint when a `recognize` call passes none. */
language?: string
/**
* Extra instructions, e.g. "This is a receipt; transcribe every line item".
* Appended to the system prompt.
*/
instructions?: string
/** Sampling temperature. Defaults to 0 — transcription is not a creative task. */
temperature?: number
/** Output token ceiling. Defaults to a length derived from the image size. */
maxOutputTokens?: number
}
Functions
createProvider(config)
Creates a language-model OCR provider.
function createProvider(config?: LlmOcrConfig): OcrProvider
config— Which AI provider/model to use and how to prompt it.
Returns: An OcrProvider backed by a vision language model.
systemPrompt(instructions)
The system prompt for one recognition pass.
function systemPrompt(instructions?: string): string
instructions— Extra caller instructions, appended last.
Returns: The system prompt.
userPrompt(language)
The text part of the user message (the image block is sent alongside it).
function userPrompt(language?: string): string
language— Optional language hint.
Returns: The user-side instruction.
Constants
provider
The provider implementation.
const provider: OcrProvider
Core Interface
Implements @molecule/api-ocr interface.
Bond Wiring
Setup function to register this provider with the core interface:
import { setProvider } from '@molecule/api-ocr'
import { provider } from '@molecule/api-ocr-llm'
export function setupOcrLlm(): void {
setProvider(provider)
}
Injection Notes
Requirements
Peer dependencies:
@molecule/api-ai>=1.0.0@molecule/api-ocr>=1.0.0
Runtime Dependencies
@molecule/api-ai@molecule/api-ocr