Skip to main content

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

Project description

Harmony

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


The [gpt-oss models][gpt-oss] were trained on the [harmony response format][harmony-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][harmony-format] 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][harmony-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

See CONTRIBUTING.md

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.10.tar.gz (232.2 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.10-cp38-abi3-win_amd64.whl (2.6 MB view details)

Uploaded CPython 3.8+Windows x86-64

oss_harmony-0.0.10-cp38-abi3-win32.whl (2.2 MB view details)

Uploaded CPython 3.8+Windows x86

oss_harmony-0.0.10-cp38-abi3-musllinux_1_2_x86_64.whl (3.4 MB view details)

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

oss_harmony-0.0.10-cp38-abi3-musllinux_1_2_i686.whl (3.2 MB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ i686

oss_harmony-0.0.10-cp38-abi3-musllinux_1_2_armv7l.whl (3.1 MB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ ARMv7l

oss_harmony-0.0.10-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.10-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.1 MB view details)

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

oss_harmony-0.0.10-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (3.6 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ppc64le

oss_harmony-0.0.10-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl (3.1 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ i686

oss_harmony-0.0.10-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.10-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (3.1 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARM64

oss_harmony-0.0.10-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.10.tar.gz.

File metadata

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

File hashes

Hashes for oss_harmony-0.0.10.tar.gz
Algorithm Hash digest
SHA256 b8caa92d3888023b4e6110aaeac17898ab9eff822647692b99866318f6f9b5d7
MD5 52e66e280117876b267bf59bbe53b43e
BLAKE2b-256 d3b941e701b831abe195acb9b59ab3f38b3b29f6afea6b13d592999be55331b2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for oss_harmony-0.0.10-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 c6b6244fed03c6ed801fd15b0346aad77214d03bd63f176c88583780f562938d
MD5 5374cde6e563e238ba0519c0383907da
BLAKE2b-256 0d2a71f4c0f6e77f7f03ad12d7be2436a563934ec3e4cb15026dd97b69c0f8e3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: oss_harmony-0.0.10-cp38-abi3-win32.whl
  • Upload date:
  • Size: 2.2 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.10-cp38-abi3-win32.whl
Algorithm Hash digest
SHA256 699e30b298fb83b9e4e5f52f95b369109eebf2bd5559f6988ff9b5dabc9b8a95
MD5 5ce74127baaafea05cb6c08452de2c22
BLAKE2b-256 ff448522f1a5602f3a08403ab99654eaaf98f099d4c052e4c16fc734a65f1017

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for oss_harmony-0.0.10-cp38-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 6e0b8cd33cd82ff5966601b2ebc8313bf168f97189704e5ffcf04a2ff3622a55
MD5 7c71eb20a21040e064dc9670268bfe05
BLAKE2b-256 354add527b17270a8bd69bb23b38dccdd976e53289858a785b17f605702e0f9e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for oss_harmony-0.0.10-cp38-abi3-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 c076cb565cec38134d59d73bb51c0a5a596561669ba4a4532ad1b4e89c76fa81
MD5 107798bbf4f5e3c7ec18eafc4cf60e24
BLAKE2b-256 47bbc117315d4d3d50f7f504a45a925c834c45750be255be56dd3bf1011ab9eb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for oss_harmony-0.0.10-cp38-abi3-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 dd50ac323d6569f1364f226e143c3cd274f1730f7fa567edd4d0e9f478444d25
MD5 13b3c44eb075224b8a6e4934220a88ba
BLAKE2b-256 710d536b40b0e997349fd8621e00e7695baab5c35212eafe2afbd45805548e53

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for oss_harmony-0.0.10-cp38-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 7671ebcc4e820f84460454179970b4820e65ee962fe6b7b6d9615364173c9783
MD5 23564ffe745b71e45bb02db7304bc945
BLAKE2b-256 3206aff4803c5ad333c873c5583663e6236fcaf79cadd54b8143be6b36af642a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for oss_harmony-0.0.10-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b432a6bec90a378abc5ba74c9f06e2126ed8e1d791544d310b9b094f51f3bb44
MD5 9cc97f0eab66dd6764bab0d6fd082ca8
BLAKE2b-256 40c48db6374b42291b8bf996f112aa707f9bbeac21e12a847f6978686e6fd375

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for oss_harmony-0.0.10-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 01f5c3a366dd3124a3802359c63ab93027a43687d9256bd6d3e2135943424a44
MD5 3162c3da16468ca33248a0b989236adb
BLAKE2b-256 66d335cb015d383e323294af3d7abbf16187841f65b1918f7ddf9eb36e3d6481

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for oss_harmony-0.0.10-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 e05ee965f0ead681154b58b33ac6402d287e7f05aa63bb0ca179b12862574f9b
MD5 2d1aa57484a0438e07398764e60ee9b9
BLAKE2b-256 a90b5bee3a580c71ff720ee5c07a2191873cdcce593be8f123cbcb805594d94b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for oss_harmony-0.0.10-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 4397d2bea193129f5fda0adbe1d27c5717bd6c5c4ebb313fd982e7179e650e8f
MD5 8a3e1fd409d7a9d92f47b2eb193ff958
BLAKE2b-256 6cac716134f3ea886ab4e8d8bfb9af83e81228d3447f03bfeeb8bb0a8692fdcd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for oss_harmony-0.0.10-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 870471541d698899ae523400361543d9d1675ca876782da4dd68b33bb4e4bbdf
MD5 415381b655bd04d623557a0b76834848
BLAKE2b-256 6dd0a81914d3c01734d43f0d696dd84d4c9d1d8b200017065e5add5635f15245

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for oss_harmony-0.0.10-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0fd4c971b4a207362d32df4f4a27b016936f0a12f869fdf02647c604d5c0d5c9
MD5 5a829a2a690f4d5a01d16d17d8845e46
BLAKE2b-256 15df41ed586177c3d4803496ee7fd212e3d8e5a425e9e4888129fb5562f4988c

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