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};

/// ChatCompletionResponseMessage : A chat completion message generated by the model.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, bon::Builder)]
pub struct ChatCompletionResponseMessage {
    /// The contents of the message.
    #[serde(rename = "content", deserialize_with = "Option::deserialize")]
    pub content: Option<String>,
    /// The refusal message generated by the model.
    #[serde(rename = "refusal", deserialize_with = "Option::deserialize")]
    pub refusal: Option<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>>>,
}

impl ChatCompletionResponseMessage {
    /// A chat completion message generated by the model.
    pub fn new(
        content: Option<String>,
        refusal: Option<String>,
        role: Role,
    ) -> ChatCompletionResponseMessage {
        ChatCompletionResponseMessage {
            content,
            refusal,
            tool_calls: None,
            annotations: None,
            role,
            function_call: None,
            audio: 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 ChatCompletionResponseMessage {
    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),
        }
    }
}