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)
|
format!("\n---\n{}", tool_prompt)
|
||||||
};
|
};
|
||||||
if let Some(last_message) = messages.last_mut() {
|
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)
|
Some(tools)
|
||||||
}
|
}
|
||||||
|
@ -1181,7 +1181,7 @@ pub struct Message {
|
|||||||
#[schema(example = "user")]
|
#[schema(example = "user")]
|
||||||
role: String,
|
role: String,
|
||||||
#[schema(example = "My name is David and I")]
|
#[schema(example = "My name is David and I")]
|
||||||
pub content: MessageContent,
|
pub content: Option<MessageContent>,
|
||||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||||
#[schema(example = "\"David\"")]
|
#[schema(example = "\"David\"")]
|
||||||
name: Option<String>,
|
name: Option<String>,
|
||||||
@ -1224,15 +1224,19 @@ impl From<Message> for TextMessage {
|
|||||||
TextMessage {
|
TextMessage {
|
||||||
role: value.role,
|
role: value.role,
|
||||||
content: match value.content {
|
content: match value.content {
|
||||||
MessageContent::SingleText(text) => text,
|
// If content is Some(MessageContent), handle it accordingly
|
||||||
MessageContent::MultipleChunks(chunks) => chunks
|
Some(MessageContent::SingleText(text)) => text,
|
||||||
.into_iter()
|
Some(MessageContent::MultipleChunks(chunks)) => {
|
||||||
|
chunks.into_iter()
|
||||||
.map(|chunk| match chunk {
|
.map(|chunk| match chunk {
|
||||||
MessageChunk::Text { text } => text,
|
MessageChunk::Text { text } => text,
|
||||||
MessageChunk::ImageUrl { image_url } => format!("", image_url.url),
|
MessageChunk::ImageUrl { image_url } => format!("", image_url.url),
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.join(""),
|
.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