| Current Path : /home/helpink/www/administrator/components/com_jbusinessdirectory/controllers/ |
| Current File : /home/helpink/www/administrator/components/com_jbusinessdirectory/controllers/ai.php |
<?php
/**
* @package J-BusinessDirectory
*
* @author CMSJunkie http://www.cmsjunkie.com/
* @copyright Copyright (C) 2007 - 2022 CMSJunkie. All rights reserved.
* @license https://www.gnu.org/licenses/agpl-3.0.en.html
*/
defined('_JEXEC') or die('Restricted access');
class JBusinessDirectoryControllerAI extends JControllerLegacy
{
public function __construct($config = array())
{
parent::__construct($config);
}
public function generateText()
{
$app = JFactory::getApplication();
$input = $app->input;
$prompt = $input->getString('prompt', '');
$type = $input->getString('type', 'business');
$field = $input->getString('field', 'description');
$language = $input->getString('language', '');
if (empty($prompt)) {
$response = array(
'status' => 'error',
'message' => JText::_('COM_JBUSINESSDIRECTORY_AI_EMPTY_PROMPT')
);
echo json_encode($response);
$app->close();
}
// Assume AIService class is available in admin context
// Might need to include/require it if it's not autoloaded
// require_once JPATH_COMPONENT_ADMINISTRATOR . '/path/to/AIService.php';
try {
$aiService = new AIService();
$generatedText = $aiService->generateText($prompt, $type, $field); // Consider passing language too if service supports it
$response = array(
'status' => 'success',
'text' => $generatedText
);
} catch (Exception $e) {
$response = array(
'status' => 'error',
'message' => $e->getMessage()
);
}
echo json_encode($response);
$app->close();
}
}