feat: add image support across all endpoints (responses, completions, gemini)
This commit is contained in:
@@ -82,10 +82,13 @@ fn google_to_openai_finish_reason(stop_reason: Option<&str>) -> &'static str {
|
||||
/// Builds the full conversation context including all messages (system, user,
|
||||
/// assistant, tool) so the model has complete history — matching how OpenAI
|
||||
/// sends the entire messages array to the model.
|
||||
fn extract_chat_input(messages: &[CompletionMessage]) -> String {
|
||||
// Always build the full conversation — we used to only take the last user
|
||||
// message which broke multi-turn conversations via the messages array.
|
||||
build_conversation_with_tools(messages)
|
||||
fn extract_chat_input(messages: &[CompletionMessage]) -> (String, Option<crate::proto::ImageData>) {
|
||||
// Extract image from last user message content array
|
||||
let image = messages.iter().rev()
|
||||
.find(|m| m.role == "user")
|
||||
.and_then(|m| super::util::extract_first_image(&m.content));
|
||||
// Always build the full conversation
|
||||
(build_conversation_with_tools(messages), image)
|
||||
}
|
||||
|
||||
/// Extract text content from a message's content field (string or array).
|
||||
@@ -257,7 +260,7 @@ pub(crate) async fn handle_completions(
|
||||
);
|
||||
}
|
||||
|
||||
let user_text = extract_chat_input(&body.messages);
|
||||
let (user_text, image) = extract_chat_input(&body.messages);
|
||||
if user_text.is_empty() {
|
||||
return err_response(
|
||||
StatusCode::BAD_REQUEST,
|
||||
@@ -302,7 +305,7 @@ pub(crate) async fn handle_completions(
|
||||
state.mitm_store.set_active_cascade(&cascade_id).await;
|
||||
match state
|
||||
.backend
|
||||
.send_message(&cascade_id, &user_text, model.model_enum)
|
||||
.send_message_with_image(&cascade_id, &user_text, model.model_enum, image.as_ref())
|
||||
.await
|
||||
{
|
||||
Ok((200, _)) => {
|
||||
@@ -361,7 +364,7 @@ pub(crate) async fn handle_completions(
|
||||
match state.backend.create_cascade().await {
|
||||
Ok(cid) => {
|
||||
// Send the same message on each extra cascade
|
||||
match state.backend.send_message(&cid, &user_text, model.model_enum).await {
|
||||
match state.backend.send_message_with_image(&cid, &user_text, model.model_enum, image.as_ref()).await {
|
||||
Ok((200, _)) => {
|
||||
let bg = Arc::clone(&state.backend);
|
||||
let cid2 = cid.clone();
|
||||
|
||||
Reference in New Issue
Block a user