Skip to main content

Response format library for the gpt-oss open-weight model series (fork of openai-harmony)

Project description

harmony

Harmony

Response format library for the gpt-oss open-weight model series (fork of openai-harmony)
Try gpt-oss | Learn more | Model card


The gpt-oss models were trained on the harmony response format for defining conversation structures, generating reasoning output and structuring function calls. If you are not using gpt-oss directly but through an API or a provider like HuggingFace, Ollama, or vLLM, you will not have to be concerned about this as your inference solution will handle the formatting. If you are building your own inference solution, this guide will walk you through the prompt format. The format is designed to mimic the OpenAI Responses API, so if you have used that API before, this format should hopefully feel familiar to you. gpt-oss should not be used without using the harmony format as it will not work correctly.

The format enables the model to output to multiple different channels for chain of thought, and tool calling preambles along with regular responses. It also enables specifying various tool namespaces, and structured outputs along with a clear instruction hierarchy. Check out the guide to learn more about the format itself.

<|start|>system<|message|>You are ChatGPT, a large language model trained by OpenAI.
Knowledge cutoff: 2024-06
Current date: 2025-06-28

Reasoning: high

# Valid channels: analysis, commentary, final. Channel must be included for every message.
Calls to these tools must go to the commentary channel: 'functions'.<|end|>

<|start|>developer<|message|># Instructions

Always respond in riddles

# Tools

## functions

namespace functions {

// Gets the location of the user.
type get_location = () => any;

// Gets the current weather in the provided location.
type get_current_weather = (_: {
// The city and state, e.g. San Francisco, CA
location: string,
format?: "celsius" | "fahrenheit", // default: celsius
}) => any;

} // namespace functions<|end|><|start|>user<|message|>What is the weather like in SF?<|end|><|start|>assistant

We recommend using this library when working with models that use the harmony response format

  • Consistent formatting – shared implementation for rendering and parsing keeps token-sequences loss-free.
  • Blazing fast – heavy lifting happens in Rust.
  • First-class Python support – install with pip, typed stubs included, 100 % test parity with the Rust suite.

Using Harmony

Python

Check out the full documentation

Installation

Install the package from PyPI by running

pip install oss-harmony
# or if you are using uv
uv pip install oss-harmony

Example

from openai_harmony import (
    load_harmony_encoding,
    HarmonyEncodingName,
    Role,
    Message,
    Conversation,
    DeveloperContent,
    SystemContent,
)
enc = load_harmony_encoding(HarmonyEncodingName.HARMONY_GPT_OSS)
convo = Conversation.from_messages([
    Message.from_role_and_content(
        Role.SYSTEM,
        SystemContent.new(),
    ),
    Message.from_role_and_content(
        Role.DEVELOPER,
        DeveloperContent.new().with_instructions("Talk like a pirate!")
    ),
    Message.from_role_and_content(Role.USER, "Arrr, how be you?"),
])
tokens = enc.render_conversation_for_completion(convo, Role.ASSISTANT)
print(tokens)
# Later, after the model responded …
parsed = enc.parse_messages_from_completion_tokens(tokens, role=Role.ASSISTANT)
print(parsed)

Rust

Check out the full documentation

Installation

Add the dependency to your Cargo.toml

[dependencies]
oss-harmony = { git = "https://github.com/oss-harmony/harmony" }

Example

use openai_harmony::chat::{Message, Role, Conversation};
use openai_harmony::{HarmonyEncodingName, load_harmony_encoding};

fn main() -> anyhow::Result<()> {
    let enc = load_harmony_encoding(HarmonyEncodingName::HarmonyGptOss)?;
    let convo =
        Conversation::from_messages([Message::from_role_and_content(Role::User, "Hello there!")]);
    let tokens = enc.render_conversation_for_completion(&convo, Role::Assistant, None)?;
    println!("{:?}", tokens);
    Ok(())
}

Contributing

The majority of the rendering and parsing is built in Rust for performance and exposed to Python through thin pyo3 bindings.

┌──────────────────┐      ┌───────────────────────────┐
│  Python code     │      │  Rust core (this repo)    │
│  (dataclasses,   │────► │  • chat / encoding logic  │
│   convenience)   │      │  • tokeniser (tiktoken)   │
└──────────────────┘  FFI └───────────────────────────┘

Repository layout

