Skip to content

OllamaFrontendAdapter

Defined in: adapters/ollama.ts:135

Frontend adapter interface.

Frontend adapters represent how developers want to interact with AI APIs. They normalize provider-specific request formats into universal IR and denormalize IR responses back to provider-specific formats.

new OllamaFrontendAdapter(): OllamaFrontendAdapter

OllamaFrontendAdapter

readonly metadata: AdapterMetadata

Defined in: adapters/ollama.ts:136

Adapter metadata for identification and capabilities.

FrontendAdapter.metadata

fromIR(response): Promise<OllamaResponse>

Defined in: adapters/ollama.ts:213

Convert Universal IR response back to Ollama API format.

This method transforms the standardized IR response into the format expected by Ollama’s API. It handles message conversion, formats the timestamp as ISO string, and maps usage statistics to Ollama’s format (prompt_eval_count and eval_count instead of token counts).

IRChatResponse

Universal IR chat response

Promise<OllamaResponse>

Promise resolving to Ollama API response

const adapter = new OllamaFrontendAdapter();
const ollamaResponse = await adapter.fromIR(irResponse);
console.log(ollamaResponse.message.content);

FrontendAdapter.fromIR


fromIRStream(stream, _options?): AsyncGenerator<string>

Defined in: adapters/ollama.ts:247

Convert Universal IR stream to Ollama streaming format.

This async generator method transforms a stream of IR chunks into Ollama-formatted responses. It yields newline-delimited JSON objects (not SSE format) with each chunk containing a message and done flag, emitting done: true when the stream completes.

AsyncGenerator<IRStreamChunk>

Universal IR chat stream

StreamConversionOptions

Optional stream conversion options (currently unused)

AsyncGenerator<string>

Newline-delimited JSON strings

const adapter = new OllamaFrontendAdapter();
for await (const jsonLine of adapter.fromIRStream(irStream)) {
console.log(jsonLine); // '{"message":{"content":"text"},"done":false}\n'
}

FrontendAdapter.fromIRStream


toIR(request): Promise<IRChatRequest>

Defined in: adapters/ollama.ts:170

Convert Ollama API request to Universal IR format.

This method transforms an Ollama-formatted request into the standardized Intermediate Representation (IR) format. It handles Ollama’s unique structure where parameters are nested in an options object, and maps Ollama-specific field names (e.g., num_predict → maxTokens).

OllamaRequest

Ollama API request

Promise<IRChatRequest>

Promise resolving to IR chat request

const adapter = new OllamaFrontendAdapter();
const irRequest = await adapter.toIR({
model: 'llama2',
messages: [{ role: 'user', content: 'Hello!' }],
options: { temperature: 0.7, num_predict: 100 }
});

FrontendAdapter.toIR