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

/// BetaFunctionTool : Defines a function in your own code the model can choose to call. Learn more about [function calling](https://developers.openai.com/api/docs/guides/function-calling).
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize, bon::Builder)]
pub struct BetaFunctionTool {
    /// The type of the function tool. Always `function`.
    #[serde(rename = "type")]
    pub r#type: Type,
    /// The name of the function to call.
    #[serde(rename = "name")]
    pub name: String,
    #[serde(rename = "async", skip_serializing_if = "Option::is_none")]
    pub r#async: Option<bool>,
    /// A description of the function. Used by the model to determine whether or not to call the function.
    #[serde(
        rename = "description",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub description: Option<Option<String>>,
    /// A JSON schema object describing the parameters of the function.
    #[serde(rename = "parameters", deserialize_with = "Option::deserialize")]
    pub parameters: Option<std::collections::HashMap<String, serde_json::Value>>,
    /// A JSON schema object describing the JSON value encoded in string outputs for this function.
    #[serde(
        rename = "output_schema",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub output_schema: Option<Option<std::collections::HashMap<String, serde_json::Value>>>,
    /// Whether strict parameter validation is enforced for this function tool.
    #[serde(rename = "strict", deserialize_with = "Option::deserialize")]
    pub strict: Option<bool>,
    /// Whether this function is deferred and loaded via tool search.
    #[serde(rename = "defer_loading", skip_serializing_if = "Option::is_none")]
    pub defer_loading: Option<bool>,
    /// The tool invocation context(s).
    #[serde(
        rename = "allowed_callers",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub allowed_callers: Option<Option<Vec<models::BetaCallableToolAllowedCaller>>>,
}

impl BetaFunctionTool {
    /// Defines a function in your own code the model can choose to call. Learn more about [function calling](https://developers.openai.com/api/docs/guides/function-calling).
    pub fn new(
        r#type: Type,
        name: String,
        parameters: Option<std::collections::HashMap<String, serde_json::Value>>,
        strict: Option<bool>,
    ) -> BetaFunctionTool {
        BetaFunctionTool {
            r#type,
            name,
            r#async: None,
            description: None,
            parameters,
            output_schema: None,
            strict,
            defer_loading: None,
            allowed_callers: None,
        }
    }
}
/// The type of the function tool. Always `function`.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum Type {
    #[serde(rename = "function")]
    Function,
}

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

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