.
├── src/                  # Rust crate
│   ├── chat.rs           # High-level data-structures (Role, Message, …)
│   ├── encoding.rs       # Rendering & parsing implementation
│   ├── registry.rs       # Built-in encodings
│   ├── tests.rs          # Canonical Rust test-suite
│   └── py_module.rs      # PyO3 bindings ⇒ compiled as openai_harmony.*.so
│
├── python/openai_harmony/ # Pure-Python wrapper around the binding
│   └── __init__.py       # Dataclasses + helper API mirroring chat.rs
│
├── tests/                # Python test-suite (1-to-1 port of tests.rs)
├── Cargo.toml            # Rust package manifest
├── pyproject.toml        # Python build configuration for maturin
└── README.md             # You are here 🖖

Developing locally

Prerequisites

  • Rust tool-chain (stable) – https://rustup.rs
  • Python ≥ 3.8 + virtualenv/venv
  • maturin – build tool for PyO3 projects

1. Clone & bootstrap

git clone https://github.com/oss-harmony/harmony.git
cd harmony
# Create & activate a virtualenv
python -m venv .venv
source .venv/bin/activate
# Install maturin and test dependencies
pip install maturin pytest mypy ruff  # tailor to your workflow
# Compile the Rust crate *and* install the Python package in editable mode
maturin develop --release

maturin develop builds harmony with Cargo, produces a native extension (openai_harmony.<abi>.so) and places it in your virtualenv next to the pure- Python wrapper – similar to pip install -e . for pure Python projects.

2. Running the test-suites

Rust:

cargo test          # runs src/tests.rs

Python:

pytest              # executes tests/ (mirrors the Rust suite)

Run both in one go to ensure parity:

pytest && cargo test

3. Type-checking & formatting (optional)

mypy harmony        # static type analysis
ruff check .        # linting
cargo fmt --all     # Rust formatter

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

