Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,19 @@ openai-harmony = { git = "https://github.com/openai/harmony" }

```rust
use openai_harmony::chat::{Message, Role, Conversation};
use openai_harmony::{HarmonyEncodingName, load_harmony_encoding};
use openai_harmony::{
HarmonyEncodingName, RenderConversationConfig, 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)?;
let config = RenderConversationConfig {
auto_drop_analysis: false,
};
let tokens =
enc.render_conversation_for_completion(&convo, Role::Assistant, Some(&config))?;
println!("{:?}", tokens);
Ok(())
}
Expand Down
6 changes: 5 additions & 1 deletion docs/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ openai-harmony = { git = "https://github.com/openai/harmony" }
and import the items you need:

```rust
use openai_harmony::{load_harmony_encoding, HarmonyEncodingName};
use openai_harmony::{load_harmony_encoding, HarmonyEncodingName, RenderConversationConfig};
use openai_harmony::chat::{Message, Role, Conversation};
```

Expand Down Expand Up @@ -94,6 +94,10 @@ Important methods:

`ParseOptions` currently exposes a single field, `strict`, which defaults to `true`. Set it to `false` when you need to recover from malformed model output in downstream systems.

### `RenderConversationConfig`

Controls conversation rendering. Passing `None` preserves analysis content. To drop eligible prior analysis, pass `Some(&RenderConversationConfig::default())`; its `auto_drop_analysis` field defaults to `true`. Set the field to `false` to preserve analysis when passing a config explicitly.

### `StreamableParser`

Incremental parser that consumes tokens one by one. Create with `StreamableParser::new(encoding, role)` and feed tokens via `process`. Access information via getters like `current_content`, `current_role`, `messages`, `tokens` and `state_json`. Use `StreamableParser::new_with_options(encoding, role, options)` when you need to override defaults such as `ParseOptions { strict: false }`.
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mod registry;
mod tiktoken;
pub mod tiktoken_ext;

pub use encoding::{HarmonyEncoding, ParseOptions, StreamableParser};
pub use encoding::{HarmonyEncoding, ParseOptions, RenderConversationConfig, StreamableParser};
pub use registry::load_harmony_encoding;
pub use registry::HarmonyEncodingName;

Expand Down