|
dolibarr 25.0.0-alpha
|
Public Member Functions | |
| __construct (string $type, string $key, string $baseUrl, string $model, int $timeout) | |
| Constructor. | |
| generate (string $system, string $userMsg, string $mode='text', array $attachments=array(), array $history=array()) | |
| Generate a response using the configured LLM provider. | |
Private Member Functions | |
| callOpenAI (string $sys, string $msg, string $mode='text', array $attachments=array(), array $history=array()) | |
| Call OpenAI-compatible API. | |
| callAnthropic (string $sys, string $msg, string $mode='text', array $attachments=array(), array $history=array()) | |
| Call Anthropic API (Claude) | |
| callGoogle (string $sys, string $msg, string $mode='text', array $attachments=array(), array $history=array()) | |
| Call Google Gemini API. | |
| clearModelFailure () | |
| Drop a recorded model failure once that model answers again. | |
| recordModelFailure (int $httpCode, string $msg) | |
| Record a "model not found / retired" type provider failure into the constant AI_MODEL_RUNTIME_FAILURE, displayed as a warning banner on the models admin page. | |
| encodeRequestForLog (array $data) | |
| JSON-encode a request for the log with base64 payloads removed, so the 60k truncation in ai_log_request() never swallows the text prompt (for Anthropic the document block precedes the text block) and document contents never land in llx_ai_request_log. | |
| curl (string $url, array $data, array $headers, bool $isClaude=false, bool $isGemini=false) | |
| Execute HTTP Request via cURL. | |
Definition at line 27 of file llmadapter.class.php.
| UniversalLLMAdapter::__construct | ( | string | $type, |
| string | $key, | ||
| string | $baseUrl, | ||
| string | $model, | ||
| int | $timeout ) |
Constructor.
| string | $type | The LLM type |
| string | $key | API Key |
| string | $baseUrl | API Base URL |
| string | $model | Model name |
| int | $timeout | Timeout in seconds |
Definition at line 62 of file llmadapter.class.php.
References type.
|
private |
Call Anthropic API (Claude)
| string | $sys | System prompt |
| string | $msg | User message |
| string | $mode | Response mode (default: text) |
| array<int,array{mime:string,data:string}> | $attachments Optional attachments sent as native multimodal parts | |
| array<int,array{role:string,text:string}> | $history Optional prior turns inserted before the current query |
Definition at line 179 of file llmadapter.class.php.
References curl(), and encodeRequestForLog().
Referenced by generate().
|
private |
Call Google Gemini API.
| string | $sys | System prompt |
| string | $msg | User message |
| string | $mode | Response mode (default: text) |
| array<int,array{mime:string,data:string}> | $attachments Optional attachments sent as native multimodal parts | |
| array<int,array{role:string,text:string}> | $history Optional prior turns inserted before the current query |
Definition at line 231 of file llmadapter.class.php.
References curl(), and encodeRequestForLog().
Referenced by generate().
|
private |
Call OpenAI-compatible API.
| string | $sys | System prompt |
| string | $msg | User message |
| string | $mode | 'json' or 'text' |
| array<int,array{mime:string,data:string}> | $attachments Optional attachments sent as native multimodal parts | |
| array<int,array{role:string,text:string}> | $history Optional prior turns inserted before the current query |
Definition at line 107 of file llmadapter.class.php.
References curl(), and encodeRequestForLog().
Referenced by generate().
|
private |
Drop a recorded model failure once that model answers again.
Definition at line 285 of file llmadapter.class.php.
References $conf, dolibarr_del_const(), and getDolGlobalString().
Referenced by curl().
|
private |
Execute HTTP Request via cURL.
| string | $url | Target API URL |
| array<string,mixed> | $data Request payload (keys are strings, values vary) | |
| array<int,string> | $headers List of HTTP headers (indexed array of strings) | |
| bool | $isClaude | Flag to handle Anthropic response format |
| bool | $isGemini | Flag to handle Gemini response format |
Definition at line 385 of file llmadapter.class.php.
References clearModelFailure(), getURLContent(), and recordModelFailure().
Referenced by callAnthropic(), callGoogle(), and callOpenAI().
|
private |
JSON-encode a request for the log with base64 payloads removed, so the 60k truncation in ai_log_request() never swallows the text prompt (for Anthropic the document block precedes the text block) and document contents never land in llx_ai_request_log.
| array<string,mixed> | $data Request payload |
| string[] | $m | Regex matches: [1] = base64-like run |
Definition at line 350 of file llmadapter.class.php.
Referenced by callAnthropic(), callGoogle(), and callOpenAI().
| UniversalLLMAdapter::generate | ( | string | $system, |
| string | $userMsg, | ||
| string | $mode = 'text', | ||
| array | $attachments = array(), | ||
| array | $history = array() ) |
Generate a response using the configured LLM provider.
Attachments are sent as NATIVE multimodal parts — instead of inlining base64 into the text prompt — which is what allows the provider to actually see the file (vision/document understanding).
| string | $system | The system prompt/instruction |
| string | $userMsg | The specific user query |
| string | $mode | 'json' for strict JSON (MCP), 'text' for legacy (default) |
| array<int,array{mime:string,data:string}> | $attachments Optional documents/images, each entry is array('mime' => 'image/png', 'data' => '<base64>') | |
| array<int,array{role:string,text:string}> | $history Optional prior conversation turns (role 'user'|'assistant'), sent as native multi-turn messages before the current query. Caller sanitizes and caps them. |
Definition at line 85 of file llmadapter.class.php.
References callAnthropic(), callGoogle(), callOpenAI(), and type.
|
private |
Record a "model not found / retired" type provider failure into the constant AI_MODEL_RUNTIME_FAILURE, displayed as a warning banner on the models admin page.
Runtime is the only fully reliable signal for a retired model: a provider's listing can be incomplete, and a listed model can still be rejected at call time (e.g. models restricted to existing customers).
| int | $httpCode | HTTP status returned by the provider |
| string | $msg | Error message returned by the provider |
Definition at line 315 of file llmadapter.class.php.
References $conf, dol_now(), dol_trunc(), dolibarr_set_const(), and getDolGlobalString().
Referenced by curl().