Registry / ai-ml / cohere-melody

cohere-melody

JSON →
library0.9.0pypypi✓ verified 81d ago

Templating rendering and generation parsing for Cohere models, version 0.9.0. This library provides tools to manage prompt templates and parse model outputs, enabling structured interactions with Cohere's generative models. It is actively developed with a focus on ease-of-use for prompt engineering.

pip install cohere-melody
INSTALL
IMPORT
SIG · COHERE-MELODY
C
cohere-melody
ai-mlpythonv0.9.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

cohere_melody
from cohere_melody import cohere_melody
from melody import CohereMelody
PyFilter
from cohere_melody import PyFilter
render_cmd3
from cohere_melody import render_cmd3

Basic usage: initialize Melody with API key, render a prompt template, and parse a model response into structured data.

from melody import CohereMelody import os cohere_api_key = os.environ.get('COHERE_API_KEY', 'your-api-key') melody = CohereMelody(api_key=cohere_api_key) # Render a template with variables template = """ Generate a short story about {{topic}}. """ rendered = melody.render(template, topic="a brave knight") print("Rendered prompt:", rendered) # Parse generation output (example: extract key-value pairs) response = "The hero's name is Sir Galahad. His quest is to find the Holy Grail." parsed = melody.parse(response, schema={"hero_name": "The hero's name is {{value}}.", "quest": "His quest is to {{value}}."}) print("Parsed output:", parsed)
Debug
Known issues
gotchaThe `parse` method requires an exact string match for schema patterns; whitespace mismatches cause failures.
fix
Ensure schema strings exactly match the format of the generation output, including punctuation and spacing.
affects: >=0.9.0
deprecatedThe `Template` class from early versions (0.1-0.5) has been removed; use `CohereMelody.render()` instead.
fix
Replace `from melody import Template` with `from melody import CohereMelody` and use the `render` method.
affects: <0.6.0
gotchaTemplate variables must be entirely lowercase; uppercase or mixed-case variable names will not be substituted.
fix
Use only lowercase variable names in templates, e.g., `{{my_var}}` not `{{MyVar}}`.
affects: >=0.9.0
Upgrade
Version history
0.9.0latest on PyPI · released May 15, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
17 hits · last 30 days
node
14
Amazon
1
OpenAI (training)
1
Resources
cohere-melody — pip install cohere-melody · libregistry