dolibarr 24.0.0-beta
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')
 Generate a response using the configured LLM provider.
 

Private Member Functions

 callOpenAI (string $sys, string $msg, string $mode='text')
 Call OpenAI-compatible API.
 
 callAnthropic (string $sys, string $msg, string $mode='text')
 Call Anthropic API (Claude)
 
 callGoogle (string $sys, string $msg, string $mode='text')
 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 26 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 58 of file llmadapter.class.php.

References type.

Member Function Documentation

◆ callAnthropic()

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

Call Anthropic API (Claude)

Parameters
string$sysSystem prompt
string$msgUser message
string$modeResponse mode (default: text)
Returns
string|null Response content or null on failure

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

References curl().

Referenced by generate().

◆ callGoogle()

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

Call Google Gemini API.

Parameters
string$sysSystem prompt
string$msgUser message
string$modeResponse mode (default: text)
Returns
string|null Response content or null on failure

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

References curl().

Referenced by generate().

◆ callOpenAI()

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

Call OpenAI-compatible API.

Parameters
string$sysSystem prompt
string$msgUser message
string$mode'json' or 'text'
Returns
string|null Response content or null on failure

Definition at line 95 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 196 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' )

Generate a response using the configured LLM provider.

Parameters
string$systemThe system prompt/instruction
string$userMsgThe specific user query
string$mode'json' for strict JSON (MCP), 'text' for legacy (default)
Returns
string|null The text response from the AI or null on failure

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

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


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