Module message

Source
Expand description

Message types and conversation handling. Message types for AI language model conversations.

This module provides types for representing messages in conversations with AI language models. Messages can have different roles (User, Assistant, System, Tool), contain text content, and optionally include attachments and annotations.

§Examples

§Creating basic messages

use ai_types::llm::{Message, Role};

// Using convenience constructors
let user_msg = Message::user("Hello, how are you?");
let assistant_msg = Message::assistant("I'm doing well, thank you!");
let system_msg = Message::system("You are a helpful assistant.");

// Using the general constructor
let tool_msg = Message::new(Role::Tool, "Tool executed successfully".into());

§Adding attachments

use ai_types::llm::Message;
use url::Url;

let message = Message::user("Check out this image")
    .with_attachment("https://example.com/image.jpg".parse::<Url>().unwrap());

let urls = [
    "https://example.com/doc1.pdf".parse::<Url>().unwrap(),
    "https://example.com/doc2.pdf".parse::<Url>().unwrap(),
];
let message_with_multiple = Message::user("Review these documents")
    .with_attachments(urls);

§Working with annotations

use ai_types::llm::{Message, Annotation, UrlAnnotation};
use url::Url;

let annotation =Annotation::url(
    "https://example.com",
    "Example Site",
    "A useful example website",
    6,  // start index of URL in content
    25, // end index of URL in content
);

let message = Message::user("Visit https://example.com for examples")
    .with_annotation(annotation);

Structs§

Message
A message in a conversation.
UrlAnnotation
URL annotation metadata.

Enums§

Annotation
Message annotation.
Role
Conversation participant role.