openai-client-base 0.12.0

Auto-generated Rust client for the OpenAI API
/*
 * OpenAI API
 *
 * The OpenAI REST API. Please see https://platform.openai.com/docs/api-reference for more details.
 *
 * The version of the OpenAPI document: 2.3.0
 *
 * Generated by: https://openapi-generator.tech
 */

use crate::models;
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, bon::Builder)]
pub struct ChatCompletionMessageListDataInner {
    /// The contents of the message.
    #[serde(rename = "content")]
    pub content: String,
    /// The refusal message generated by the model.
    #[serde(rename = "refusal")]
    pub refusal: String,
    /// The tool calls generated by the model, such as function calls.
    #[serde(rename = "tool_calls", skip_serializing_if = "Option::is_none")]
    pub tool_calls: Option<Vec<models::ChatCompletionMessageToolCallsInner>>,
    /// Annotations for the message, when applicable, as when using the [web search tool](/docs/guides/tools-web-search?api-mode=chat).
    #[serde(rename = "annotations", skip_serializing_if = "Option::is_none")]
    pub annotations: Option<Vec<models::ChatCompletionResponseMessageAnnotationsInner>>,
    /// The role of the author of this message.
    #[serde(rename = "role")]
    pub role: Role,
    #[serde(rename = "function_call", skip_serializing_if = "Option::is_none")]
    pub function_call: Option<Box<models::ChatCompletionResponseMessageFunctionCall>>,
    #[serde(
        rename = "audio",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub audio: Option<Option<Box<models::Object03>>>,
    /// The identifier of the chat message.
    #[serde(rename = "id")]
    pub id: String,
    /// If a content parts array was provided, this is an array of `text` and `image_url` parts. Otherwise, null.
    #[serde(
        rename = "content_parts",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub content_parts:
        Option<Option<Vec<models::ChatCompletionMessageListDataInnerAllOfContentPartsInner>>>,
}

impl ChatCompletionMessageListDataInner {
    pub fn new(
        content: String,
        refusal: String,
        role: Role,
        id: String,
    ) -> ChatCompletionMessageListDataInner {
        ChatCompletionMessageListDataInner {
            content,
            refusal,
            tool_calls: None,
            annotations: None,
            role,
            function_call: None,
            audio: None,
            id,
            content_parts: None,
        }
    }
}
/// The role of the author of this message.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum Role {
    #[serde(rename = "assistant")]
    Assistant,
}

impl Default for Role {
    fn default() -> Role {
        Self::Assistant
    }
}

impl std::fmt::Display for ChatCompletionMessageListDataInner {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match serde_json::to_string(self) {
            Ok(s) => write!(f, "{}", s),
            Err(_) => Err(std::fmt::Error),
        }
    }
}