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.
Implements
Section titled “Implements”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new OllamaFrontendAdapter():
OllamaFrontendAdapter
Returns
Section titled “Returns”OllamaFrontendAdapter
Properties
Section titled “Properties”metadata
Section titled “metadata”
readonlymetadata:AdapterMetadata
Defined in: adapters/ollama.ts:136
Adapter metadata for identification and capabilities.
Implementation of
Section titled “Implementation of”Methods
Section titled “Methods”fromIR()
Section titled “fromIR()”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).
Parameters
Section titled “Parameters”response
Section titled “response”Universal IR chat response
Returns
Section titled “Returns”Promise<OllamaResponse>
Promise resolving to Ollama API response
Example
Section titled “Example”const adapter = new OllamaFrontendAdapter();const ollamaResponse = await adapter.fromIR(irResponse);console.log(ollamaResponse.message.content);Implementation of
Section titled “Implementation of”fromIRStream()
Section titled “fromIRStream()”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.
Parameters
Section titled “Parameters”stream
Section titled “stream”AsyncGenerator<IRStreamChunk>
Universal IR chat stream
_options?
Section titled “_options?”Optional stream conversion options (currently unused)
Returns
Section titled “Returns”AsyncGenerator<string>
Yields
Section titled “Yields”Newline-delimited JSON strings
Example
Section titled “Example”const adapter = new OllamaFrontendAdapter();for await (const jsonLine of adapter.fromIRStream(irStream)) { console.log(jsonLine); // '{"message":{"content":"text"},"done":false}\n'}Implementation of
Section titled “Implementation of”toIR()
Section titled “toIR()”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).
Parameters
Section titled “Parameters”request
Section titled “request”Ollama API request
Returns
Section titled “Returns”Promise<IRChatRequest>
Promise resolving to IR chat request
Example
Section titled “Example”const adapter = new OllamaFrontendAdapter();const irRequest = await adapter.toIR({ model: 'llama2', messages: [{ role: 'user', content: 'Hello!' }], options: { temperature: 0.7, num_predict: 100 }});