fix(#5626): handle multi-text content better for openai format models#5838
fix(#5626): handle multi-text content better for openai format models#5838alexhancock wants to merge 1 commit intomainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where messages containing multiple text content blocks were incorrectly handled in the OpenAI format provider. Previously, when multiple text chunks were present in a single message, only the last chunk would be retained. The fix accumulates all text parts and joins them with newlines, ensuring all content is preserved.
Key Changes:
- Accumulate text blocks in a
text_partsvector instead of overwritingconverted["content"] - Join accumulated text blocks with newlines after processing all content
- Add test coverage for multiple text block scenarios
| if let Some(image_path) = detect_image_path(&text.text) { | ||
| // Try to load and convert the image | ||
| if let Ok(image) = load_image_file(image_path) { | ||
| converted["content"] = json!([ | ||
| {"type": "text", "text": text.text}, | ||
| convert_image(&image, image_format) | ||
| ]); |
There was a problem hiding this comment.
When an image path is detected and successfully loaded (lines 72-77), this code directly assigns to converted["content"], which will overwrite any previously accumulated text_parts. This breaks the fix for multiple text content chunks.
If a message has multiple text blocks and one contains an image path, only the text with the image will be included, losing the other text blocks. Consider accumulating the text in text_parts and handling the image separately, or restructuring to build the content array incrementally.
|
Closing in favor of #5839 which had some similar code to fix images in acp |
We weren't properly handling when messages have multiple text chunks in
providers/formats/openai.rsThis surfaced in #5626 when encountering a message with content like this:
Previously when a message contained multiple text content chunks, we would overwrite the earlier ones and replace them with the last one. So this message
what does this code do?would lead to an answer likewhat code?Example
Before:
After: