Commit graph

56 commits

Author SHA1 Message Date
Pichinov-Jose
5d851934d5
Fix: Ai::generateContent uses Google Gemini native API for google provider (#38296)
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.
2026-05-18 01:17:39 +02:00
Laurent Destailleur
07d282daad Fix spellchecker AI tool 2026-05-07 12:11:48 +02:00
Laurent Destailleur
8aa00a8908 Clean code. Add comment on fields. Use the correct rounding param. 2026-04-27 14:13:45 +02:00
Laurent Destailleur
1a1031e209 Merge branch '23.0' of git@github.com:Dolibarr/dolibarr.git into develop 2026-04-23 13:54:04 +02:00
Laurent Destailleur
93eeeb8946 FIX Can use AI module to make SSRF call. Report by Dilip
<dilipchowdary21@gmail.com>
2026-04-23 12:27:36 +02:00
Laurent Destailleur
30430e1674 NEW Enable AI tools on the message editor for tickets 2026-04-20 12:34:18 +02:00
Lucas Marcouiller
0e5cb22cf1
NEW add ai feature to spell check (#37692)
* 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>
2026-04-03 05:11:14 +02:00
Laurent Destailleur
f1d6371da5
Fix typo in AI_DEFAULT_PROMPT_FOR_DOC_PARSING 2026-04-03 03:56:38 +02:00
Laurent Destailleur
531c55a9fd NEW Show example of ai models in setup 2026-03-12 21:13:49 +01:00
ldestailleur
34a34efec5 Enhance AI setup and log report 2025-09-20 15:01:26 +02:00
ldestailleur
a7191abb11 Better log 2025-07-19 18:19:56 +02:00
ldestailleur
55ed1de694 Debug v22. Try to report error on screen for more case - #34463 2025-07-19 18:14:06 +02:00
Laurent Destailleur
a993ef3b00 Debug v22 2025-06-11 03:56:29 +02:00
Laurent Destailleur
333a32ba97 CSS 2025-06-11 03:30:34 +02:00
ldestailleur
95519edb78 Debug v22 2025-05-28 09:57:46 +02:00
Lucas Marcouiller
0f8b0da651
New AI extrafield filler (#33979)
* New ai extrafield filler

* remove comment

* Fix Ci

---------

Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
2025-04-26 01:59:36 +02:00
ldestailleur
8bdd6dff07 Debug v22 2025-04-09 23:03:22 +02:00
ldestailleur
f9355dd04b enhance AI 2025-04-08 23:18:23 +02:00
ldestailleur
6b11ed0187 Fix CI 2025-04-08 21:50:04 +02:00
ldestailleur
1bb7edea8b Enhance AI features 2025-04-08 11:42:46 +02:00
ldestailleur
936e35a767 Enhance AI setup. 2025-04-07 20:29:38 +02:00
ldestailleur
ef95c311a7 Merge branch '21.0' of git@github.com:Dolibarr/dolibarr.git into develop 2025-04-03 21:09:46 +02:00
ldestailleur
174d6497b3 Signed-off-by: ldestailleur <eldy@destailleur.fr> 2025-04-03 21:04:35 +02:00
John BOTELLA
038008dd69
Fix curl error (#33653) 2025-04-03 16:00:38 +02:00
ldestailleur
1726312fc3 Fix travis 2025-03-24 18:23:31 +01:00
ldestailleur
65496604b4 Debug ai v22 2025-03-20 23:54:24 +01:00
Hystepik
7eb0b2b885 New add new setup in ai setup 2025-02-19 10:59:19 +01:00
ldestailleur
99e8842f0a Fix phpstan 2025-02-17 03:49:11 +01:00
ldestailleur
3258dd4837 Fix TODO 2025-02-16 23:15:51 +01:00
ldestailleur
47d59c7938 NEW Add a test mode for AI setup 2025-02-16 22:45:14 +01:00
Laurent Destailleur
7b9a485f17 Fix CI 2026-01-20 13:22:48 +01:00
Laurent Destailleur
13d872a265 Fix warning 2026-01-19 18:39:34 +01:00
Laurent Destailleur
94217e800d Fix CI 2026-01-19 18:28:06 +01:00
Laurent Destailleur
47c4ebeb14 WIP Upload file with AI parsing 2026-01-18 21:29:19 +01:00
Laurent Destailleur
3ba8daab0c Work on AI doc parsing protopype 2026-01-18 14:21:09 +01:00
MDW
099dbd9c1e
Qual: Fix notices for htdocs/admin/* (#30982)
* Fix (Possibly)UndeclaredGlobalVariable

* Update phan baseline

* Fix (Possibly)UndeclaredGlobalVariable (2)

* Qual: Fix notices for htdocs/admin/*

# Qual: Fix notices for htdocs/admin/*

Fixes most phan/phpstan noticies for files under htdocs/admin/* and ai.
2024-09-18 03:27:25 +02:00
Laurent Destailleur
3a9931c0bb NEW Add a test mode into the setup of AI prompts 2024-07-19 15:38:52 +02:00
Laurent Destailleur
dd93065f41 WIP AI 2024-07-16 18:20:23 +02:00
Laurent Destailleur
811f4b6c15 WIP Work on custom local bridge AI 2024-07-16 18:08:26 +02:00
Laurent Destailleur
ac1704ec49 Clean menu for AI generation modes 2024-07-15 13:40:55 +02:00
Laurent Destailleur
78421f4607 Debug v20 2024-06-06 11:09:43 +02:00
Laurent Destailleur
0371ffefd0 Debug v20 2024-06-06 00:37:08 +02:00
Laurent Destailleur
ac1e6fccb8 Fix php error 2024-04-24 20:03:46 +02:00
Laurent Destailleur
82fd5a8ac3 Debug v20 2024-04-24 13:07:47 +02:00
Frédéric FRANCE
7cf6a0821f
fix phpdoc for ismultientitymanaged (#29245)
* fix phpdoc

* fix

* fix

* fix

* fix

* fix

---------

Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
2024-04-06 17:38:39 +02:00
Laurent Destailleur
87388d7dab Debug v20 2024-03-16 21:33:55 +01:00
Laurent Destailleur
364892008d
Merge pull request #28772 from lamrani002/chageCurlInAiModule
New update in generate_content in module Ai
2024-03-12 14:15:32 +01:00
Laurent Destailleur
7869c1a309 AI support both plain text and HTML generation 2024-03-12 10:01:39 +01:00
Laurent Destailleur
56a4dd46db Add a log 2024-03-11 20:41:56 +01:00
Lamrani Abdel
d916a70acf Remove comments 2024-03-11 18:03:33 +01:00