Feature: Add configurable LLM model name
This commit is contained in:
@@ -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');
|
||||
|
||||
@@ -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' => [
|
||||
|
||||
@@ -98,6 +98,24 @@ style('display:none');
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="analytics-hub-settings__field">
|
||||
<label for="llm_model">
|
||||
<?php p($l->t('Model')); ?>
|
||||
<span class="analytics-hub-settings__optional"><?php p($l->t('(Optional - defaults to claude-sonnet-4-5-20250929)')); ?></span>
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
id="llm_model"
|
||||
name="llm_model"
|
||||
value="<?php p($_['llm_model']); ?>"
|
||||
placeholder="claude-sonnet-4-5-20250929"
|
||||
autocomplete="off"
|
||||
/>
|
||||
<p class="analytics-hub-settings__hint">
|
||||
<?php p($l->t('Enter the model to use. Examples: claude-sonnet-4-5-20250929, claude-3-5-sonnet-20241022, claude-3-opus-20240229')); ?>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="analytics-hub-settings__field">
|
||||
<label for="anthropic_api_key">
|
||||
<?php p($l->t('API Key')); ?>
|
||||
|
||||
Reference in New Issue
Block a user