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.11.tar.gz (2.2 MB 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.11-cp38-abi3-win_amd64.whl (3.3 MB view details)

Uploaded CPython 3.8+Windows x86-64

oss_harmony-0.0.11-cp38-abi3-win32.whl (3.1 MB view details)

Uploaded CPython 3.8+Windows x86

oss_harmony-0.0.11-cp38-abi3-musllinux_1_2_x86_64.whl (3.8 MB view details)

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

oss_harmony-0.0.11-cp38-abi3-musllinux_1_2_i686.whl (3.8 MB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ i686

oss_harmony-0.0.11-cp38-abi3-musllinux_1_2_armv7l.whl (3.7 MB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ ARMv7l

oss_harmony-0.0.11-cp38-abi3-musllinux_1_2_aarch64.whl (3.7 MB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ ARM64

oss_harmony-0.0.11-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.6 MB view details)

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

oss_harmony-0.0.11-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (3.7 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ppc64le

oss_harmony-0.0.11-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (3.4 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARMv7l

oss_harmony-0.0.11-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (3.5 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARM64

oss_harmony-0.0.11-cp38-abi3-manylinux_2_5_i686.manylinux1_i686.whl (3.6 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.5+ i686

oss_harmony-0.0.11-cp38-abi3-macosx_11_0_arm64.whl (3.3 MB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

File details

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

File metadata

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

File hashes

Hashes for oss_harmony-0.0.11.tar.gz
Algorithm Hash digest
SHA256 ccad467b71d61490df1f2204b7a064990833338615ac135536c5b3a8e2d03a15
MD5 1ae40fb7a0e895289c527e9c4f1f42f5
BLAKE2b-256 4388ca56e5b17df4763bbb552c7be3abe432b51db3c51f6327a3848b88ad7c08

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for oss_harmony-0.0.11-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 4db175b6f6264cd60ceb692c0e686937e072ca6ea1239d0d4cace2cfb50f4974
MD5 9ce0c8204a192a27c35207a7f4d335ba
BLAKE2b-256 c8c9eedd8d02be8bbaa586f8a323de2fc976e6053582411020b7be1f7c7e1734

See more details on using hashes here.

File details

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

File metadata

  • Download URL: oss_harmony-0.0.11-cp38-abi3-win32.whl
  • Upload date:
  • Size: 3.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.11-cp38-abi3-win32.whl
Algorithm Hash digest
SHA256 fd91609eef825f342ae7ac990651cfebcf28aac6b6ad1186bf37c5b593cdf950
MD5 121e9155c261b2d7080c9d0e51bb5f06
BLAKE2b-256 03332917125287b46255cfc6d7e0bc4bc5e5c90f7ad4e02d3922c2f0f95b696b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for oss_harmony-0.0.11-cp38-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 0d1545203973abb3002dcc6c5cffd14ca4a376b655c14ce190c78eb6aaf5f6fd
MD5 9a95b0932a66fdbf20149c4a053477ea
BLAKE2b-256 489aad24d20ea1e8b3167744f5d357d48a116086258ca58540986a0896781864

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for oss_harmony-0.0.11-cp38-abi3-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 5c7b0cea27e1e4e9fc485bf8039a119d6732718cce6b067d1f7de9e637572348
MD5 ca700a3668800a67ecb92b04f6dc2602
BLAKE2b-256 0d7dd71b3ee5abfbf9130eea646b9589e8f00a039514cdca2ab6dbffa22f8351

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for oss_harmony-0.0.11-cp38-abi3-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 952218411c219dc7ca8ee56eb86271d015d0c347896b2009906096422d7a94cf
MD5 781d235ee0408cb3c9360672d07f7195
BLAKE2b-256 94a8fb8cad33079ee848514ea70688005ef7b6c32ccee788cc18fcb04e24fa74

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for oss_harmony-0.0.11-cp38-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 036505bfb39c6b50edcf717349518d269bb375207f7f8e95f517e938b8f2e0c8
MD5 624f8fd8b0f00003d8772fb2e94fe674
BLAKE2b-256 4bc9720aed1527d87f82e07a7f35c3c81c6d9198a8d1223bdbd298b3c66a72db

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for oss_harmony-0.0.11-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d877c6b526cdbdf55068bae8f05c60398e929c9e296c7f69a1d533339708be80
MD5 28942531f7bee7befa52c117a65db5d0
BLAKE2b-256 8968001d7429a692b2db0c03bd49b756f834716b64afc0bbbece96824e8f0af8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for oss_harmony-0.0.11-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 f215934b05f3a7658e0cf30cf92bc25f4aed125a693529c53dd97325ecfbf7ef
MD5 d34f403f316c65e58dcb50d6f5990750
BLAKE2b-256 8bf7f802d7aba027cd4e1c0ff5509c645de8d70fa674b31d80cdf8fec63ac844

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for oss_harmony-0.0.11-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 2221f2790411cfd5d0e517769dc2662b15b2711e44728291961506a367ffc3d1
MD5 ce555b2d49dd122f4106b6edcf294cbf
BLAKE2b-256 dec3502b7ba6f36645117b58859b250355cba34d7107ec104ea40087b752977b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for oss_harmony-0.0.11-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 f1f74ef7f8be32fa1dcfe1644839af5f0873acce78b5668c2aa39f26d83218ff
MD5 fd1159b456334391eed283bf75fdaa5c
BLAKE2b-256 fde90b33d4c592e1422c9faeaf1cfe10731328ecf3504e900dc7921109affd55

See more details on using hashes here.

File details

Details for the file oss_harmony-0.0.11-cp38-abi3-manylinux_2_5_i686.manylinux1_i686.whl.

File metadata

File hashes

Hashes for oss_harmony-0.0.11-cp38-abi3-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm Hash digest
SHA256 e451e5dc28b0d883f33aa17a77c923afcab5d26ef3b95d7593b68a07e399706e
MD5 5abc2eb35722c41d954b253a450e1b8f
BLAKE2b-256 3b5dedf954b0aace872ec137a9ef7b92c29120bd16a4277fd11c5b83e7d1ed16

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for oss_harmony-0.0.11-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 83ca71b85be6e2f8e93527673cd2eff4da9180608ee5d4197bd4f01afc4fa6be
MD5 a4a7471049b7b508c262afb0462f3025
BLAKE2b-256 8b4c400a7e375943ff06447c8cd3920819d2e37c808d0cfea3296b159e961610

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