use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use super::common::ReasoningEffort;
use super::input::ResponseInput;
use super::tools::{ResponseTool, ResponseToolChoice};
pub use super::common::ReasoningSummary;
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
pub struct Reasoning {
#[serde(default)]
#[serde(skip_serializing_if = "Option::is_none")]
pub effort: Option<ReasoningEffort>,
#[serde(default)]
#[serde(skip_serializing_if = "Option::is_none")]
pub summary: Option<ReasoningSummary>,
}
impl Reasoning {
pub fn effort(&mut self, effort: ReasoningEffort) -> &mut Self {
self.effort = Some(effort);
self
}
pub fn summary(&mut self, summary: ReasoningSummary) -> &mut Self {
self.summary = Some(summary);
self
}
pub fn build(&self) -> Result<Self, String> {
Ok(self.clone())
}
}
pub type ReasoningArgs = Reasoning;
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
pub struct ResponseTextConfig {
#[serde(default)]
#[serde(skip_serializing_if = "Option::is_none")]
pub format: Option<ResponseTextFormat>,
#[serde(default)]
#[serde(skip_serializing_if = "Option::is_none")]
pub verbosity: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
#[serde(tag = "type")]
#[non_exhaustive]
pub enum ResponseTextFormat {
#[serde(rename = "text")]
Text,
#[serde(rename = "json_object")]
JsonObject,
#[serde(rename = "json_schema")]
JsonSchema {
name: String,
#[serde(default)]
#[serde(skip_serializing_if = "Option::is_none")]
description: Option<String>,
#[serde(default)]
#[serde(skip_serializing_if = "Option::is_none")]
schema: Option<serde_json::Value>,
#[serde(default)]
#[serde(skip_serializing_if = "Option::is_none")]
strict: Option<bool>,
},
}
#[derive(Debug, Clone, Default, Serialize)]
#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
pub struct ResponseCreateRequest {
#[serde(default)]
pub model: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub input: Option<ResponseInput>,
#[serde(skip_serializing_if = "Option::is_none")]
pub instructions: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub tools: Option<Vec<ResponseTool>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub tool_choice: Option<ResponseToolChoice>,
#[serde(skip_serializing_if = "Option::is_none")]
pub parallel_tool_calls: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub previous_response_id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub temperature: Option<f64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub top_p: Option<f64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub max_output_tokens: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub truncation: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub reasoning: Option<Reasoning>,
#[serde(skip_serializing_if = "Option::is_none")]
pub store: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub metadata: Option<HashMap<String, String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub include: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub stream: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub service_tier: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub user: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub text: Option<ResponseTextConfig>,
#[serde(skip_serializing_if = "Option::is_none")]
pub prompt_cache_key: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub prompt_cache_retention: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub background: Option<bool>,
}
impl ResponseCreateRequest {
pub fn new(model: impl Into<String>) -> Self {
Self {
model: model.into(),
..Default::default()
}
}
pub fn input(mut self, input: impl Into<ResponseInput>) -> Self {
self.input = Some(input.into());
self
}
pub fn instructions(mut self, instructions: impl Into<String>) -> Self {
self.instructions = Some(instructions.into());
self
}
pub fn tools(mut self, tools: Vec<ResponseTool>) -> Self {
self.tools = Some(tools);
self
}
pub fn tool_choice(mut self, choice: ResponseToolChoice) -> Self {
self.tool_choice = Some(choice);
self
}
pub fn previous_response_id(mut self, id: impl Into<String>) -> Self {
self.previous_response_id = Some(id.into());
self
}
pub fn temperature(mut self, temperature: f64) -> Self {
self.temperature = Some(temperature);
self
}
pub fn max_output_tokens(mut self, max: i64) -> Self {
self.max_output_tokens = Some(max);
self
}
pub fn reasoning(mut self, reasoning: Reasoning) -> Self {
self.reasoning = Some(reasoning);
self
}
pub fn truncation(mut self, truncation: impl Into<String>) -> Self {
self.truncation = Some(truncation.into());
self
}
pub fn store(mut self, store: bool) -> Self {
self.store = Some(store);
self
}
pub fn model(mut self, model: impl Into<String>) -> Self {
self.model = model.into();
self
}
pub fn text(mut self, text: ResponseTextConfig) -> Self {
self.text = Some(text);
self
}
pub fn top_p(mut self, top_p: f64) -> Self {
self.top_p = Some(top_p);
self
}
pub fn parallel_tool_calls(mut self, parallel: bool) -> Self {
self.parallel_tool_calls = Some(parallel);
self
}
pub fn metadata(mut self, metadata: HashMap<String, String>) -> Self {
self.metadata = Some(metadata);
self
}
pub fn include(mut self, include: Vec<String>) -> Self {
self.include = Some(include);
self
}
pub fn service_tier(mut self, tier: impl Into<String>) -> Self {
self.service_tier = Some(tier.into());
self
}
pub fn user(mut self, user: impl Into<String>) -> Self {
self.user = Some(user.into());
self
}
pub fn prompt_cache_key(mut self, key: impl Into<String>) -> Self {
self.prompt_cache_key = Some(key.into());
self
}
pub fn prompt_cache_retention(mut self, retention: impl Into<String>) -> Self {
self.prompt_cache_retention = Some(retention.into());
self
}
pub fn background(mut self, background: bool) -> Self {
self.background = Some(background);
self
}
}
pub type CreateResponse = ResponseCreateRequest;
pub type CreateResponseArgs = ResponseCreateRequest;