Feature: Add configurable LLM model name
This commit is contained in:
@@ -34,6 +34,7 @@ class AdminController {
|
||||
$clientId = $this->config->getAppValue('google_client_id', 'analyticshub', '');
|
||||
$apiKey = $this->config->getAppValue('anthropic_api_key', 'analyticshub', '');
|
||||
$llmEndpoint = $this->config->getAppValue('llm_api_endpoint', 'analyticshub', '');
|
||||
$llmModel = $this->config->getAppValue('llm_model', 'analyticshub', '');
|
||||
$refreshToken = $this->config->getAppValue('google_refresh_token', 'analyticshub', '');
|
||||
|
||||
// Check if configured
|
||||
@@ -56,6 +57,7 @@ class AdminController {
|
||||
'google_client_id' => $clientId,
|
||||
'google_refresh_token' => $maskedRefreshToken,
|
||||
'llm_api_endpoint' => $llmEndpoint,
|
||||
'llm_model' => $llmModel,
|
||||
'anthropic_api_key' => $maskedApiKey,
|
||||
'is_configured' => $isConfigured,
|
||||
],
|
||||
@@ -80,6 +82,7 @@ class AdminController {
|
||||
$refreshToken = $data['google_refresh_token'] ?? '';
|
||||
$apiKey = $data['anthropic_api_key'] ?? '';
|
||||
$llmEndpoint = $data['llm_api_endpoint'] ?? '';
|
||||
$llmModel = $data['llm_model'] ?? '';
|
||||
|
||||
if (empty($clientId) || empty($clientSecret) || empty($apiKey)) {
|
||||
return new JSONResponse([
|
||||
@@ -100,6 +103,10 @@ class AdminController {
|
||||
$this->config->setAppValue('llm_api_endpoint', 'analyticshub', $llmEndpoint);
|
||||
}
|
||||
|
||||
if (!empty($llmModel)) {
|
||||
$this->config->setAppValue('llm_model', 'analyticshub', $llmModel);
|
||||
}
|
||||
|
||||
$this->config->setAppValue('anthropic_api_key', 'analyticshub', $apiKey);
|
||||
|
||||
// Check if fully configured
|
||||
|
||||
@@ -62,6 +62,7 @@ class PageController extends \OCP\AppFramework\Controller {
|
||||
$clientId = $this->config->getAppValue('google_client_id', 'analyticshub', '');
|
||||
$apiKey = $this->config->getAppValue('anthropic_api_key', 'analyticshub', '');
|
||||
$llmEndpoint = $this->config->getAppValue('llm_api_endpoint', 'analyticshub', '');
|
||||
$llmModel = $this->config->getAppValue('llm_model', 'analyticshub', '');
|
||||
|
||||
// Mask API key for display
|
||||
$maskedApiKey = '';
|
||||
@@ -78,6 +79,7 @@ class PageController extends \OCP\AppFramework\Controller {
|
||||
'is_llm_configured' => $isLLMConfigured,
|
||||
'google_client_id' => $clientId,
|
||||
'llm_api_endpoint' => $llmEndpoint,
|
||||
'llm_model' => $llmModel,
|
||||
'anthropic_api_key_masked' => $maskedApiKey,
|
||||
'request' => $this->request,
|
||||
]);
|
||||
|
||||
@@ -45,6 +45,7 @@ class LLMService {
|
||||
try {
|
||||
$apiKey = $this->config->getAppValue('anthropic_api_key', 'analyticshub');
|
||||
$apiEndpoint = $this->config->getAppValue('llm_api_endpoint', 'analyticshub', '');
|
||||
$model = $this->config->getAppValue('llm_model', 'analyticshub', 'claude-sonnet-4-5-20250929');
|
||||
|
||||
if (empty($apiKey)) {
|
||||
throw new \Exception('API key not configured');
|
||||
@@ -58,7 +59,7 @@ class LLMService {
|
||||
$userPrompt = $this->buildUserPrompt($processedData);
|
||||
|
||||
// Call with retry
|
||||
$response = $this->callWithRetry($systemPrompt, $userPrompt, $apiKey, $endpoint);
|
||||
$response = $this->callWithRetry($systemPrompt, $userPrompt, $apiKey, $endpoint, $model);
|
||||
|
||||
return $response;
|
||||
|
||||
@@ -124,12 +125,12 @@ PROMPT;
|
||||
/**
|
||||
* Call Claude API with retry logic
|
||||
*/
|
||||
private function callWithRetry(string $systemPrompt, string $userPrompt, string $apiKey, string $endpoint): string {
|
||||
private function callWithRetry(string $systemPrompt, string $userPrompt, string $apiKey, string $endpoint, string $model): string {
|
||||
for ($attempt = 0; $attempt < self::MAX_RETRIES; $attempt++) {
|
||||
$this->logger->info("LLM API call attempt {$attempt}/" . self::MAX_RETRIES);
|
||||
|
||||
try {
|
||||
$response = $this->makeLLMRequest($systemPrompt, $userPrompt, $apiKey, $endpoint);
|
||||
$response = $this->makeLLMRequest($systemPrompt, $userPrompt, $apiKey, $endpoint, $model);
|
||||
|
||||
// Validate response
|
||||
$this->validateResponse($response);
|
||||
@@ -186,11 +187,11 @@ PROMPT;
|
||||
/**
|
||||
* Make HTTP request to LLM API
|
||||
*/
|
||||
private function makeLLMRequest(string $systemPrompt, string $userPrompt, string $apiKey, string $endpoint): string {
|
||||
private function makeLLMRequest(string $systemPrompt, string $userPrompt, string $apiKey, string $endpoint, string $model): string {
|
||||
$ch = curl_init();
|
||||
|
||||
$payload = [
|
||||
'model' => 'claude-sonnet-4-5-20250929',
|
||||
'model' => $model,
|
||||
'max_tokens' => 2000,
|
||||
'system' => $systemPrompt,
|
||||
'messages' => [
|
||||
|
||||
Reference in New Issue
Block a user