New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: improve message content chunks handling #1845
Conversation
**note this PR improves how images are handle when sent as separate content in the chat endpoint. If example request from huggingface_hub import InferenceClient
client = InferenceClient("http://127.0.0.1:3000")
chat = client.chat_completion(
messages=[
{
"role": "user",
"content": [
{"type": "text", "text": "Whats in this image?"},
{
"type": "image_url",
"image_url": {
"url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/rabbit.png"
},
},
],
},
],
seed=42,
max_tokens=100,
) |
Can you add some tests too for the deserialization ? |
updates: this pr now also parses markdown images into typed for example both the string and structured JSON inputs are deserialized into text-generation-inference/router/src/lib.rs Lines 1277 to 1288 in f8be8d5
and text-generation-inference/router/src/lib.rs Lines 1300 to 1319 in f8be8d5
|
|
||
fn parse_markdown_to_chunks(s: &str) -> Result<Vec<ContentChunk>, serde_json::Error> { | ||
let mut chunks = Vec::new(); | ||
let re = Regex::new(r"!\[([^\]]*)\]\(([^)]+)\)").unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is exactly what we do not want.
closing in favor of #1906 |
This PR improves the parsing of content in messages by deserializing all content into
ContentChunks
(a vector ofContentChunk
). EachContentChunk
is an enum representing either raw text or an image URL. For minimal change impact, ContentChunks can be serialized directly into a flattened string.