Widgets

AIChat

Chat interface widget for AI applications.

Overview

The AIChat widget provides a complete chat interface for building conversational AI applications in the terminal.

Basic Usage

use ratkit::widgets::ai_chat::{AIChat, ChatState, Message};
use ratatui::Frame;

fn render_chat(frame: &mut Frame) {
    let messages = vec![
        Message::user("Hello, can you help me?"),
        Message::assistant("Of course! What would you like to know?"),
    ];
    
    let chat = AIChat::new(messages);
    let mut state = ChatState::default();
    
    frame.render_stateful_widget(chat, frame.area(), &mut state);
}

Features

  • Message types - User, assistant, and system messages
  • Streaming support - Real-time message updates
  • Input area - Built-in text input with history
  • Scrollback - View message history
  • Markdown rendering - Rich message formatting

Customization

let chat = AIChat::new(messages)
    .user_style(Style::default().fg(Color::Blue))
    .assistant_style(Style::default().fg(Color::Green))
    .show_timestamps(true)
    .max_messages(100);