import harmony_response as hr
def main():
try:
encoding_name = hr.HarmonyEncodingName.harmony_gpt_oss()
encoding = hr.load_harmony_encoding(encoding_name)
print(f"Loaded encoding: {encoding.name()}")
system_content = (hr.SystemContent()
.with_model_identity("Test Assistant")
.with_reasoning_effort(hr.ReasoningEffort.medium())
.with_required_channels(["analysis", "commentary", "final"])
.with_browser_tool())
system_msg = hr.Message.from_role_and_content(hr.Role.system(), system_content)
user_msg = hr.Message.from_role_and_content(hr.Role.user(), "What is 2 + 2?")
assistant_analysis = (hr.Message.from_role_and_content(hr.Role.assistant(), "This is basic arithmetic.")
.with_channel("analysis"))
assistant_final = (hr.Message.from_role_and_content(hr.Role.assistant(), "2 + 2 = 4")
.with_channel("final"))
conversation = hr.Conversation.from_messages([
system_msg,
user_msg,
assistant_analysis,
assistant_final,
])
print(f"Created conversation with {len(conversation)} messages")
tokens = encoding.render_conversation(conversation)
print(f"Rendered to {len(tokens)} tokens ready for OpenAI")
completion_tokens = encoding.render_conversation_for_completion(
conversation,
hr.Role.assistant()
)
print(f"Completion input tokens: {len(completion_tokens)}")
print("\n🎯 NEXT STEPS (You need to implement):")
print(" 1. Send completion_tokens to OpenAI's API")
print(" 2. Receive response_tokens from the model")
print(" 3. Use encoding.parse_messages_from_completion_tokens(response_tokens)")
print("✅ Formatting example completed successfully!")
except Exception as e:
print(f"❌ Error (expected without network): {e}")
if __name__ == "__main__":
main()