cohere-melody 0.15.0


pip install cohere-melody

  Latest version

Released: Sep 19, 2026


Meta
Requires Python: >=3.10

Classifiers

Programming Language
  • Rust
  • Python :: Implementation :: CPython
  • Python :: Implementation :: PyPy

Development Status
  • 5 - Production/Stable

Intended Audience
  • Developers

Topic
  • Software Development :: Libraries

melody

Templating rendering and generation parsing for Cohere models.

Dev Setup

  1. Install Rust from rustup.rs.
  2. Install rust-analyzer for IDE support.
  3. make rust-test && make rust-lint to ensure everything is working.

Examples

The examples/ directory contains several example programs demonstrating how to use the Melody parsing library in Rust. You can run them using:

cargo run --example basic

Usage

Parsing

use cohere_melody::parsing::Filter;
use cohere_melody::*;

// Create a filter with options
let options = parsing::FilterOptions::new().cmd3();

let mut filter = parsing::new_filter(options);

// Simulate text
let citation_text = "Hello <co: 1>world</co: 1>!";

// Write text — returns an aggregated result
let result = filter.write_decoded(citation_text);

if let Some(text) = &result.content {
    println!("  Content: {text}");
}
for citation in &result.citations {
    println!(
        "    Citation: {} (indices {}-{})",
        citation.text, citation.start_index, citation.end_index
    );
}

// Flush remaining tokens
let final_result = filter.flush_partials();

Parsing vision generations (unary)

Parse/OCR models emit markdown interleaved with [visual_element]…[/visual_element] blocks. Use the unary helper (full generation text, not streaming):

use cohere_melody::parsing::parse_vision_generation;

let parsed = parse_vision_generation(model_output)?;
for segment in &parsed.segments {
    match segment {
        cohere_melody::parsing::VisionSegment::Text { text } => { /* markdown */ }
        cohere_melody::parsing::VisionSegment::Element { element } => {
            // element.type, bbox, description, html, ...
        }
    }
}

Go: gobindings.ParseVisionGeneration(text). Python: cohere_melody.parse_vision_generation(text).

Templating

use cohere_melody::parsing::Filter;
use cohere_melody::*;

// Assemble inputs into the template (e.g. conversation history)
let options = templating::RenderCmd4Options {
    messages: vec![
        templating::types::Message {
            role: templating::types::Role::System,
            content: vec![templating::types::Content {
                content_type: templating::types::ContentType::Text,
                text: Some("You are a helpful assistant.".to_string()),
                thinking: None,
                image: None,
                document: None,
            }],
            tool_calls: vec![],
            tool_call_id: None,
            citations: vec![],
        },
        templating::types::Message {
            role: templating::types::Role::User,
            content: vec![templating::types::Content {
                content_type: templating::types::ContentType::Text,
                text: Some("Hello Command!.".to_string()),
                thinking: None,
                image: None,
                document: None,
            }],
            tool_calls: vec![],
            tool_call_id: None,
            citations: vec![],
        },
    ],
    ..Default::default()
};

// Render prompt
let prompt = templating::render_cmd4(&options).unwrap();

Releasing

Bump the version in Cargo.toml and push to main. The CI will automatically create a GitHub release, build wheels for all platforms, and publish to PyPI.

Building Python Bindings

Prerequisites (from pyo3)

  1. Recommended install uv
  2. From root directory, run:
    make python-bindings
    
  3. Test the bindings:
    cd rust
    uv run python -c "import cohere_melody;"
    

Debugging

You may run into issues calling the Rust static library from other languages (e.g. Golang via CGO). One effective way to debug these issues is to:

  1. Build the library in debug mode. You can do this by adding these lines to the Cargo.toml file:
[profile.release]
debug = true

and then building the library normally: make rust-build-with-tokenizers.

  1. Create a binary to debug. In Golang, I create a binary from a test:
go test -count=1 ./gobindings/... -c
  1. Use gdb (brew install gdb on macOS).
gdb ./gobindings.test
break melody_render_cmd3
run
  1. When it hits the breakpoint, you can step through the Rust code to see where things might be going wrong.

Wheel compatibility matrix

