From 77da1654c89661e481e878e8b6b480f572d64d58 Mon Sep 17 00:00:00 2001 From: Michael hughes Date: Mon, 25 Mar 2024 11:48:33 +0000 Subject: [PATCH] Latest checkin --- ai/classes/aiprovider.php | 8 ++++---- lang/en/ai.php | 2 ++ mod/xaichat/view.php | 4 +++- search/engine/solrrag/classes/engine.php | 11 ++++++----- search/engine/solrrag/settings.php | 22 ++++++++++++++++++++++ 5 files changed, 37 insertions(+), 10 deletions(-) diff --git a/ai/classes/aiprovider.php b/ai/classes/aiprovider.php index 7dc88f908a9f..a4bdb4151aa7 100644 --- a/ai/classes/aiprovider.php +++ b/ai/classes/aiprovider.php @@ -256,14 +256,14 @@ public static function get_records($filters = [], $sort = '', $order = 'ASC', $s $providercontextid = $record->get('contextid'); if ($providercontextid == self::CONTEXT_ALL_MY_COURSES) { // More problematic. - debugging('Provider needs to be in one of user\'s courses', DEBUG_DEVELOPER); +// debugging('Provider needs to be in one of user\'s courses', DEBUG_DEVELOPER); $result = $result & true; } else if ($providercontextid == null) { // System provider so always matches. - debugging("System AI provider", DEBUG_DEVELOPER); +// debugging("System AI provider", DEBUG_DEVELOPER); $result = $result & true; } else { - debugging("Context linked AI provider", DEBUG_DEVELOPER); +// debugging("Context linked AI provider", DEBUG_DEVELOPER); $providercontext = \context::instance_by_id( $providercontextid ); @@ -272,7 +272,7 @@ public static function get_records($filters = [], $sort = '', $order = 'ASC', $s $result = $result & $ischild; } }else { - debugging('Filtering on '.$key. "' = {$value}", DEBUG_DEVELOPER); +// debugging('Filtering on '.$key. "' = {$value}", DEBUG_DEVELOPER); if ($record->get($key) != $value) { return false; } diff --git a/lang/en/ai.php b/lang/en/ai.php index a3773be72441..a4b76a272e38 100644 --- a/lang/en/ai.php +++ b/lang/en/ai.php @@ -40,6 +40,7 @@ '; $string['chat'] = 'Chat Completion'; $string['chat_help'] = 'Chat Completion allows the AIProvider to be used to generate text.'; +$string['disable'] = 'Disable'; $string['embedding'] = 'Embedding'; $string['embedding_help'] = 'Embedding allows the AI to generate vector representations of text.'; $string['aiproviderfeatures'] = ''; @@ -85,3 +86,4 @@ $string['constraints'] = 'Constraints'; $string['savechanges'] = 'Save changes'; +$string['aisettings'] = 'AI Provider Settings'; diff --git a/mod/xaichat/view.php b/mod/xaichat/view.php index cdb94b416f09..825f2c1c3aca 100644 --- a/mod/xaichat/view.php +++ b/mod/xaichat/view.php @@ -25,6 +25,8 @@ require(__DIR__.'/../../config.php'); require_once(__DIR__.'/lib.php'); + +use core_ai\api; use mod_xaichat\aichatform; // Course module id. @@ -57,7 +59,7 @@ } //$aicontext = $_SESSION[$aicontextkey]; -if (!($aiprovider = \core\ai\api::get_provider($moduleinstance->aiproviderid))){ +if (!($aiprovider = api::get_provider($moduleinstance->aiproviderid))){ throw new moodle_exception("noaiproviderfound", 'xaichat'); } diff --git a/search/engine/solrrag/classes/engine.php b/search/engine/solrrag/classes/engine.php index 043102731605..5fb1850ac0fd 100644 --- a/search/engine/solrrag/classes/engine.php +++ b/search/engine/solrrag/classes/engine.php @@ -2,6 +2,7 @@ namespace search_solrrag; +use core_ai\api; use search_solrrag\document; use search_solrrag\schema; //require_once($CFG->dirroot . "/search/engine/solrrag/lib.php"); @@ -9,9 +10,9 @@ // require_once($CFG->dirroot ."/search/engine/solrrag/classes/ai/api.php"); // require_once($CFG->dirroot ."/search/engine/solrrag/classes/ai/aiprovider.php"); // require_once($CFG->dirroot ."/search/engine/solrrag/classes/ai/aiclient.php"); -use \core\ai\AIProvider; -use \core\ai\AIClient; -use \core\ai\AiException; +use \core_ai\AIProvider; +use \core_ai\aiclient; +use \core_ai\AiException; class engine extends \search_solr\engine { /** @@ -28,8 +29,8 @@ public function __construct(bool $alternateconfiguration = false) // Ideally we'd be using a Moodle AI provider to tell us which LLM to use for generating embeddings, and // then simply calling the API and get some results back...but we don't have that yet. // So we'll fudge this for the moment and leverage an OpenAI Web Service API via a simple HTTP request. - $aiproviderid = 1; - $aiprovider = \core\ai\api::get_provider($aiproviderid); + $aiproviderid = get_config('search_solrrag', 'aiprovider'); + $aiprovider = api::get_provider($aiproviderid); $this->aiprovider = $aiprovider; $this->aiclient = !is_null($aiprovider)? new AIClient($aiprovider) : null; } diff --git a/search/engine/solrrag/settings.php b/search/engine/solrrag/settings.php index b4a837c5e0e4..a17b7227b24b 100644 --- a/search/engine/solrrag/settings.php +++ b/search/engine/solrrag/settings.php @@ -31,6 +31,28 @@ $settings->add(new admin_setting_heading('search_solrrag_settings', '', get_string('extensionerror', 'search_solrrag'))); } else { + // Which AI Provider to use: + $settings->add(new admin_setting_heading('search_solrrag_aiprovider', + new lang_string('aisettings', 'ai'), '')); + $providers = \core_ai\api::get_providers( + null, + true, + true + ); + $optproviders = [ + '' => get_string('disable', 'ai') + ]; + + foreach($providers as $provider) { + $optproviders[$provider->get('id')] = $provider->get('name'); + } + $settings->add(new admin_setting_configselect( + 'search_solrrag/aiprovider', + 'Choose Provider', + 'List of available AI services', + "", + $optproviders + )); $settings->add(new admin_setting_heading('search_solrrag_connection', new lang_string('connectionsettings', 'search_solrrag'), '')); $settings->add(new admin_setting_configtext('search_solrrag/server_hostname', new lang_string('solrserverhostname', 'search_solrrag'), new lang_string('solrserverhostname_desc', 'search_solrrag'), '127.0.0.1', PARAM_HOST));