feat: reasoning_content in API for reasoning models (#6322)
Signed-off-by: Abhijay007 <Abhijay007j@gmail.com>
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user