Module gemini

Module gemini 

Source
Expand description

The Google Gemini adapter (DW-075).

Speaks the Gemini generateContent API (POST /v1beta/models/{model}:generateContent โ€” note the model rides in the PATH, not the body, which is why ProviderAdapter::build_request takes the provider model explicitly). Translation notes:

  • System messages lift to systemInstruction.
  • Roles are user/model only; OpenAI tool results become user turns carrying a functionResponse part. Gemini requires the FUNCTION NAME there, while the OpenAI shape carries only the call id โ€” the adapter resolves the name by scanning backward through the conversation for the assistant tool_calls entry with that id, and falls back to the id itself when the history does not contain it (a client that invented a tool_call_id out of thin air).
  • Tool declarations become functionDeclarations; the JSON-Schema parameters object is passed through minus $schema (which Gemini rejects).
  • data: URI images become inline_data parts; remote image URLs have no Gemini equivalent in this API and are DROPPED (documented limitation of the translation, not a silent corruption โ€” the alternative, fetching the URL, is a side effect a gateway must not invent).
  • Finish reasons map STOP -> stop, MAX_TOKENS -> length, SAFETY/PROHIBITED_CONTENT -> content filter, RECITATION -> other. Usage maps promptTokenCount/candidatesTokenCount.
  • Streaming uses :streamGenerateContent?alt=sse; each SSE data payload is a GenerateContentResponse translated like a single-choice fragment.

Structsยง

GeminiAdapter
The Gemini generateContent adapter. Stateless singleton.