use crate::models;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, bon::Builder)]
pub struct RunObject {
#[serde(rename = "id")]
pub id: String,
#[serde(rename = "object")]
pub object: Object,
#[serde(rename = "created_at")]
pub created_at: i32,
#[serde(rename = "thread_id")]
pub thread_id: String,
#[serde(rename = "assistant_id")]
pub assistant_id: String,
#[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>>,
#[serde(rename = "expires_at", deserialize_with = "Option::deserialize")]
pub expires_at: Option<i32>,
#[serde(rename = "started_at", deserialize_with = "Option::deserialize")]
pub started_at: Option<i32>,
#[serde(rename = "cancelled_at", deserialize_with = "Option::deserialize")]
pub cancelled_at: Option<i32>,
#[serde(rename = "failed_at", deserialize_with = "Option::deserialize")]
pub failed_at: Option<i32>,
#[serde(rename = "completed_at", deserialize_with = "Option::deserialize")]
pub completed_at: Option<i32>,
#[serde(rename = "incomplete_details")]
pub incomplete_details: Option<Box<models::RunObjectIncompleteDetails>>,
#[serde(rename = "model")]
pub model: String,
#[serde(rename = "instructions")]
pub instructions: String,
#[serde(rename = "tools")]
pub tools: Vec<models::AssistantObjectToolsInner>,
#[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>>,
#[serde(
rename = "temperature",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub temperature: Option<Option<f64>>,
#[serde(
rename = "top_p",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub top_p: Option<Option<f64>>,
#[serde(rename = "max_prompt_tokens", deserialize_with = "Option::deserialize")]
pub max_prompt_tokens: Option<i32>,
#[serde(
rename = "max_completion_tokens",
deserialize_with = "Option::deserialize"
)]
pub max_completion_tokens: Option<i32>,
#[serde(
rename = "truncation_strategy",
deserialize_with = "Option::deserialize"
)]
pub truncation_strategy: Option<Box<models::TruncationObject>>,
#[serde(rename = "tool_choice", deserialize_with = "Option::deserialize")]
pub tool_choice: Option<Box<models::AssistantsApiToolChoiceOption>>,
#[serde(rename = "parallel_tool_calls")]
pub parallel_tool_calls: bool,
#[serde(rename = "response_format", deserialize_with = "Option::deserialize")]
pub response_format: Option<Box<models::AssistantsApiResponseFormatOption>>,
}
impl RunObject {
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: Option<i32>,
started_at: Option<i32>,
cancelled_at: Option<i32>,
failed_at: Option<i32>,
completed_at: Option<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: Option<i32>,
max_completion_tokens: Option<i32>,
truncation_strategy: Option<models::TruncationObject>,
tool_choice: Option<models::AssistantsApiToolChoiceOption>,
parallel_tool_calls: bool,
response_format: Option<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: truncation_strategy.map(Box::new),
tool_choice: tool_choice.map(Box::new),
parallel_tool_calls,
response_format: response_format.map(Box::new),
}
}
}
#[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
}
}
#[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),
}
}
}