dolibarr 25.0.0-alpha
UniversalLLMAdapter Class Reference

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())
 Generate a response using the configured LLM provider.
 

Private Member Functions

 callOpenAI (string $sys, string $msg, string $mode='text', array $attachments=array())
 Call OpenAI-compatible API.
 
 callAnthropic (string $sys, string $msg, string $mode='text', array $attachments=array())
 Call Anthropic API (Claude)
 
 callGoogle (string $sys, string $msg, string $mode='text', array $attachments=array())
 Call Google Gemini API.
 
 curl (string $url, array $data, array $headers, bool $isClaude=false, bool $isGemini=false)
 Execute HTTP Request via cURL.
 

Detailed Description

Definition at line 27 of file llmadapter.class.php.

Constructor & Destructor Documentation

◆ __construct()

UniversalLLMAdapter::__construct ( string $type,
string $key,
string $baseUrl,
string $model,
int $timeout )

Constructor.

Parameters
string$typeThe LLM type
string$keyAPI Key
string$baseUrlAPI Base URL
string$modelModel name
int$timeoutTimeout in seconds

Definition at line 59 of file llmadapter.class.php.

References type.

Member Function Documentation

◆ callAnthropic()

UniversalLLMAdapter::callAnthropic ( string $sys,
string $msg,
string $mode = 'text',
array $attachments = array() )
private

Call Anthropic API (Claude)

Parameters
string$sysSystem prompt
string$msgUser message
string$modeResponse mode (default: text)
array<int,array{mime:string,data:string}>$attachments Optional attachments sent as native multimodal parts
Returns
string|null Response content or null on failure

Definition at line 155 of file llmadapter.class.php.

References curl().

Referenced by generate().

◆ callGoogle()

UniversalLLMAdapter::callGoogle ( string $sys,
string $msg,
string $mode = 'text',
array $attachments = array() )
private

Call Google Gemini API.

Parameters
string$sysSystem prompt
string$msgUser message
string$modeResponse mode (default: text)
array<int,array{mime:string,data:string}>$attachments Optional attachments sent as native multimodal parts
Returns
string|null Response content or null on failure

Definition at line 198 of file llmadapter.class.php.

References curl().

Referenced by generate().

◆ callOpenAI()

UniversalLLMAdapter::callOpenAI ( string $sys,
string $msg,
string $mode = 'text',
array $attachments = array() )
private

Call OpenAI-compatible API.

Parameters
string$sysSystem prompt
string$msgUser message
string$mode'json' or 'text'
array<int,array{mime:string,data:string}>$attachments Optional attachments sent as native multimodal parts
Returns
string|null Response content or null on failure

Definition at line 102 of file llmadapter.class.php.

References curl().

Referenced by generate().

◆ curl()

UniversalLLMAdapter::curl ( string $url,
array $data,
array $headers,
bool $isClaude = false,
bool $isGemini = false )
private

Execute HTTP Request via cURL.

Parameters
string$urlTarget 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$isClaudeFlag to handle Anthropic response format
bool$isGeminiFlag to handle Gemini response format
Returns
string|null Returns the extracted text, an error message, or null

Definition at line 242 of file llmadapter.class.php.

References getURLContent(), and string.

Referenced by callAnthropic(), callGoogle(), and callOpenAI().

◆ generate()

UniversalLLMAdapter::generate ( string $system,
string $userMsg,
string $mode = 'text',
array $attachments = 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).

Parameters
string$systemThe system prompt/instruction
string$userMsgThe 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>')
Returns
string|null The text response from the AI or null on failure

Definition at line 81 of file llmadapter.class.php.

References callAnthropic(), callGoogle(), callOpenAI(), and type.


The documentation for this class was generated from the following file: