The primary text prompt.
Optionaloptions: {Optionalcache?: booleanCache the model response before user processing, not the callback output. Defaults to true.
OptionalcontextWindow?: numberOverride the model's context window size.
Optionalfiles?: { path: string; type: "image" | "text" }[]Files to send alongside the prompt. Only "image" and "text" types are supported (local paths only; no GCS, audio, video, or PDF). Text files are sent as separate user messages after the prompt; images are sent as attachments to the prompt message.
Optionalmodel?: stringModel name; defaults to AI_MODEL env var.
Optionalollama?: unknownCustom Ollama instance targeting a specific host.
OptionalollamaParameters?: Partial<ChatRequest>Extra params merged into client.chat.
OptionalprocessResponse?: (response: unknown) => TResponse | Promise<TResponse>Transform or validate the model response on every call, including cache hits. The callback output is never cached; rejected cached responses are removed.
OptionalschemaJson?: unknownJSON schema for structured output.
OptionalsystemPrompt?: stringOptional system prompt.
Optionaltemperature?: numberSampling temperature (default 0).
OptionalthinkingLevel?: boolean | "low" | "medium" | "high"Enables reasoning. Pass true for models that only support on/off, or "low", "medium", or "high" for granular control.
// Assumes AI_MODEL is set in environment variables.
const result = await askOllama("What is the capital of France?");
console.log(result.response); // "Paris"
// Use a custom Ollama instance.
import { Ollama } from "ollama";
const client = new Ollama({ host: "http://127.0.0.1:11434" });
const result = await askOllama("What is the capital of France?", { ollama: client });
// Analyse a local image.
const result = await askOllama("Describe this image.", {
files: [{ path: "./photo.jpg", type: "image" }],
});
// Structured JSON output.
import * as z from "zod";
const schema = z.toJSONSchema(z.object({ country: z.string(), capital: z.string() }));
const result = await askOllama(
"What is the capital of France?",
{ schemaJson: schema },
);
Interacts with a local Ollama model to perform a wide range of tasks.
Ollama must be running on the machine. Set the
AI_MODELenvironment variable or passmodeldirectly.Pass a custom
Ollamainstance via theollamaoption to target a non-default host.File handling: pass local files via
files: [{ path, type }]. Only"image"and"text"types are supported for now.Caching: model calls can be slow and costly, so original responses are cached in
.journalism-cacheby default.processResponsereruns on every call, including cache hits, and its output is never cached. Keep it lightweight and optimize heavier processing, especially for large workloads. Setcache: falseto disable caching.Temperature defaults to 0 for deterministic responses.