The Ai class currently builds every outbound request in OpenAI's
chat/completions shape, regardless of the configured provider.
This works for OpenAI-compatible backends (chatgpt, mistral, groq,
custom) but breaks the 'google' provider, whose native API differs
on all four key dimensions:
- URL path: /v1beta/models/<model>:generateContent
(not /v1beta/chat/completions)
- Payload root: 'contents' / 'parts' / optional 'system_instruction'
(not 'messages')
- Auth header: x-goog-api-key
(not Authorization: Bearer)
- Response shape: candidates[0].content.parts[*].text
(not choices[0].message.content)
As a result, every call to Gemini via Ai::generateContent() ended
with HTTP 404 (wrong path) or unparsed response data.
This patch makes Ai::generateContent() emit the native Gemini shape
when $this->apiService === 'google':
1. URL: after $model is resolved, suffix
/models/<urlencoded model>:generateContent
(and skip the /chat/completions suffix entirely for google)
2. Payload:
{
"contents": [
{"role": "user", "parts": [{"text": <full prompt>}]}
],
"system_instruction": {"parts": [{"text": <pre-prompt>}]}
}
3. Header: x-goog-api-key: <key> (no Bearer)
4. Response parsing: concatenate
candidates[0].content.parts[*].text
All other providers go through the existing OpenAI-compat branches
unchanged. No behavioral change for chatgpt, mistral, groq,
anthropic-compat, or custom endpoints.
Tested with: gemini-2.5-flash end-to-end via the AI Assistant web
UI (textgeneration). HTTP 200 with valid JSON output.
* New add ai feature to spell check
* fix translate
---------
Co-authored-by: Lucas Marcouiller <lmarcouiller@dolicloud.com>
Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>