-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MAICI Updates for Capstone Project #11
Open
CrystalAIML
wants to merge
4
commits into
caiocarvalhofre:main
Choose a base branch
from
SuperIntel24:feature/capstone
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0f23937
feat: update MAICI to use pruju URL.
CrystalAIML 8b0b69a
feat: added api url field.
CrystalAIML 58bb748
feat: added the api url to the maici settings form and updated the ve…
CrystalAIML 5993188
feat: added file upload observer.
CrystalAIML File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* External Class | ||
* | ||
* @package | ||
* @author Tay Moss <[email protected]> | ||
* @copyright 2024 CHURCHx at TUCC <https://churchx.ca> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
namespace mod_maici; // Replace with your actual plugin namespace | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
class mod_maici_observer { | ||
public static function resource_created_handler(\core\event\course_module_created $event) { | ||
global $CFG; | ||
|
||
$fileinfo = $event->get_record_snapshot('course_modules', $event->objectid); | ||
$filecontext = \context_module::instance($fileinfo->id); | ||
|
||
// You might need to adjust this to get the actual file | ||
$fs = get_file_storage(); | ||
$files = $fs->get_area_files($filecontext->id, 'mod_resource', 'content', false, 'timemodified', false); | ||
|
||
foreach ($files as $file) { | ||
if (!$file->is_directory()) { | ||
// Get file content | ||
$filecontent = $file->get_content(); | ||
|
||
// Send the file content to the remote server | ||
$ch = curl_init(); | ||
|
||
// Get file content | ||
$filecontent = $file->get_content(); | ||
|
||
// Prepare the file for upload | ||
$tempfile = tempnam(sys_get_temp_dir(), 'moodle_upload_'); | ||
file_put_contents($tempfile, $filecontent); | ||
|
||
// Send the file content to the remote server | ||
$ch = curl_init(); | ||
curl_setopt($ch, CURLOPT_URL, "http://prujuai:6500/uploadfile/"); | ||
curl_setopt($ch, CURLOPT_POST, 1); | ||
curl_setopt($ch, CURLOPT_POSTFIELDS, [ | ||
'file' => new \CURLFile($tempfile, $file->get_mimetype(), $file->get_filename()) | ||
]); | ||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | ||
$response = curl_exec($ch); | ||
curl_close($ch); | ||
|
||
// Clean up temporary file | ||
unlink($tempfile); | ||
|
||
} | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
$observers = array( | ||
array ( | ||
'eventname' => '\core\event\course_module_created', | ||
'callback' => '\mod_maici\mod_maici_observer::resource_created_handler', | ||
'internal' => false, | ||
'priority' => 1000, | ||
), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,64 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<XMLDB PATH="mod/maici/db" VERSION="20240111" COMMENT="XMLDB file for Moodle mod_maici" | ||
<XMLDB PATH="mod/maici/db" VERSION="20240722" COMMENT="XMLDB file for Moodle mod_maici" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd" | ||
> | ||
|
||
<TABLES> | ||
<TABLE NAME="maici" COMMENT="Stores the maici activity module instances."> | ||
<FIELDS> | ||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/> | ||
<FIELD NAME="course" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="ID of the course this activity is part of."/> | ||
<FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="The name of the activity module instance"/> | ||
<FIELD NAME="intro" TYPE="text" NOTNULL="true" SEQUENCE="false"/> | ||
<FIELD NAME="introformat" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="The format of the intro field."/> | ||
<FIELD NAME="instructions_submit" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="Instruction block (HTML)"/> | ||
<FIELD NAME="instructionsformat" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="Instruction block (HTML)"/> | ||
<FIELD NAME="apikey" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" COMMENT="The name of the activity module instance"/> | ||
<FIELD NAME="apitype" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="The name of the activity module instance"/> | ||
<FIELD NAME="username" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="The name of the activity module instance"/> | ||
<FIELD NAME="assistantname" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="The name of the activity module instance"/> | ||
<FIELD NAME="assistant" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="The name of the activity module instance"/><!-- ASSISTANT --> | ||
<FIELD NAME="persistconvo" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="1" COMMENT="Max number of tokens per day for this instance."/><!-- ASSISTANT --> | ||
<FIELD NAME="model" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="The name of the activity module instance"/><!-- CHAT --> | ||
<FIELD NAME="maxperday" TYPE="int" LENGTH="10" NOTNULL="false" DEFAULT="0" COMMENT="Max number of tokens per day for this instance."/><!-- CHAT --> | ||
<FIELD NAME="maxperuser" TYPE="int" LENGTH="10" NOTNULL="false" DEFAULT="0" COMMENT="Max number of tokens per user for this instance."/><!-- CHAT --> | ||
<FIELD NAME="maxpermonth" TYPE="int" LENGTH="10" NOTNULL="false" DEFAULT="0" COMMENT="Max number of tokens per calendar month for this instance."/><!-- CHAT --> | ||
<FIELD NAME="prompt" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="The name of the activity module instance"/><!-- CHAT --> | ||
<FIELD NAME="sourceoftruth" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="The name of the activity module instance"/><!-- CHAT --> | ||
<FIELD NAME="instructiontokens" TYPE="int" LENGTH="10" NOTNULL="false" DEFAULT="0" COMMENT="Max number of tokens per day for this instance."/> | ||
<FIELD NAME="assistantfile" TYPE="int" LENGTH="11" NOTNULL="false" UNSIGNED="false" DEFAULT="0" SEQUENCE="false"/> | ||
<FIELD NAME="assistantfileid" TYPE="char" LENGTH="255" NOTNULL="false" UNSIGNED="false" DEFAULT="" SEQUENCE="false"/> | ||
<FIELD NAME="conversation_logging" TYPE="int" DEFAULT="0" LENGTH="1" NOTNULL="false" COMMENT="Flag for conversation logging for this instance."/> | ||
<FIELD NAME="completionai" TYPE="int" LENGTH="11" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/><!-- CHAT --> | ||
<FIELD NAME="completionaiexchanges" TYPE="int" LENGTH="11" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/><!-- CHAT --> | ||
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Timestamp of when the instance was added to the course."/> | ||
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Timestamp of when the instance was last modified."/> | ||
</FIELDS> | ||
<KEYS> | ||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/> | ||
<KEY NAME="fk_course" TYPE="foreign" FIELDS="course" REFTABLE="course" REFFIELDS="id"/> | ||
</KEYS> | ||
</TABLE> | ||
|
||
<!-- Table for storing usage and logs --> | ||
<TABLE NAME="maici_logs" COMMENT="Stores usage and logs for the Simple AI Chat activity module."> | ||
<FIELDS> | ||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/> | ||
<FIELD NAME="maiciid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="ID of the associated configuration."/> | ||
<FIELD NAME="cmid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="ID of the course module."/> | ||
<FIELD NAME="apitype" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="The name of the activity module instance"/> | ||
<FIELD NAME="logging" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" COMMENT="Max number of tokens per day for this instance."/> | ||
<FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="ID of the course this activity is part of."/> | ||
<FIELD NAME="prompt_tokens" TYPE="int" LENGTH="10" NOTNULL="true" COMMENT="Token usage: prompt"/> | ||
<FIELD NAME="completion_tokens" TYPE="int" LENGTH="10" NOTNULL="true" COMMENT="Token usage: completion"/> | ||
<FIELD NAME="total_tokens" TYPE="int" LENGTH="10" NOTNULL="true" COMMENT="Token usage: total"/> | ||
<FIELD NAME="message" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="Message send to AI"/> | ||
<FIELD NAME="completion" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="Completion message from AI"/> | ||
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Timestamp of when the instance was added to the course."/> | ||
<!-- Add other fields based on your criteria --> | ||
</FIELDS> | ||
<KEYS> | ||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/> | ||
<KEY NAME="fk_maici" TYPE="foreign" FIELDS="maiciid" REFTABLE="maici" REFFIELDS="id"/> | ||
<!-- Add foreign keys if needed --> | ||
</KEYS> | ||
</TABLE> | ||
|
||
</TABLES> | ||
|
||
<TABLES> | ||
<TABLE NAME="maici" COMMENT="Stores the maici activity module instances."> | ||
<FIELDS> | ||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/> | ||
<FIELD NAME="course" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="ID of the course this activity is part of."/> | ||
<FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="The name of the activity module instance"/> | ||
<FIELD NAME="intro" TYPE="text" NOTNULL="true" SEQUENCE="false"/> | ||
<FIELD NAME="introformat" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="The format of the intro field."/> | ||
<FIELD NAME="instructions_submit" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="Instruction block (HTML)"/> | ||
<FIELD NAME="instructionsformat" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="Instruction block (HTML)"/> | ||
<FIELD NAME="apikey" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" COMMENT="The name of the activity module instance"/> | ||
<FIELD NAME="apitype" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="The name of the activity module instance"/> | ||
<FIELD NAME="username" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="The name of the activity module instance"/> | ||
<FIELD NAME="assistantname" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="The name of the activity module instance"/> | ||
<FIELD NAME="assistant" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="The name of the activity module instance"/> | ||
<FIELD NAME="persistconvo" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="1" SEQUENCE="false" COMMENT="Max number of tokens per day for this instance."/> | ||
<FIELD NAME="model" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="The name of the activity module instance"/> | ||
<FIELD NAME="maxperday" TYPE="int" LENGTH="10" NOTNULL="false" DEFAULT="0" SEQUENCE="false" COMMENT="Max number of tokens per day for this instance."/> | ||
<FIELD NAME="maxperuser" TYPE="int" LENGTH="10" NOTNULL="false" DEFAULT="0" SEQUENCE="false" COMMENT="Max number of tokens per user for this instance."/> | ||
<FIELD NAME="maxpermonth" TYPE="int" LENGTH="10" NOTNULL="false" DEFAULT="0" SEQUENCE="false" COMMENT="Max number of tokens per calendar month for this instance."/> | ||
<FIELD NAME="prompt" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="The name of the activity module instance"/> | ||
<FIELD NAME="sourceoftruth" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="The name of the activity module instance"/> | ||
<FIELD NAME="instructiontokens" TYPE="int" LENGTH="10" NOTNULL="false" DEFAULT="0" SEQUENCE="false" COMMENT="Max number of tokens per day for this instance."/> | ||
<FIELD NAME="assistantfile" TYPE="int" LENGTH="11" NOTNULL="false" DEFAULT="0" SEQUENCE="false"/> | ||
<FIELD NAME="assistantfileid" TYPE="char" LENGTH="255" NOTNULL="false" DEFAULT="" SEQUENCE="false"/> | ||
<FIELD NAME="conversation_logging" TYPE="int" LENGTH="1" NOTNULL="false" DEFAULT="0" SEQUENCE="false" COMMENT="Flag for conversation logging for this instance."/> | ||
<FIELD NAME="completionai" TYPE="int" LENGTH="11" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/> | ||
<FIELD NAME="completionaiexchanges" TYPE="int" LENGTH="11" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/> | ||
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Timestamp of when the instance was added to the course."/> | ||
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Timestamp of when the instance was last modified."/> | ||
<FIELD NAME="apiurl" TYPE="text" NOTNULL="false" SEQUENCE="false"/> | ||
</FIELDS> | ||
<KEYS> | ||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/> | ||
<KEY NAME="fk_course" TYPE="foreign" FIELDS="course" REFTABLE="course" REFFIELDS="id"/> | ||
</KEYS> | ||
</TABLE> | ||
<TABLE NAME="maici_logs" COMMENT="Stores usage and logs for the Simple AI Chat activity module."> | ||
<FIELDS> | ||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/> | ||
<FIELD NAME="maiciid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="ID of the associated configuration."/> | ||
<FIELD NAME="cmid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="ID of the course module."/> | ||
<FIELD NAME="apitype" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="The name of the activity module instance"/> | ||
<FIELD NAME="logging" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Max number of tokens per day for this instance."/> | ||
<FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="ID of the course this activity is part of."/> | ||
<FIELD NAME="prompt_tokens" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="Token usage: prompt"/> | ||
<FIELD NAME="completion_tokens" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="Token usage: completion"/> | ||
<FIELD NAME="total_tokens" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="Token usage: total"/> | ||
<FIELD NAME="message" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="Message send to AI"/> | ||
<FIELD NAME="completion" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="Completion message from AI"/> | ||
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Timestamp of when the instance was added to the course."/> | ||
</FIELDS> | ||
<KEYS> | ||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/> | ||
<KEY NAME="fk_maici" TYPE="foreign" FIELDS="maiciid" REFTABLE="maici" REFFIELDS="id"/> | ||
</KEYS> | ||
</TABLE> | ||
</TABLES> | ||
</XMLDB> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clean up comment