use harmony_response::{
chat::{Conversation, Message, Role, SystemContent},
load_harmony_encoding, HarmonyEncodingName,
};
fn main() -> anyhow::Result<()> {
println!("🦀 Harmony Response Format - Basic Usage Example");
println!("================================================");
println!("\n📝 Step 1: Creating messages");
let system_content = SystemContent::new()
.with_model_identity("Example Assistant")
.with_required_channels(["analysis", "commentary", "final"]);
let system_msg = Message::from_role_and_content(Role::System, system_content);
println!("✓ Created system message with identity and channels");
let user_msg = Message::from_role_and_content(Role::User, "Hello, world!");
println!("✓ Created user message: 'Hello, world!'");
let assistant_msg = Message::from_role_and_content(Role::Assistant, "Hello! How can I help you today?")
.with_channel("final");
println!("✓ Created assistant message with 'final' channel");
println!("\n💬 Step 2: Creating conversation");
let conversation = Conversation::from_messages([system_msg, user_msg, assistant_msg]);
println!("✓ Created conversation with {} messages", conversation.messages.len());
println!("\n🔧 Step 3: Loading encoding");
match load_harmony_encoding(HarmonyEncodingName::HarmonyGptOss) {
Ok(encoding) => {
println!("✅ Successfully loaded encoding: {}", encoding.name());
println!(" Tokenizer: {}", encoding.tokenizer_name());
println!(" Max tokens: {}", encoding.max_message_tokens());
println!("\n🎨 Step 4: Rendering conversation");
let tokens = encoding.render_conversation(&conversation, None)?;
println!("✓ Rendered conversation to {} tokens", tokens.len());
let completion_tokens = encoding
.render_conversation_for_completion(&conversation, Role::Assistant, None)?;
println!("✓ Rendered for completion: {} tokens", completion_tokens.len());
let training_tokens = encoding
.render_conversation_for_training(&conversation, None)?;
println!("✓ Rendered for training: {} tokens", training_tokens.len());
println!("\n📊 Token preview (first 10 tokens ready for OpenAI):");
for (i, &token) in tokens.iter().take(10).enumerate() {
println!(" {}: {}", i, token);
}
if tokens.len() > 10 {
println!(" ... and {} more tokens", tokens.len() - 10);
}
println!("\n🎯 NEXT STEPS (You need to implement):");
println!(" 1. Send these tokens to OpenAI's API (or compatible model)");
println!(" 2. Receive response tokens from the model");
println!(" 3. Use this library to parse response tokens back to messages");
println!(" Example: let messages = encoding.parse_messages_from_completion_tokens(response_tokens, Some(Role::Assistant))?;");
println!("\n🎉 Formatting example completed successfully!");
}
Err(e) => {
println!("⚠️ Encoding load failed (expected without network access)");
println!(" Error: {}", e);
println!(" This is normal in environments without internet connectivity.");
println!(" The conversation structure was created successfully!");
}
}
Ok(())
}