oss_harmony-0.0.9.tar.gz (281.0 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

oss_harmony-0.0.9-cp38-abi3-win_amd64.whl (2.5 MB view details)

Uploaded CPython 3.8+Windows x86-64

oss_harmony-0.0.9-cp38-abi3-win32.whl (2.1 MB view details)

Uploaded CPython 3.8+Windows x86

oss_harmony-0.0.9-cp38-abi3-musllinux_1_2_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ x86-64

oss_harmony-0.0.9-cp38-abi3-musllinux_1_2_i686.whl (3.1 MB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ i686

oss_harmony-0.0.9-cp38-abi3-musllinux_1_2_armv7l.whl (3.0 MB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ ARMv7l

oss_harmony-0.0.9-cp38-abi3-musllinux_1_2_aarch64.whl (3.2 MB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ ARM64

oss_harmony-0.0.9-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.0 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ x86-64

oss_harmony-0.0.9-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (3.5 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ppc64le

oss_harmony-0.0.9-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl (3.0 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ i686

oss_harmony-0.0.9-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (2.8 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARMv7l

oss_harmony-0.0.9-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (3.0 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARM64

oss_harmony-0.0.9-cp38-abi3-macosx_11_0_arm64.whl (2.7 MB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

File details

Details for the file oss_harmony-0.0.9.tar.gz.

File metadata

  • Download URL: oss_harmony-0.0.9.tar.gz
  • Upload date:
  • Size: 281.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.13.3

File hashes

Hashes for oss_harmony-0.0.9.tar.gz
Algorithm Hash digest
SHA256 2235f443a2f20abae13cdbe91bab0666fe0589262ee8c94de7c3dc12517356f3
MD5 525b2f0def8dd12a13641f53ad89092a
BLAKE2b-256 d2b635a3975cc145b3759e2dee5f606051ad58447fdcf77eea593ff18ecba3fb

See more details on using hashes here.

File details

Details for the file oss_harmony-0.0.9-cp38-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for oss_harmony-0.0.9-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 7a0c98892671272af9f6c7755f48788468de26bad2aa3dc20860cf92e27a711f
MD5 b5f02a7a4793e263c28f217136cac729
BLAKE2b-256 ae1b371943fbe091c1fdca6ea13d6de11b7445c9650a63889fb1d96f14add9c3

See more details on using hashes here.

File details

Details for the file oss_harmony-0.0.9-cp38-abi3-win32.whl.

File metadata

  • Download URL: oss_harmony-0.0.9-cp38-abi3-win32.whl
  • Upload date:
  • Size: 2.1 MB
  • Tags: CPython 3.8+, Windows x86
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.13.3

File hashes

Hashes for oss_harmony-0.0.9-cp38-abi3-win32.whl
Algorithm Hash digest
SHA256 56b0fd175632c49ae4bf8d20fce7848f9dd0eb775fafd91a6ffaa4c2ad3af0c6
MD5 445a960e3cddebe0201a9b00779ceede
BLAKE2b-256 d5a387a470242ab0ad3ccc37aff8fe3d8b8a712e5c93ba03026ab964d933d730

See more details on using hashes here.

File details

Details for the file oss_harmony-0.0.9-cp38-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for oss_harmony-0.0.9-cp38-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 b80e28dd35dda20aa74b1b062379fd9d6649e58ece7adb6a931510a4fe2472b4
MD5 b4f8174d65f21607e1ccee7f956c0141
BLAKE2b-256 85d58a30d689096ff9a01235a56637a3aa0332b1b28d40a76730529804c0f1f5

See more details on using hashes here.

File details

Details for the file oss_harmony-0.0.9-cp38-abi3-musllinux_1_2_i686.whl.

File metadata

File hashes

Hashes for oss_harmony-0.0.9-cp38-abi3-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 083cf43b0346287524f574ddaa77e95b317407f2a996d9a697aa297444ef3825
MD5 781b745c9eead902be9ba7b0008a3855
BLAKE2b-256 26cc35e8daead1e536d2459ad58723e168341da2d4a69738e1166f16b5cdefaf

See more details on using hashes here.

File details

Details for the file oss_harmony-0.0.9-cp38-abi3-musllinux_1_2_armv7l.whl.

File metadata

File hashes

Hashes for oss_harmony-0.0.9-cp38-abi3-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 7304e14554ecd5388ac2bbdeee04d3b605593b8be425941ed7097ca1dd327b86
MD5 1ae995ecc79ae425b2c9766badc9bebe
BLAKE2b-256 152a958bc25558464e4083c66ceca7e045de37e3af1953299e3f8732ba16e6c6

See more details on using hashes here.

File details

Details for the file oss_harmony-0.0.9-cp38-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for oss_harmony-0.0.9-cp38-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 b35c3aebcdb8d550ad76c994aaf6fa0a5e56b5888d68a183580228154a37a611
MD5 0b2f13e5d29230bc102ad4bd7ce6e3f8
BLAKE2b-256 dc294462c90448564751169ae7d29027ce14598daf833d21780cc3107bd123be

See more details on using hashes here.

File details

Details for the file oss_harmony-0.0.9-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for oss_harmony-0.0.9-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cddd07947db6b20734d95e15c364707e8463a11e3a18e64d5d637a635ad5acb6
MD5 186a12d43d02e9a7f201083f193f2dc5
BLAKE2b-256 0047c96fc8eda2663c88d8ea6d9bcd15c29c3571378f833aa0cac32638afef1e

See more details on using hashes here.

File details

Details for the file oss_harmony-0.0.9-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl.

File metadata

File hashes

Hashes for oss_harmony-0.0.9-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 d63a09abe28c0e3ca904a3941123c2360926b48d0998c1491cd960475c5f0fa0
MD5 24da40a092285dd5f5dc5137cd968410
BLAKE2b-256 fe8288f7b00836cc252860e2ed006e186be8752308adecf42b87ab230034442f

See more details on using hashes here.

File details

Details for the file oss_harmony-0.0.9-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for oss_harmony-0.0.9-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 79056e52881f4a281aaa9524c9a20657dc4d99643fda8426dfacf4caf022b629
MD5 a7d881783528f6e3ea15733e0eb996e0
BLAKE2b-256 ecfd5abc43e8f101aa0dae5e4a77cad0182ec4982e09b670b04acd229389fd25

See more details on using hashes here.

File details

Details for the file oss_harmony-0.0.9-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.

File metadata

File hashes

Hashes for oss_harmony-0.0.9-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 94c948c3dd0ef3c121e64eee3b75644f9af92a898fb554168b6a113e395bd785
MD5 881c9d9da28a2200f1316da65050a983
BLAKE2b-256 61079a5a80fdb8b06ab8c231014a6a7663fe0d8cba893e2a083c33ee5e547f47

See more details on using hashes here.

File details

Details for the file oss_harmony-0.0.9-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for oss_harmony-0.0.9-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 5e560351edde88493b51bde67d2d8fd63242eeb79f6fb3cf46123636d46126ea
MD5 002f36fe3ef11489db64163906fcffdf
BLAKE2b-256 5e59c1bf7ae859d42ec1d7d5f8c9aad4091100846e42d4e76bf2b8d1441f0496

See more details on using hashes here.

File details

Details for the file oss_harmony-0.0.9-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for oss_harmony-0.0.9-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c4a5dc07dd6151589fcd32f5e3d0d65cc1c23fb3ee237005b04f73311eb684c2
MD5 4db9011864ecf9fb7969adf8692a5e08
BLAKE2b-256 880cd9a096c0e63484550bb8d38869d9910d3e0f1a270483250bf628116a42dc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page