Extracts base64-encoded images from OpenAI-format message JSON, returning raw bytes and sanitized text markers. Reuse when preprocessing multimodal LLM inputs for local inference.
// Source: https://github.com/aaif-goose/goose | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
// Provided via justclaw.it.com; keep this notice with the code.
use base64::prelude::*;
use serde_json::Value;
use goose_provider_types::conversation::message::{Message, MessageContent};
use goose_provider_types::errors::ProviderError;
#[derive(Debug)]
pub struct ExtractedImage {
pub bytes: Vec<u8>,
}
#[derive(Debug)]
#[allow(dead_code)]
pub struct MultimodalMessages {
pub messages_json: String,
pub images: Vec<ExtractedImage>,
}
/// Walk the OpenAI-format messages JSON array. For each content part with
/// `type: "image_url"`, decode the base64 data URL, store the raw bytes,
/// and replace the part with `{"type": "text", "text": "<m
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key