diff --git a/analyticshub/js/admin.js b/analyticshub/js/admin.js index 0df1730..a061b66 100644 --- a/analyticshub/js/admin.js +++ b/analyticshub/js/admin.js @@ -27,6 +27,7 @@ google_client_secret: document.getElementById('google_client_secret').value, google_refresh_token: document.getElementById('google_refresh_token').value, llm_api_endpoint: document.getElementById('llm_api_endpoint').value, + llm_model: document.getElementById('llm_model').value, anthropic_api_key: document.getElementById('anthropic_api_key').value }; @@ -96,6 +97,7 @@ document.getElementById('google_client_secret').value = ''; document.getElementById('google_refresh_token').value = ''; document.getElementById('llm_api_endpoint').value = data.data.llm_api_endpoint || ''; + document.getElementById('llm_model').value = data.data.llm_model || ''; document.getElementById('anthropic_api_key').value = ''; updateStatus(!!data.data.is_configured); showNotification('Success', 'Configuration loaded'); diff --git a/analyticshub/lib/Controller/AdminController.php b/analyticshub/lib/Controller/AdminController.php index d182818..6e404a4 100644 --- a/analyticshub/lib/Controller/AdminController.php +++ b/analyticshub/lib/Controller/AdminController.php @@ -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 diff --git a/analyticshub/lib/Controller/PageController.php b/analyticshub/lib/Controller/PageController.php index 8ad0a64..cb820f8 100644 --- a/analyticshub/lib/Controller/PageController.php +++ b/analyticshub/lib/Controller/PageController.php @@ -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, ]); diff --git a/analyticshub/lib/Service/LLMService.php b/analyticshub/lib/Service/LLMService.php index aeb52b3..4366cb3 100644 --- a/analyticshub/lib/Service/LLMService.php +++ b/analyticshub/lib/Service/LLMService.php @@ -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' => [ diff --git a/analyticshub/templates/admin.php b/analyticshub/templates/admin.php index 399be85..a7977c1 100644 --- a/analyticshub/templates/admin.php +++ b/analyticshub/templates/admin.php @@ -98,6 +98,24 @@ style('display:none');
++ t('Enter the model to use. Examples: claude-sonnet-4-5-20250929, claude-3-5-sonnet-20241022, claude-3-opus-20240229')); ?> +
+