Skip to content

Commit

Permalink
Latest checkin
Browse files Browse the repository at this point in the history
  • Loading branch information
mhughes2k committed Mar 25, 2024
1 parent 1bdbabc commit 77da165
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 10 deletions.
8 changes: 4 additions & 4 deletions ai/classes/aiprovider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand All @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions lang/en/ai.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] = '';
Expand Down Expand Up @@ -85,3 +86,4 @@

$string['constraints'] = 'Constraints';
$string['savechanges'] = 'Save changes';
$string['aisettings'] = 'AI Provider Settings';
4 changes: 3 additions & 1 deletion mod/xaichat/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

require(__DIR__.'/../../config.php');
require_once(__DIR__.'/lib.php');

use core_ai\api;
use mod_xaichat\aichatform;

// Course module id.
Expand Down Expand Up @@ -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');
}

Expand Down
11 changes: 6 additions & 5 deletions search/engine/solrrag/classes/engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@

namespace search_solrrag;

use core_ai\api;
use search_solrrag\document;
use search_solrrag\schema;
//require_once($CFG->dirroot . "/search/engine/solrrag/lib.php");
// // Fudge autoloading!
// 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 {

/**
Expand All @@ -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;
}
Expand Down
22 changes: 22 additions & 0 deletions search/engine/solrrag/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit 77da165

Please sign in to comment.