RegisterPrivate('save_settings', 'Save'); $this->RegisterPrivate('delete_log', 'DeleteLog'); $this->RegisterPrivate('download_log', 'DownloadLog'); $this->RegisterPrivate('validate_ai_key', 'ValidateAIKey'); } public function ValidateAIKey() { $key = $this->GetRequired('APIKey'); $model = $this->GetRequired('Model'); $caller = APiCallerBase::GetCallerByName($model); if ($caller == null) { $this->SendErrorMessage("Model not found"); } $caller->SetAPIKey($key); try { $caller->Chat([(object) ["role" => "user", "content" => "Hello!. Reply me using json"]], $key); } catch (Exception $e) { $this->SendErrorMessage($e->getMessage()); } $this->SendSuccessMessage(true); } public function Save() { $currency = $this->GetRequired('Currency'); $log = $this->GetRequired('LogOptions'); $googleApiKey = $this->GetRequired('GoogleMapsApiKey'); $recaptcha = $this->GetRequired('Recaptcha'); $aiModels = $this->GetRequired('AIModels'); do_action('allinoneforms_save_settings', $this->GetRequired('AddOnOptions')); $repository = new SettingsRepository($this->Loader); $repository->SaveRecaptchaSettings($recaptcha); $repository->SetGoogleMapsApiKey($googleApiKey); $repository->SaveCurrency($currency); $repository->SaveAIModels($aiModels); $repository->SaveLog($log); $this->SendSuccessMessage(true); } public function DeleteLog() { LogManager::RemoveLog(); $this->SendSuccessMessage(true); } public function DownloadLog() { if (!\file_exists(LogManager::GetLogFilePath())) { echo "No log file found"; die(); } $disposition = 'attachment'; if (isset($_GET['view'])) { $disposition = 'inline'; } header('Content-Disposition: ' . $disposition . '; filename="log.txt"'); header("Content-Type: text"); header("Content-Length: " . filesize(LogManager::GetLogFilePath())); echo (file_get_contents(LogManager::GetLogFilePath())); } }