Platform CPython 3.10 CPython 3.11 CPython 3.12 CPython 3.13 CPython 3.14 CPython (additional flags: t) 3.14 PyPy 3.11 (pp73)
macosx_10_12_x86_64
macosx_11_0_arm64
manylinux1_i686
manylinux2014_aarch64
manylinux2014_armv7l
manylinux2014_ppc64le
manylinux2014_s390x
manylinux2014_x86_64
manylinux_2_17_aarch64
manylinux_2_17_armv7l
manylinux_2_17_ppc64le
manylinux_2_17_s390x
manylinux_2_17_x86_64
manylinux_2_5_i686
musllinux_1_2_aarch64
musllinux_1_2_armv7l
musllinux_1_2_i686
musllinux_1_2_x86_64
win32
win_amd64

Files in release

cohere_melody-0.15.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.4MiB)
cohere_melody-0.15.0-cp310-cp310-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (2.3MiB)
cohere_melody-0.15.0-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (2.7MiB)
cohere_melody-0.15.0-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl (2.5MiB)
cohere_melody-0.15.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.4MiB)
cohere_melody-0.15.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.whl (2.6MiB)
cohere_melody-0.15.0-cp310-cp310-musllinux_1_2_aarch64.whl (2.6MiB)
cohere_melody-0.15.0-cp310-cp310-musllinux_1_2_armv7l.whl (2.6MiB)
cohere_melody-0.15.0-cp310-cp310-musllinux_1_2_i686.whl (2.7MiB)
cohere_melody-0.15.0-cp310-cp310-musllinux_1_2_x86_64.whl (2.7MiB)
cohere_melody-0.15.0-cp310-cp310-win_amd64.whl (2.0MiB)
cohere_melody-0.15.0-cp311-cp311-macosx_10_12_x86_64.whl (2.2MiB)
cohere_melody-0.15.0-cp311-cp311-macosx_11_0_arm64.whl (2.1MiB)
cohere_melody-0.15.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.4MiB)
cohere_melody-0.15.0-cp311-cp311-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (2.3MiB)
cohere_melody-0.15.0-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (2.7MiB)
cohere_melody-0.15.0-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl (2.5MiB)
cohere_melody-0.15.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.4MiB)
cohere_melody-0.15.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.whl (2.6MiB)
cohere_melody-0.15.0-cp311-cp311-musllinux_1_2_aarch64.whl (2.6MiB)
cohere_melody-0.15.0-cp311-cp311-musllinux_1_2_armv7l.whl (2.6MiB)
cohere_melody-0.15.0-cp311-cp311-musllinux_1_2_i686.whl (2.7MiB)
cohere_melody-0.15.0-cp311-cp311-musllinux_1_2_x86_64.whl (2.7MiB)
cohere_melody-0.15.0-cp311-cp311-win_amd64.whl (2.0MiB)
cohere_melody-0.15.0-cp312-cp312-macosx_10_12_x86_64.whl (2.2MiB)
cohere_melody-0.15.0-cp312-cp312-macosx_11_0_arm64.whl (2.1MiB)
cohere_melody-0.15.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.4MiB)
cohere_melody-0.15.0-cp312-cp312-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (2.3MiB)
cohere_melody-0.15.0-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (2.7MiB)
cohere_melody-0.15.0-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl (2.5MiB)
cohere_melody-0.15.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.4MiB)
cohere_melody-0.15.0-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.whl (2.6MiB)
cohere_melody-0.15.0-cp312-cp312-musllinux_1_2_aarch64.whl (2.6MiB)
cohere_melody-0.15.0-cp312-cp312-musllinux_1_2_armv7l.whl (2.6MiB)
cohere_melody-0.15.0-cp312-cp312-musllinux_1_2_i686.whl (2.7MiB)
cohere_melody-0.15.0-cp312-cp312-musllinux_1_2_x86_64.whl (2.7MiB)
cohere_melody-0.15.0-cp312-cp312-win_amd64.whl (2.0MiB)
cohere_melody-0.15.0-cp313-cp313-macosx_10_12_x86_64.whl (2.2MiB)
cohere_melody-0.15.0-cp313-cp313-macosx_11_0_arm64.whl (2.1MiB)
cohere_melody-0.15.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.4MiB)
cohere_melody-0.15.0-cp313-cp313-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (2.3MiB)
cohere_melody-0.15.0-cp313-cp313-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (2.7MiB)
cohere_melody-0.15.0-cp313-cp313-manylinux_2_17_s390x.manylinux2014_s390x.whl (2.5MiB)
cohere_melody-0.15.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.4MiB)
cohere_melody-0.15.0-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.whl (2.6MiB)
cohere_melody-0.15.0-cp313-cp313-musllinux_1_2_aarch64.whl (2.6MiB)
cohere_melody-0.15.0-cp313-cp313-musllinux_1_2_armv7l.whl (2.6MiB)
cohere_melody-0.15.0-cp313-cp313-musllinux_1_2_i686.whl (2.7MiB)
cohere_melody-0.15.0-cp313-cp313-musllinux_1_2_x86_64.whl (2.7MiB)
cohere_melody-0.15.0-cp313-cp313-win_amd64.whl (2.0MiB)
cohere_melody-0.15.0-cp314-cp314-macosx_10_12_x86_64.whl (2.2MiB)
cohere_melody-0.15.0-cp314-cp314-macosx_11_0_arm64.whl (2.1MiB)
cohere_melody-0.15.0-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.4MiB)
cohere_melody-0.15.0-cp314-cp314-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (2.3MiB)
cohere_melody-0.15.0-cp314-cp314-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (2.7MiB)
cohere_melody-0.15.0-cp314-cp314-manylinux_2_17_s390x.manylinux2014_s390x.whl (2.5MiB)
cohere_melody-0.15.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.4MiB)
cohere_melody-0.15.0-cp314-cp314-manylinux_2_5_i686.manylinux1_i686.whl (2.6MiB)
cohere_melody-0.15.0-cp314-cp314-musllinux_1_2_aarch64.whl (2.6MiB)
cohere_melody-0.15.0-cp314-cp314-musllinux_1_2_armv7l.whl (2.6MiB)
cohere_melody-0.15.0-cp314-cp314-musllinux_1_2_i686.whl (2.7MiB)
cohere_melody-0.15.0-cp314-cp314-musllinux_1_2_x86_64.whl (2.7MiB)
cohere_melody-0.15.0-cp314-cp314-win32.whl (1.8MiB)
cohere_melody-0.15.0-cp314-cp314-win_amd64.whl (2.0MiB)
cohere_melody-0.15.0-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.4MiB)
cohere_melody-0.15.0-cp314-cp314t-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (2.3MiB)
cohere_melody-0.15.0-cp314-cp314t-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (2.7MiB)
cohere_melody-0.15.0-cp314-cp314t-manylinux_2_17_s390x.manylinux2014_s390x.whl (2.5MiB)
cohere_melody-0.15.0-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.4MiB)
cohere_melody-0.15.0-cp314-cp314t-manylinux_2_5_i686.manylinux1_i686.whl (2.6MiB)
cohere_melody-0.15.0-cp314-cp314t-musllinux_1_2_aarch64.whl (2.6MiB)
cohere_melody-0.15.0-cp314-cp314t-musllinux_1_2_armv7l.whl (2.6MiB)
cohere_melody-0.15.0-cp314-cp314t-musllinux_1_2_i686.whl (2.7MiB)
cohere_melody-0.15.0-cp314-cp314t-musllinux_1_2_x86_64.whl (2.7MiB)
cohere_melody-0.15.0-pp311-pypy311_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.4MiB)
cohere_melody-0.15.0-pp311-pypy311_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (2.3MiB)
cohere_melody-0.15.0-pp311-pypy311_pp73-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (2.7MiB)
cohere_melody-0.15.0-pp311-pypy311_pp73-manylinux_2_17_s390x.manylinux2014_s390x.whl (2.5MiB)
cohere_melody-0.15.0-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.4MiB)
cohere_melody-0.15.0-pp311-pypy311_pp73-manylinux_2_5_i686.manylinux1_i686.whl (2.6MiB)
cohere_melody-0.15.0-pp311-pypy311_pp73-musllinux_1_2_aarch64.whl (2.6MiB)
cohere_melody-0.15.0-pp311-pypy311_pp73-musllinux_1_2_armv7l.whl (2.6MiB)
cohere_melody-0.15.0-pp311-pypy311_pp73-musllinux_1_2_i686.whl (2.7MiB)
cohere_melody-0.15.0-pp311-pypy311_pp73-musllinux_1_2_x86_64.whl (2.7MiB)
cohere_melody-0.15.0.tar.gz (9.2MiB)
No dependencies