_name = __('Perplexity Generate Text', 'ai-copilot-content-generator'); $this->_desc = __('Perplexity text generation', 'ai-copilot-content-generator'); $this->_sublabel = array('name'); $this->setBlock($block); } public function getSettings() { if (empty($this->_settings)) { $this->setSettings(); } return $this->_settings; } public function setSettings() { $modelOptions = WaicFrame::_()->getModule('options')->getModel(); $this->_settings = array( 'name' => array( 'type' => 'input', 'label' => __('Node Name', 'ai-copilot-content-generator'), 'default' => '', ), 'model' => array( 'type' => 'select', 'label' => __('Model', 'ai-copilot-content-generator'), 'default' => $modelOptions->getDefaults('api', 'perplexity_model'), 'options' => $modelOptions->getVariations('api', 'model', 'perplexity'), ), 'tokens' => array( 'type' => 'number', 'label' => __('Max Tokens', 'ai-copilot-content-generator'), 'default' => 4096, ), 'prompt' => array ( 'type' => 'textarea', 'label' => __('Prompt *', 'ai-copilot-content-generator'), 'default' => '', 'rows' => 8, 'variables' => true, ), ); } public function getVariables() { if (empty($this->_variables)) { $this->setVariables(); } return $this->_variables; } public function setVariables() { $this->_variables = array( 'content' => __('Generated Text', 'ai-copilot-content-generator'), ); return $this->_variables; } public function getResults( $taskId, $variables, $step = 0 ) { $apiOptions = array( 'engine' => 'perplexity', 'perplexity_model' => $this->getParam('model'), 'tokens' => $this->getParam('tokens'), ); $aiProvider = WaicFrame::_()->getModule('workspace')->getModel('aiprovider')->getInstance($apiOptions); if (!$aiProvider) { return false; } $aiProvider->init($taskId); if (!$aiProvider->setApiOptions($apiOptions)) { return false; } $prompt = $this->replaceVariables($this->getParam('prompt'), $variables); $this->setAiProviderSessionId($aiProvider, $taskId, $variables, $step); $result = $aiProvider->getText(array('prompt' => $prompt)); $error = $result['error']; $this->_results = array( 'result' => $error ? array() : array('content' => $this->controlText($result['data'])), 'error' => $error ? $this->controlText($result['msg']) : '', 'tokens' => empty($result['tokens']) ? array() : ( (int) $result['tokens'] ), 'status' => $error ? 7 : 3, ); return $this->_results; } }