mirror of
https://github.com/openai/harmony.git
synced 2025-08-23 01:17:09 -04:00
Merge branch 'main' into main
This commit is contained in:
commit
eb86106b69
6 changed files with 27 additions and 20 deletions
18
.github/workflows/CI.yml
vendored
18
.github/workflows/CI.yml
vendored
|
@ -28,14 +28,10 @@ jobs:
|
||||||
target: x86_64
|
target: x86_64
|
||||||
- runner: ubuntu-22.04
|
- runner: ubuntu-22.04
|
||||||
target: x86
|
target: x86
|
||||||
# - runner: ubuntu-22.04
|
- runner: ubuntu-22.04
|
||||||
# target: aarch64
|
target: aarch64
|
||||||
- runner: ubuntu-22.04
|
- runner: ubuntu-22.04
|
||||||
target: armv7
|
target: armv7
|
||||||
# - runner: ubuntu-22.04
|
|
||||||
# target: s390x
|
|
||||||
# - runner: ubuntu-22.04
|
|
||||||
# target: ppc64le
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: actions/setup-python@v5
|
- uses: actions/setup-python@v5
|
||||||
|
@ -43,6 +39,9 @@ jobs:
|
||||||
python-version: 3.x
|
python-version: 3.x
|
||||||
- name: Build wheels
|
- name: Build wheels
|
||||||
uses: PyO3/maturin-action@v1
|
uses: PyO3/maturin-action@v1
|
||||||
|
env:
|
||||||
|
# Ensure ring's ARM assembly sees an explicit architecture on aarch64 (glibc)
|
||||||
|
CFLAGS_aarch64_unknown_linux_gnu: -D__ARM_ARCH=8
|
||||||
with:
|
with:
|
||||||
target: ${{ matrix.platform.target }}
|
target: ${{ matrix.platform.target }}
|
||||||
args: --release --out dist --find-interpreter
|
args: --release --out dist --find-interpreter
|
||||||
|
@ -74,6 +73,9 @@ jobs:
|
||||||
python-version: 3.x
|
python-version: 3.x
|
||||||
- name: Build wheels
|
- name: Build wheels
|
||||||
uses: PyO3/maturin-action@v1
|
uses: PyO3/maturin-action@v1
|
||||||
|
env:
|
||||||
|
# Ensure ring's ARM assembly sees an explicit architecture on aarch64 (musl)
|
||||||
|
CFLAGS_aarch64_unknown_linux_musl: -D__ARM_ARCH=8
|
||||||
with:
|
with:
|
||||||
target: ${{ matrix.platform.target }}
|
target: ${{ matrix.platform.target }}
|
||||||
args: --release --out dist --find-interpreter
|
args: --release --out dist --find-interpreter
|
||||||
|
@ -104,7 +106,7 @@ jobs:
|
||||||
uses: PyO3/maturin-action@v1
|
uses: PyO3/maturin-action@v1
|
||||||
with:
|
with:
|
||||||
target: ${{ matrix.platform.target }}
|
target: ${{ matrix.platform.target }}
|
||||||
args: -F python-binding --release --out dist --find-interpreter
|
args: --release --out dist --find-interpreter
|
||||||
sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
|
sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
|
||||||
- name: Upload wheels
|
- name: Upload wheels
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
|
@ -130,7 +132,7 @@ jobs:
|
||||||
uses: PyO3/maturin-action@v1
|
uses: PyO3/maturin-action@v1
|
||||||
with:
|
with:
|
||||||
target: ${{ matrix.platform.target }}
|
target: ${{ matrix.platform.target }}
|
||||||
args: -F python-binding --release --out dist --find-interpreter
|
args: --release --out dist --find-interpreter
|
||||||
sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
|
sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
|
||||||
- name: Upload wheels
|
- name: Upload wheels
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
|
|
|
@ -42,7 +42,10 @@ reqwest = { version = "0.12.5", default-features = false, features = [
|
||||||
] }
|
] }
|
||||||
futures = "0.3"
|
futures = "0.3"
|
||||||
clap = { version = "4", features = ["derive"] }
|
clap = { version = "4", features = ["derive"] }
|
||||||
pyo3 = { version = "0.25.0", optional = true, features = ["extension-module"] }
|
pyo3 = { version = "0.25.0", optional = true, features = [
|
||||||
|
"extension-module",
|
||||||
|
"abi3-py38",
|
||||||
|
] }
|
||||||
wasm-bindgen = { version = "0.2.100", optional = true, features = [
|
wasm-bindgen = { version = "0.2.100", optional = true, features = [
|
||||||
"serde-serialize",
|
"serde-serialize",
|
||||||
] }
|
] }
|
||||||
|
|
18
README.md
18
README.md
|
@ -10,9 +10,9 @@
|
||||||
|
|
||||||
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 [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 premables 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.
|
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.
|
||||||
|
|
||||||
```
|
```text
|
||||||
<|start|>system<|message|>You are ChatGPT, a large language model trained by OpenAI.
|
<|start|>system<|message|>You are ChatGPT, a large language model trained by OpenAI.
|
||||||
Knowledge cutoff: 2024-06
|
Knowledge cutoff: 2024-06
|
||||||
Current date: 2025-06-28
|
Current date: 2025-06-28
|
||||||
|
@ -114,11 +114,11 @@ openai-harmony = { git = "https://github.com/openai/harmony" }
|
||||||
```rust
|
```rust
|
||||||
use openai_harmony::chat::{Message, Role, Conversation};
|
use openai_harmony::chat::{Message, Role, Conversation};
|
||||||
use openai_harmony::{HarmonyEncodingName, load_harmony_encoding};
|
use openai_harmony::{HarmonyEncodingName, load_harmony_encoding};
|
||||||
|
|
||||||
fn main() -> anyhow::Result<()> {
|
fn main() -> anyhow::Result<()> {
|
||||||
let enc = load_harmony_encoding(HarmonyEncodingName::HarmonyGptOss)?;
|
let enc = load_harmony_encoding(HarmonyEncodingName::HarmonyGptOss)?;
|
||||||
let convo = Conversation::from_messages([
|
let convo =
|
||||||
Message::from_role_and_content(Role::User, "Hello there!"),
|
Conversation::from_messages([Message::from_role_and_content(Role::User, "Hello there!")]);
|
||||||
]);
|
|
||||||
let tokens = enc.render_conversation_for_completion(&convo, Role::Assistant, None)?;
|
let tokens = enc.render_conversation_for_completion(&convo, Role::Assistant, None)?;
|
||||||
println!("{:?}", tokens);
|
println!("{:?}", tokens);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -130,7 +130,7 @@ fn main() -> anyhow::Result<()> {
|
||||||
The majority of the rendering and parsing is built in Rust for performance and exposed to Python
|
The majority of the rendering and parsing is built in Rust for performance and exposed to Python
|
||||||
through thin [`pyo3`](https://pyo3.rs/) bindings.
|
through thin [`pyo3`](https://pyo3.rs/) bindings.
|
||||||
|
|
||||||
```
|
```text
|
||||||
┌──────────────────┐ ┌───────────────────────────┐
|
┌──────────────────┐ ┌───────────────────────────┐
|
||||||
│ Python code │ │ Rust core (this repo) │
|
│ Python code │ │ Rust core (this repo) │
|
||||||
│ (dataclasses, │────► │ • chat / encoding logic │
|
│ (dataclasses, │────► │ • chat / encoding logic │
|
||||||
|
@ -140,7 +140,7 @@ through thin [`pyo3`](https://pyo3.rs/) bindings.
|
||||||
|
|
||||||
### Repository layout
|
### Repository layout
|
||||||
|
|
||||||
```
|
```text
|
||||||
.
|
.
|
||||||
├── src/ # Rust crate
|
├── src/ # Rust crate
|
||||||
│ ├── chat.rs # High-level data-structures (Role, Message, …)
|
│ ├── chat.rs # High-level data-structures (Role, Message, …)
|
||||||
|
@ -177,10 +177,10 @@ source .venv/bin/activate
|
||||||
# Install maturin and test dependencies
|
# Install maturin and test dependencies
|
||||||
pip install maturin pytest mypy ruff # tailor to your workflow
|
pip install maturin pytest mypy ruff # tailor to your workflow
|
||||||
# Compile the Rust crate *and* install the Python package in editable mode
|
# Compile the Rust crate *and* install the Python package in editable mode
|
||||||
maturin develop -F python-binding --release
|
maturin develop --release
|
||||||
```
|
```
|
||||||
|
|
||||||
`maturin develop -F python-binding` builds _harmony_ with Cargo, produces a native extension
|
`maturin develop` builds _harmony_ with Cargo, produces a native extension
|
||||||
(`openai_harmony.<abi>.so`) and places it in your virtualenv next to the pure-
|
(`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.
|
Python wrapper – similar to `pip install -e .` for pure Python projects.
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ readme = "README.md"
|
||||||
demo = ["uvicorn", "fastapi"]
|
demo = ["uvicorn", "fastapi"]
|
||||||
|
|
||||||
[tool.maturin]
|
[tool.maturin]
|
||||||
features = ["pyo3/extension-module"]
|
features = ["python-binding", "pyo3/extension-module"]
|
||||||
module-name = "openai_harmony"
|
module-name = "openai_harmony"
|
||||||
python-source = "python"
|
python-source = "python"
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
#![doc = include_str!("../README.md")]
|
||||||
|
|
||||||
pub mod chat;
|
pub mod chat;
|
||||||
mod encoding;
|
mod encoding;
|
||||||
mod registry;
|
mod registry;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -e
|
set -e
|
||||||
source .venv/bin/activate
|
source .venv/bin/activate
|
||||||
maturin develop -F python-binding --release
|
maturin develop --release
|
||||||
pytest "$@"
|
pytest "$@"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue