Skip to main content
Generate text completions using locally hosted Ollama models. Unlike chat completion, this function is designed for single-turn text generation with optional system prompts, images, and custom templates.

Samples

Generate a completion

Get a text completion from a local model:

Use a system prompt

Set a system prompt to control the model’s behavior:

Add context for continuation

Continue a previous generation using context:

Generate with images

Analyze images with vision-capable models:

Configure model options

Customize the generation parameters:

Arguments

Returns

JSONB: The complete API response including:
  • model: Model used for generation
  • response: The generated text
  • context: Context array for continuation
  • created_at: Generation timestamp
  • done: Whether generation is complete
  • total_duration: Total time taken
  • prompt_eval_count: Number of tokens in prompt
  • eval_count: Number of tokens generated