feat: reasoning_content in API for reasoning models (#6322)

Signed-off-by: Abhijay007 <Abhijay007j@gmail.com>
This commit is contained in:
Abhijay Jain
2026-02-12 20:48:44 +05:30
committed by GitHub
parent d1aa571871
commit 738f5f647c
14 changed files with 276 additions and 35 deletions
+19
View File
@@ -175,6 +175,11 @@ pub struct SystemNotificationContent {
pub data: Option<serde_json::Value>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ToSchema)]
pub struct ReasoningContent {
pub text: String,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ToSchema)]
/// Content passed inside a message, which can be both simple content and tool content
#[serde(tag = "type", rename_all = "camelCase")]
@@ -189,6 +194,7 @@ pub enum MessageContent {
Thinking(ThinkingContent),
RedactedThinking(RedactedThinkingContent),
SystemNotification(SystemNotificationContent),
Reasoning(ReasoningContent),
}
impl fmt::Display for MessageContent {
@@ -230,6 +236,7 @@ impl fmt::Display for MessageContent {
MessageContent::SystemNotification(r) => {
write!(f, "[SystemNotification: {}]", r.msg)
}
MessageContent::Reasoning(r) => write!(f, "[Reasoning: {}]", r.text),
}
}
}
@@ -443,6 +450,10 @@ impl MessageContent {
})
}
pub fn reasoning<S: Into<String>>(text: S) -> Self {
MessageContent::Reasoning(ReasoningContent { text: text.into() })
}
pub fn as_system_notification(&self) -> Option<&SystemNotificationContent> {
if let MessageContent::SystemNotification(ref notification) = self {
Some(notification)
@@ -514,6 +525,14 @@ impl MessageContent {
_ => None,
}
}
/// Get the reasoning content if this is a ReasoningContent variant
pub fn as_reasoning(&self) -> Option<&ReasoningContent> {
match self {
MessageContent::Reasoning(reasoning) => Some(reasoning),
_ => None,
}
}
}
impl From<Content> for MessageContent {