mirror of
https://github.com/huggingface/text-generation-inference.git
synced 2025-06-19 15:52:08 +00:00
make content field optional in chat request
This commit is contained in:
parent
230aa25641
commit
e14617d88d
@ -74,7 +74,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)
|
||||
}
|
||||
|
@ -1181,7 +1181,7 @@ pub struct Message {
|
||||
#[schema(example = "user")]
|
||||
role: String,
|
||||
#[schema(example = "My name is David and I")]
|
||||
pub content: MessageContent,
|
||||
pub content: Option<MessageContent>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
#[schema(example = "\"David\"")]
|
||||
name: Option<String>,
|
||||
@ -1224,15 +1224,19 @@ impl From<Message> 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::<Vec<_>>()
|
||||
.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::<Vec<_>>()
|
||||
.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
|
||||
},
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user