{"name":"Harmony: OpenAI's Renderer for GPT-OSS Response Format","description":"Harmony is OpenAI's dedicated renderer for its `harmony` response format, specifically designed for use with `gpt-oss` open-weight models. This library provides a robust solution for defining conversation structures, generating reasoning output, and structuring function calls, ensuring consistent and efficient token-sequence handling for both rendering and parsing. It offers first-class support for both Python and Rust development.","github":"https://github.com/openai/harmony","url":"https://osrepos.com/repo/openai-harmony","source":"osrepos.com","sourceDescription":"This repository profile is provided by osrepos.com, an open source repository discovery platform.","repositoryProfile":"https://osrepos.com/repo/openai-harmony","generatedFor":"open source discovery and AI-assisted research","markdown":"https://osrepos.com/repo/openai-harmony.md","json":"https://osrepos.com/repo/openai-harmony.json","topics":["Rust","Python","AI","LLM","OpenAI","GPT-OSS","Response Format","Developer Tools"],"keywords":["Rust","Python","AI","LLM","OpenAI","GPT-OSS","Response Format","Developer Tools"],"stars":null,"summary":"Harmony is OpenAI's dedicated renderer for its `harmony` response format, specifically designed for use with `gpt-oss` open-weight models. This library provides a robust solution for defining conversation structures, generating reasoning output, and structuring function calls, ensuring consistent and efficient token-sequence handling for both rendering and parsing. It offers first-class support for both Python and Rust development.","content":"## Introduction\n\nOpenAI Harmony is a dedicated library for rendering and parsing the `harmony` response format, crucial for interacting with OpenAI's `gpt-oss` open-weight model series. The `gpt-oss` models are trained on this specific format, which defines conversation structures, generates reasoning output, and structures function calls. While users interacting with `gpt-oss` through an API or providers like HuggingFace, Ollama, or vLLM might not need to handle this format directly, developers building custom inference solutions will find Harmony essential for ensuring correct model operation. The format is designed to mimic the OpenAI Responses API, making it familiar to those who have used that API before.\n\n## Installation\n\nHarmony offers robust support for both Python and Rust, allowing developers to integrate it seamlessly into their projects.\n\n### Python\n\nInstall the package from PyPI:\n\nbash\npip install openai-harmony\n# or if you are using uv\nuv pip install openai-harmony\n\nFor comprehensive documentation, please refer to the [official Python documentation](https://github.com/openai/harmony/blob/main/docs/python.md).\n\n### Rust\n\nAdd the dependency to your `Cargo.toml`:\n\ntoml\n[dependencies]\nopenai-harmony = { git = \"https://github.com/openai/harmony\" }\n\nFor comprehensive documentation, please refer to the [official Rust documentation](https://github.com/openai/harmony/blob/main/docs/rust.md).\n\n## Examples\n\nHere are examples demonstrating how to use Harmony in both Python and Rust to render and parse conversations.\n\n### Python Example\n\npython\nfrom openai_harmony import (\n    load_harmony_encoding,\n    HarmonyEncodingName,\n    Role,\n    Message,\n    Conversation,\n    DeveloperContent,\n    SystemContent,\n)\nenc = load_harmony_encoding(HarmonyEncodingName.HARMONY_GPT_OSS)\nconvo = Conversation.from_messages([\n    Message.from_role_and_content(\n        Role.SYSTEM,\n        SystemContent.new(),\n    ),\n    Message.from_role_and_content(\n        Role.DEVELOPER,\n        DeveloperContent.new().with_instructions(\"Talk like a pirate!\")\n    ),\n    Message.from_role_and_content(Role.USER, \"Arrr, how be you?\"),\n])\ntokens = enc.render_conversation_for_completion(convo, Role.ASSISTANT)\nprint(tokens)\n# Later, after the model responded …\nparsed = enc.parse_messages_from_completion_tokens(tokens, role=Role.ASSISTANT)\nprint(parsed)\n\n\n### Rust Example\n\nrust\nuse openai_harmony::chat::{Message, Role, Conversation};\nuse openai_harmony::{HarmonyEncodingName, load_harmony_encoding};\n\nfn main() -> anyhow::Result<()> {\n    let enc = load_harmony_encoding(HarmonyEncodingName::HarmonyGptOss)?;\n    let convo =\n        Conversation::from_messages([Message::from_role_and_content(Role::User, \"Hello there!\")]);\n    let tokens = enc.render_conversation_for_completion(&convo, Role::Assistant, None)?;\n    println!(\"{:?}\", tokens);\n    Ok(())\n}\n\n\n## Why Use Harmony?\n\nHarmony offers several compelling advantages for developers working with `gpt-oss` models:\n\n*   **Consistent formatting**: A shared implementation for both rendering and parsing ensures token-sequences remain loss-free, maintaining data integrity.\n*   **Blazing fast performance**: The core logic, built in Rust, provides high performance for demanding applications.\n*   **First-class Python support**: Enjoy seamless integration with Python projects, including easy installation via `pip`, comprehensive typed stubs, and 100% test parity with the Rust suite.\n\n## Links\n\nExplore Harmony and related resources further:\n\n*   **GitHub Repository**: [openai/harmony](https://github.com/openai/harmony)\n*   **Try `gpt-oss`**: [gpt-oss.com](https://gpt-oss.com)\n*   **Learn more about `gpt-oss`**: [OpenAI Cookbook](https://cookbook.openai.com/topic/gpt-oss)\n*   **`gpt-oss` Model Card**: [OpenAI](https://openai.com/index/gpt-oss-model-card/)\n*   **Learn more about the `harmony` format**: [OpenAI Cookbook](https://cookbook.openai.com/articles/openai-harmony)","metrics":{"detailViews":10,"githubClicks":11},"dates":{"published":null,"modified":"2025-10-14T15:01:39.000Z"}}