use serde::{Deserialize, Serialize};
use serde_json::{Map, Value};
use crate::{
adapter::ModelRequestParameters,
message::ModelMessage,
profile::{ModelProfile, StructuredOutputMode},
settings::{ModelSettings, ThinkingSettings},
};
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct PreparedModelRequest {
pub canonical_messages: Vec<ModelMessage>,
pub normalized_messages: Vec<ModelMessage>,
pub params: ModelRequestParameters,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub settings: Option<ModelSettings>,
pub profile: ModelProfile,
pub output_mode: OutputMode,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub thinking: Option<ThinkingSettings>,
#[serde(default, skip_serializing_if = "Map::is_empty")]
pub metadata: Map<String, Value>,
}
impl PreparedModelRequest {
pub(super) fn with_thinking_from_params(mut self) -> Self {
self.thinking = self.params.thinking.clone();
self
}
}
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum OutputMode {
Auto,
Text,
NativeJsonSchema,
NativeJsonObject,
Tool,
ToolOrText,
Prompted,
Image,
}
impl OutputMode {
#[must_use]
pub const fn from_structured_output_mode(mode: StructuredOutputMode) -> Self {
match mode {
StructuredOutputMode::NativeJsonSchema => Self::NativeJsonSchema,
StructuredOutputMode::NativeJsonObject => Self::NativeJsonObject,
StructuredOutputMode::Tool => Self::Tool,
StructuredOutputMode::Prompted => Self::Prompted,
}
}
}