About this project

OpenAI Harmony is a library for working with the harmony response format, the conversation structure on which OpenAI's open-weight gpt-oss models were trained. According to the README, gpt-oss should not be used without the harmony format, as it will not work correctly. Users who access gpt-oss through an API or providers such as HuggingFace, Ollama, or vLLM do not need to handle formatting themselves, since the inference solution does so. The library targets developers building their own inference solutions. The format is designed to mimic the OpenAI Responses API and supports multiple output channels for chain-of-thought, tool-calling preambles, regular responses, tool namespaces, structured outputs, and an instruction hierarchy. The README includes an example prompt showing system, developer, and user messages with tool definitions. Key stated features: - Consistent formatting: a shared implementation for rendering and parsing keeps token sequences loss-free. - Performance: heavy lifting is implemented in Rust. - Python support: installable via pip, with typed stubs and test parity with the Rust suite. The repository contains a Rust crate (chat data structures, encoding/rendering and parsing, built-in encoding registry, tests, and PyO3 bindings) plus a pure-Python wrapper exposing dataclasses and a helper API. Python installation is via `pip install openai-harmony` or `uv pip install openai-harmony`; Rust usage adds the crate as a git dependency in Cargo.toml. Examples show loading the HARMONY_GPT_OSS encoding, building a Conversation from messages, rendering it for completion, and parsing messages from completion tokens. For local development, prerequisites are a stable Rust toolchain, Python 3.8+ with a virtual environment, and maturin. The workflow uses `maturin develop --release` to compile the Rust crate and install the Python package in editable mode. Tests run with `cargo test` for Rust and `pytest` for Python, with the Python suite described as a one-to-one port of the Rust tests. Optional tooling includes mypy for type checking, ruff for linting, and cargo fmt for formatting.