diff --git a/router/src/infer/chat_template.rs b/router/src/infer/chat_template.rs index ceba14a6..a7bcea65 100644 --- a/router/src/infer/chat_template.rs +++ b/router/src/infer/chat_template.rs @@ -67,7 +67,9 @@ impl ChatTemplate { format!("\n---\n{}", tool_prompt) }; if let Some(last_message) = messages.last_mut() { - last_message.content.push(MessageChunk::Text { text }); + if let Some(content) = last_message.content.as_mut() { + content.push(MessageChunk::Text { text }); + } } Some(tools) } diff --git a/router/src/lib.rs b/router/src/lib.rs index ea697c3a..b143d314 100644 --- a/router/src/lib.rs +++ b/router/src/lib.rs @@ -1183,7 +1183,7 @@ pub struct Message { #[schema(example = "user")] role: String, #[schema(example = "My name is David and I")] - pub content: MessageContent, + pub content: Option, #[serde(default, skip_serializing_if = "Option::is_none")] #[schema(example = "\"David\"")] name: Option, @@ -1226,15 +1226,19 @@ impl From for TextMessage { TextMessage { role: value.role, content: match value.content { - MessageContent::SingleText(text) => text, - MessageContent::MultipleChunks(chunks) => chunks - .into_iter() - .map(|chunk| match chunk { - MessageChunk::Text { text } => text, - MessageChunk::ImageUrl { image_url } => format!("![]({})", image_url.url), - }) - .collect::>() - .join(""), + // If content is Some(MessageContent), handle it accordingly + Some(MessageContent::SingleText(text)) => text, + Some(MessageContent::MultipleChunks(chunks)) => { + chunks.into_iter() + .map(|chunk| match chunk { + MessageChunk::Text { text } => text, + MessageChunk::ImageUrl { image_url } => format!("![]({})", image_url.url), + }) + .collect::>() + .join("") + } + // If content is None, use an empty string or a default message + None => String::new(), // or you could use "No content" or another placeholder }, } }