Expand description
§ollama-vision
Robust Ollama vision model toolkit for image tagging and captioning.
§Features
- Image tagging with a 7-strategy response parser that handles every
common LLM output format (JSON arrays, code blocks,
<think>tags, JSON objects, numbered lists, comma-separated text) - Image captioning with automatic
<think>block stripping - Works with any Ollama vision model (llava, minicpm-v, llama3.2-vision, etc.)
- Base64 API for in-memory images (no file I/O required)
§Quick Start
use ollama_vision::{OllamaVisionConfig, TagOptions, CaptionOptions};
use std::path::Path;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = OllamaVisionConfig::with_model("llava");
let client = reqwest::Client::new();
// Tag an image
let tags = ollama_vision::tag_image(
&client, &config,
Path::new("photo.jpg"),
&TagOptions::default(),
).await?;
println!("Tags: {:?}", tags);
// Caption an image
let caption = ollama_vision::caption_image(
&client, &config,
Path::new("photo.jpg"),
&CaptionOptions::default(),
).await?;
println!("Caption: {}", caption);
Ok(())
}§Parsing Robustness
The tag parser handles all common LLM response formats:
use ollama_vision::parse_tags;
// Pure JSON array
assert!(parse_tags(r#"["portrait", "fantasy"]"#).is_ok());
// With <think> blocks from reasoning models
assert!(parse_tags(r#"<think>analyzing...</think>["portrait"]"#).is_ok());
// Markdown code blocks
assert!(parse_tags("```json\n[\"portrait\"]\n```").is_ok());
// JSON objects with "tags" key
assert!(parse_tags(r#"{"tags": ["portrait"]}"#).is_ok());
// Comma-separated fallback
assert!(parse_tags("portrait, fantasy, dark").is_ok());Re-exports§
pub use captioner::caption_image;pub use captioner::caption_image_base64;pub use captioner::CaptionError;pub use tagger::tag_image;pub use tagger::tag_image_base64;pub use tagger::TagError;pub use types::CaptionOptions;pub use types::GenerateOptions;pub use types::OllamaVisionConfig;pub use types::TagOptions;
Modules§
Enums§
- Parse
Error - Errors returned by output parsers.
Functions§
- parse_
tags - Parse an LLM response into a cleaned list of strings.
- strip_
think_ tags - Strip all
<think>...</think>and<thinking>...</thinking>blocks from text.