objectiveai 0.1.4

ObjectiveAI SDK, definitions, and utilities
Documentation
//! Message type for unary chat completion responses.

use crate::chat::completions::response;
use serde::{Deserialize, Serialize};

/// A message generated by the model.
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct Message {
    /// The text content of the message.
    pub content: Option<String>,
    /// A refusal message if the model declined to respond.
    pub refusal: Option<String>,
    /// The role of the message author (always "assistant").
    pub role: response::Role,
    /// Tool calls made by the model.
    pub tool_calls: Option<Vec<super::ToolCall>>,

    /// Reasoning/thinking output (for models that support it).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub reasoning: Option<String>,
    /// Generated images (for multimodal models).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub images: Option<Vec<response::Image>>,
}

impl From<response::streaming::Delta> for Message {
    fn from(
        response::streaming::Delta {
            content,
            refusal,
            role,
            tool_calls,
            reasoning,
            images,
        }: response::streaming::Delta,
    ) -> Self {
        Self {
            content,
            refusal,
            role: role.unwrap_or_default(),
            tool_calls: tool_calls.map(|tool_calls| {
                tool_calls.into_iter().map(super::ToolCall::from).collect()
            }),
            reasoning,
            images,
        }
    }
}