Crate umf

Crate umf 

Source
Expand description

Universal Message Format (UMF)

This crate provides a provider-agnostic message representation for LLM interactions. It follows the OpenAI-compatible JSON structure as the foundation while supporting conversion to any LLM provider format (Anthropic, Google Gemini, Cohere, etc.).

§Core Principles

  1. OpenAI-Compatible Base: The format follows OpenAI’s JSON structure
  2. Provider-Agnostic: Can be converted to any LLM provider format
  3. Metadata Support: Includes optional metadata for internal tracking
  4. Tool Calling Support: Full support for function/tool calling

§Usage

use umf::{InternalMessage, MessageRole, ContentBlock};

// Create a simple text message
let msg = InternalMessage::user("Hello, world!");

// Create a message with tool calls
let msg = InternalMessage::assistant_with_tools(
    "Let me search for that",
    vec![ContentBlock::tool_use("call_123", "search", serde_json::json!({"q": "rust"}))],
);

Re-exports§

pub use chatml::ChatMLFormatter;
pub use chatml::ChatMLMessage;
pub use chatml::MessageRole as ChatMLMessageRole;

Modules§

chatml
ChatML message formatter for simpaticoder.

Structs§

Function
Function definition for tools
FunctionCall
Function call structure for tool invocations
InternalMessage
A message in the internal format
Tool
Tool definition for OpenAI-compatible tools
ToolCall
Tool call structure for function calling

Enums§

ContentBlock
A content block within a message
GenerateResult
Result of generation with tools
ImageSource
Image source for image blocks
MessageContent
Message content (text or structured blocks)
MessageRole
Message role in a conversation