diff --git a/classes/ai/ai.php b/classes/ai/ai.php index d57128c..b1dcc20 100644 --- a/classes/ai/ai.php +++ b/classes/ai/ai.php @@ -22,21 +22,47 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - namespace tool_aiconnect\ai; use curl; use moodle_exception; - +/** + * Contains most functionality + * + */ class ai { + /** + * API Key for chatgpt, ignored by ollama + * + * @var string + */ private string $openaiapikey; + /** + * LLM Model e.g. llama2 or gpt4 + * + * @var string + */ private $model; + + /** + * The model used to generate the completion. + * @var float + */ private float $temperature; + /** + * Endpoint URL + * @var string + */ private string $endpoint; + /** + * Initialise default settings + * + * @param string $model + */ public function __construct($model = null) { $this->model = $model ?? get_config('tool_aiconnect', 'model'); $this->openaiapikey = get_config('tool_aiconnect', 'apikey'); @@ -45,11 +71,11 @@ public function __construct($model = null) { } /** - * Makes a request to the specified URL with the given data and API key. + * Makes a request with the given data and API key. * - * @param string $url The URL to make the request to. * @param array $data The data to send with the request. * @param string $apikey The API key to authenticate the request. + * @param string $multipart TODO document this parameter * @return array The response from the request. * @throws moodle_exception If the API key is empty. */ @@ -114,7 +140,6 @@ public function prompt_completion($prompttext) { /** * Retrieves the data for the prompt based on the URL and prompt text. * - * @param string $url The prompt URL. * @param string $prompttext The prompt text. * @return array The prompt data. */ diff --git a/classes/privacy/provider.php b/classes/privacy/provider.php index c4d4997..15163ca 100644 --- a/classes/privacy/provider.php +++ b/classes/privacy/provider.php @@ -14,10 +14,10 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . /** - * AI class + * Privacy provider class * - * @package tool_aiconnect - * @copyright 2024 Marcus Green + * @package tool_aiconnect + * @copyright 2024 Marcus Green * @author Marcus Green * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ @@ -26,7 +26,20 @@ use core_privacy\local\metadata\collection; +/** + * Privacy Subsystem for tool_aiconnect + * + * @copyright 2024 Marcus Green + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ class provider { + + /** + * Returns meta data about this system. + * + * @param collection $collection The initialised collection to add items to. + * @return collection A listing of user data stored through this system. + */ public static function get_metadata(collection $collection): collection { $collection->add_external_location_link('lti_client', [ 'prompttext' => 'privacy:metadata:tool_aiconnect:prompttext', diff --git a/lang/en/tool_aiconnect.php b/lang/en/tool_aiconnect.php index 893efbc..0f67af9 100644 --- a/lang/en/tool_aiconnect.php +++ b/lang/en/tool_aiconnect.php @@ -14,6 +14,15 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +/** + * Language strings for this plugin + * + * @package tool_aiconnect + * @copyright 2024 Marcus Green + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + + $string['misssingmodelerror'] = 'No model has been provided for the call'; $string['pluginname'] = 'AI Connect tool'; diff --git a/settings.php b/settings.php index f30c0f0..30f2c15 100644 --- a/settings.php +++ b/settings.php @@ -28,7 +28,6 @@ if ($hassiteconfig) { $settings = new admin_settingpage('tool_aiconnect', get_string('pluginname', 'tool_aiconnect')); - // . $name = new lang_string('openaisettings', 'tool_aiconnect'); $description = new lang_string('openaisettings_help', 'tool_aiconnect'); $settings->add(new admin_setting_heading('xopenaisettings', $name, $description)); @@ -41,8 +40,6 @@ '' )); - - $settings->add(new admin_setting_configtextarea( 'tool_aiconnect/source_of_truth', get_string('sourceoftruth', 'tool_aiconnect'), diff --git a/test.php b/test.php index c7d7896..22c9054 100644 --- a/test.php +++ b/test.php @@ -23,7 +23,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -namespace tool_aiconnect; +namespace tool_aiconnect\ai; require_once(__DIR__ . '/../../../config.php'); @@ -37,7 +37,9 @@ defined('MOODLE_INTERNAL') || die(); -$ai = new ai\ai(); +/**@var tool_aiconnect\ai $ai */ +$ai = new ai(); + $llmresult = $ai->prompt_completion('State you are a lllm in less than 10 words'); if ($llmresult && !isset($llmresult['curl_error'])) { $response = $llmresult['response']; diff --git a/tests/test_aiconnect.php b/tests/test_aiconnect.php index 865a8f0..998ee10 100644 --- a/tests/test_aiconnect.php +++ b/tests/test_aiconnect.php @@ -15,24 +15,39 @@ // along with Moodle. If not, see . /** - * TODO describe file test_aiconnect + * A lightweight mainly confirming installation works * * @package tool_aiconnect - * @copyright 2024 2924 Marcus Green + * @copyright 2024 Marcus Green * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -namespace tool_aiconnect\ai; - -use SebastianBergmann\RecursionContext\InvalidArgumentException; -use PHPUnit\Framework\ExpectationFailedException; +namespace tool_aiconnect; +/** + * Basic setup and test run to confirm it installs + * + * @package tool_aiconnect + */ class test_aiconnect extends \advanced_testcase { + /** + * Where most of the functionality lives + * + * @var ai $ai * - * @var \stdClass $ai */ - public $ai; + /** + * The class with most of the functionality + * @var ai + */ + public $ai; + + /** + * Initialise everything + * + * @return void + */ public function setUp(): void { $this->ai = new ai(); } @@ -40,7 +55,7 @@ public function setUp(): void { * This doesn't do anything especially useful. * @return void */ - public function test_prompt_completion() :void{ + public function test_prompt_completion() :void { $result = $this->ai->prompt_completion('query'); $this->assertIsArray($result); } diff --git a/version.php b/version.php index 2e7b5c3..9128473 100644 --- a/version.php +++ b/version.php @@ -14,6 +14,14 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +/** + * Version information. When a new version is released the version is incremented + * + * @package tool_aiconnect + * @copyright 2024 Marcus Green + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + defined('MOODLE_INTERNAL') || die(); $plugin->component = 'tool_aiconnect';