file_uploads_processor.go

Overview

This source file provides specialized handling for file upload requests within the internal LLM (Large Language Model) integration layer. Specifically, it addresses compatibility issues with the Gemini API backend by modifying file upload requests to comply with its constraints. The Gemini API backend does not support the display_name parameter on file uploads, and this file ensures that any such fields are removed to prevent request failures.

The file contains utility logic that operates on LLM request data structures defined elsewhere in the system, modifying them in-place before the requests are sent to the backend.

Detailed Explanation

Package

Imports

Function: removeDisplayNameIfExists

func removeDisplayNameIfExists(ctx agent.InvocationContext, req *model.LLMRequest) error

Purpose

Removes the display_name field from all inline and file parts within the LLM request contents if the backend variant is Gemini API.

Parameters

Return Value

Behavior and Implementation Details

  1. Checks if the Contents field in the request is nil. If so, it returns immediately.

  2. Iterates over each content block in the request.

  3. For each content, checks if Parts exists; if missing, skips to next content.

  4. Checks if the current LLM variant is Gemini API by calling googlellm.GetGoogleLLMVariant().

  5. If the variant is Gemini API:

    • Iterates over each part in the content.

    • For parts containing InlineData, sets InlineData.DisplayName to an empty string.

    • For parts containing FileData, sets FileData.DisplayName to an empty string.

This logic ensures that requests sent to Gemini API exclude the unsupported display_name field, preventing backend request errors.

Example Usage

var llmReq model.LLMRequest
// llmReq is populated with contents that may include display names
err := removeDisplayNameIfExists(ctx, &llmReq)
if err != nil {
    // handle error (currently always nil)
}
// Proceed with sending llmReq to Gemini API backend

Important Implementation Details

Interaction with Other System Components

This function is likely called during the request preparation phase in the LLM agent pipeline, possibly integrated with Agent Invocation Context and LLM Integration and Agents for preprocessing requests before dispatch.

Mermaid Diagram

flowchart TD
A[LLMRequest] --> B[Contents]
B --> C[Content.Parts]
C --> D1[Part.InlineData]
C --> D2[Part.FileData]
subgraph GeminiAPI Check
E["googlellm.GetGoogleLLMVariant()"]
end
E -- "If Gemini API" --> F[Remove DisplayName fields]
F -->|InlineData| D1
F -->|FileData| D2
style A fill:#f9f,stroke:#333,stroke-width:1px
style F fill:#bbf,stroke:#333,stroke-width:1px

This diagram illustrates the structure of the LLMRequest and the conditional logic applied by removeDisplayNameIfExists to remove DisplayName fields from inline and file data parts when the Gemini API variant is detected.