gh_models 0.2.0

A Rust client for GitHub-hosted AI models, compatible with the models.github.ai chat completion API.
Documentation
//! # types
//!
//! Core data structures used for interacting with the GitHub Models API.
//!
//! This module defines the request and response types for chat-based model inference,
//! including message formatting and response parsing. These types are used by the
//! `GHModels` client to send prompts and receive completions.

use serde::{Deserialize, Serialize};

/// Represents a single message in a chat conversation.
///
/// Each message has a `role` (e.g., `"system"`, `"user"`, or `"assistant"`)
/// and a `content` string containing the message text.
#[derive(Clone, Serialize, Deserialize)]
pub struct ChatMessage {
    /// The role of the message sender (e.g., `"system"`, `"user"`, `"assistant"`).
    pub role: String,

    /// The textual content of the message.
    pub content: String,
}

/// The top-level response returned from the GitHub Models API.
///
/// Contains a list of `ChatChoice` objects representing possible completions.
///
/// # Example
/// ```rust
/// let response: ChatResponse = client.chat_completion(...).await.unwrap();
/// for choice in response.choices {
///     println!("{}", choice.message.content);
/// }
/// ```
#[derive(Deserialize)]
pub struct ChatResponse {
    /// A list of completion choices returned by the model.
    pub choices: Vec<ChatChoice>,
}

/// Represents a single completion choice returned by the model.
///
/// Each choice contains a `ChatMessage` with the model's response.
///
/// # Example
/// ```rust
/// let choice: &ChatChoice = &response.choices[0];
/// println!("Model replied: {}", choice.message.content);
/// ```
#[derive(Deserialize)]
pub struct ChatChoice {
    /// The message generated by the model for this choice.
    pub message: ChatMessage,
}