Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusgreen committed Mar 21, 2024
1 parent 9ffce10 commit 8a0d562
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 22 deletions.
35 changes: 30 additions & 5 deletions classes/ai/ai.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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.
*/
Expand Down Expand Up @@ -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.
*/
Expand Down
19 changes: 16 additions & 3 deletions classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* 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
*/
Expand All @@ -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',
Expand Down
9 changes: 9 additions & 0 deletions lang/en/tool_aiconnect.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* 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';

Expand Down
3 changes: 0 additions & 3 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -41,8 +40,6 @@
''
));



$settings->add(new admin_setting_configtextarea(
'tool_aiconnect/source_of_truth',
get_string('sourceoftruth', 'tool_aiconnect'),
Expand Down
6 changes: 4 additions & 2 deletions test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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'];
Expand Down
33 changes: 24 additions & 9 deletions tests/test_aiconnect.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,47 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* 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();
}
/**
* 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);
}
Expand Down
8 changes: 8 additions & 0 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* 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';
Expand Down

0 comments on commit 8a0d562

Please sign in to comment.