Skip to content

Commit

Permalink
Inject image token if not present for oai image messages (EricLBuehle…
Browse files Browse the repository at this point in the history
  • Loading branch information
bioshazard committed Dec 29, 2024
1 parent d722164 commit e14384d
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions mistralrs-server/src/chat_completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,16 @@ async fn parse_request(
if image_messages[text_idx]["text"].is_right() {
anyhow::bail!("Expected string value in `text`.");
}
let mut content = image_messages[text_idx]["text"]
let content_original = image_messages[text_idx]["text"]
.as_ref()
.unwrap_left()
.clone();
if !content.contains("<|image|>") {
content = format!("<|image|> {}", content.trim());
}
.unwrap_left(); // Borrow `content` immutably.

let content = if !content_original.contains("<|image|>") {
format!("<|image|> {}", content_original.trim())
} else {
content_original.to_string()
};

if image_messages[url_idx]["image_url"].is_left()
|| !image_messages[url_idx]["image_url"]
.as_ref()
Expand Down

0 comments on commit e14384d

Please sign in to comment.