openai-client-base 0.16.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};

/// FunctionCallOutputItemResource : The result supplied for a function call.
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize, bon::Builder)]
pub struct FunctionCallOutputItemResource {
    /// The ID of the function call output item.
    #[serde(rename = "id")]
    pub id: String,
    /// The ID of the turn that contains this item.
    #[serde(rename = "turn_id")]
    pub turn_id: String,
    /// The item type. Always `function_call_output`.
    #[serde(rename = "type")]
    pub r#type: Type,
    /// The ID of the function call that produced this output.
    #[serde(rename = "call_id")]
    pub call_id: String,
    #[serde(rename = "status")]
    pub status: models::FunctionCallStatusResource,
    #[serde(rename = "output", deserialize_with = "Option::deserialize")]
    pub output: Option<Box<models::FunctionCallOutputResource>>,
    /// The error message, if the call failed.
    #[serde(rename = "error", deserialize_with = "Option::deserialize")]
    pub error: Option<String>,
}

impl FunctionCallOutputItemResource {
    /// The result supplied for a function call.
    pub fn new(
        id: String,
        turn_id: String,
        r#type: Type,
        call_id: String,
        status: models::FunctionCallStatusResource,
        output: Option<models::FunctionCallOutputResource>,
        error: Option<String>,
    ) -> FunctionCallOutputItemResource {
        FunctionCallOutputItemResource {
            id,
            turn_id,
            r#type,
            call_id,
            status,
            output: output.map(Box::new),
            error,
        }
    }
}
/// The item type. Always `function_call_output`.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum Type {
    #[serde(rename = "function_call_output")]
    FunctionCallOutput,
}

impl Default for Type {
    fn default() -> Type {
        Self::FunctionCallOutput
    }
}

impl std::fmt::Display for FunctionCallOutputItemResource {
    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),
        }
    }
}