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

/// RunObject : Represents an execution run on a [thread](/docs/api-reference/threads).
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, bon::Builder)]
pub struct RunObject {
    /// The identifier, which can be referenced in API endpoints.
    #[serde(rename = "id")]
    pub id: String,
    /// The object type, which is always `thread.run`.
    #[serde(rename = "object")]
    pub object: Object,
    /// The Unix timestamp (in seconds) for when the run was created.
    #[serde(rename = "created_at")]
    pub created_at: i32,
    /// The ID of the [thread](/docs/api-reference/threads) that was executed on as a part of this run.
    #[serde(rename = "thread_id")]
    pub thread_id: String,
    /// The ID of the [assistant](/docs/api-reference/assistants) used for execution of this run.
    #[serde(rename = "assistant_id")]
    pub assistant_id: String,
    /// The status of the run, which can be either `queued`, `in_progress`, `requires_action`, `cancelling`, `cancelled`, `failed`, `completed`, `incomplete`, or `expired`.
    #[serde(rename = "status")]
    pub status: Status,
    #[serde(rename = "required_action")]
    pub required_action: Option<Box<models::RunObjectRequiredAction>>,
    #[serde(rename = "last_error")]
    pub last_error: Option<Box<models::RunObjectLastError>>,
    /// The Unix timestamp (in seconds) for when the run will expire.
    #[serde(rename = "expires_at")]
    pub expires_at: i32,
    /// The Unix timestamp (in seconds) for when the run was started.
    #[serde(rename = "started_at")]
    pub started_at: i32,
    /// The Unix timestamp (in seconds) for when the run was cancelled.
    #[serde(rename = "cancelled_at")]
    pub cancelled_at: i32,
    /// The Unix timestamp (in seconds) for when the run failed.
    #[serde(rename = "failed_at")]
    pub failed_at: i32,
    /// The Unix timestamp (in seconds) for when the run was completed.
    #[serde(rename = "completed_at")]
    pub completed_at: i32,
    #[serde(rename = "incomplete_details")]
    pub incomplete_details: Option<Box<models::RunObjectIncompleteDetails>>,
    /// The model that the [assistant](/docs/api-reference/assistants) used for this run.
    #[serde(rename = "model")]
    pub model: String,
    /// The instructions that the [assistant](/docs/api-reference/assistants) used for this run.
    #[serde(rename = "instructions")]
    pub instructions: String,
    /// The list of tools that the [assistant](/docs/api-reference/assistants) used for this run.
    #[serde(rename = "tools")]
    pub tools: Vec<models::AssistantObjectToolsInner>,
    /// Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format, and querying for objects via API or the dashboard.  Keys are strings with a maximum length of 64 characters. Values are strings with a maximum length of 512 characters.
    #[serde(rename = "metadata", deserialize_with = "Option::deserialize")]
    pub metadata: Option<std::collections::HashMap<String, String>>,
    #[serde(rename = "usage", deserialize_with = "Option::deserialize")]
    pub usage: Option<Box<models::RunCompletionUsage>>,
    /// The sampling temperature used for this run. If not set, defaults to 1.
    #[serde(rename = "temperature", skip_serializing_if = "Option::is_none")]
    pub temperature: Option<f64>,
    /// The nucleus sampling value used for this run. If not set, defaults to 1.
    #[serde(rename = "top_p", skip_serializing_if = "Option::is_none")]
    pub top_p: Option<f64>,
    /// The maximum number of prompt tokens specified to have been used over the course of the run.
    #[serde(rename = "max_prompt_tokens")]
    pub max_prompt_tokens: i32,
    /// The maximum number of completion tokens specified to have been used over the course of the run.
    #[serde(rename = "max_completion_tokens")]
    pub max_completion_tokens: i32,
    #[serde(rename = "truncation_strategy")]
    pub truncation_strategy: Box<models::TruncationObject>,
    #[serde(rename = "tool_choice")]
    pub tool_choice: Box<models::AssistantsApiToolChoiceOption>,
    /// Whether to enable [parallel function calling](/docs/guides/function-calling#configuring-parallel-function-calling) during tool use.
    #[serde(rename = "parallel_tool_calls")]
    pub parallel_tool_calls: bool,
    #[serde(rename = "response_format")]
    pub response_format: Box<models::AssistantsApiResponseFormatOption>,
}

impl RunObject {
    /// Represents an execution run on a [thread](/docs/api-reference/threads).
    pub fn new(
        id: String,
        object: Object,
        created_at: i32,
        thread_id: String,
        assistant_id: String,
        status: Status,
        required_action: Option<models::RunObjectRequiredAction>,
        last_error: Option<models::RunObjectLastError>,
        expires_at: i32,
        started_at: i32,
        cancelled_at: i32,
        failed_at: i32,
        completed_at: i32,
        incomplete_details: Option<models::RunObjectIncompleteDetails>,
        model: String,
        instructions: String,
        tools: Vec<models::AssistantObjectToolsInner>,
        metadata: Option<std::collections::HashMap<String, String>>,
        usage: Option<models::RunCompletionUsage>,
        max_prompt_tokens: i32,
        max_completion_tokens: i32,
        truncation_strategy: models::TruncationObject,
        tool_choice: models::AssistantsApiToolChoiceOption,
        parallel_tool_calls: bool,
        response_format: models::AssistantsApiResponseFormatOption,
    ) -> RunObject {
        RunObject {
            id,
            object,
            created_at,
            thread_id,
            assistant_id,
            status,
            required_action: required_action.map(Box::new),
            last_error: last_error.map(Box::new),
            expires_at,
            started_at,
            cancelled_at,
            failed_at,
            completed_at,
            incomplete_details: incomplete_details.map(Box::new),
            model,
            instructions,
            tools,
            metadata,
            usage: usage.map(Box::new),
            temperature: None,
            top_p: None,
            max_prompt_tokens,
            max_completion_tokens,
            truncation_strategy: Box::new(truncation_strategy),
            tool_choice: Box::new(tool_choice),
            parallel_tool_calls,
            response_format: Box::new(response_format),
        }
    }
}
/// The object type, which is always `thread.run`.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum Object {
    #[serde(rename = "thread.run")]
    ThreadRun,
}

impl Default for Object {
    fn default() -> Object {
        Self::ThreadRun
    }
}
/// The status of the run, which can be either `queued`, `in_progress`, `requires_action`, `cancelling`, `cancelled`, `failed`, `completed`, `incomplete`, or `expired`.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum Status {
    #[serde(rename = "queued")]
    Queued,
    #[serde(rename = "in_progress")]
    InProgress,
    #[serde(rename = "requires_action")]
    RequiresAction,
    #[serde(rename = "cancelling")]
    Cancelling,
    #[serde(rename = "cancelled")]
    Cancelled,
    #[serde(rename = "failed")]
    Failed,
    #[serde(rename = "completed")]
    Completed,
    #[serde(rename = "incomplete")]
    Incomplete,
    #[serde(rename = "expired")]
    Expired,
}

impl Default for Status {
    fn default() -> Status {
        Self::Queued
    }
}

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