Skip to content

Commit

Permalink
MBS-9809: Provide component and context id
Browse files Browse the repository at this point in the history
  • Loading branch information
PhMemmel committed Jan 16, 2025
1 parent 82bf516 commit a94b71e
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion amd/build/ai_manager.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion amd/build/ai_manager.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion amd/build/dialog.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion amd/build/dialog.min.js.map

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions amd/src/ai_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import {makeRequest} from 'local_ai_manager/make_request';
*
* @param {string} purpose
* @param {string} prompt
* @param {number} contextid
* @param {array} options
* @returns {string}
*/
export const askLocalAiManager = async(purpose, prompt, options = []) => {
export const askLocalAiManager = async(purpose, prompt, contextid, options = []) => {
let result = {};
try {
result = await makeRequest(purpose, prompt, options);
result = await makeRequest(purpose, prompt, 'block_ai_chat', contextid, options);
} catch (error) {
result.code = 'aiconnector';
result.result = error.error + " " + error.message;
Expand Down
14 changes: 7 additions & 7 deletions amd/src/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,14 +299,13 @@ const enterQuestion = async(question) => {
});
}

// Ceck history for length limit.
// Check history for length limit.
const convHistory = await checkMessageHistoryLengthLimit(conversation.messages);

// Options, with conversation history.
const options = {
'component': 'block_ai_chat',
'contextid': contextid,
'conversationcontext': convHistory,
'conversationcontext': convHistory
};

// For a new conversation, get an id.
Expand All @@ -326,11 +325,11 @@ const enterQuestion = async(question) => {
options.itemid = conversation.id;

// Send to local_ai_manager.
let requestresult = await manager.askLocalAiManager('chat', question, options);
let requestresult = await manager.askLocalAiManager('chat', question, contextid, options);

// Handle errors.
if (requestresult.code != 200) {
requestresult = await errorHandling(requestresult, question, options);
requestresult = await errorHandling(requestresult, question, contextid, options);
}

// Attach copy listener.
Expand Down Expand Up @@ -683,10 +682,11 @@ const clickSubmitButton = () => {
* Handle error from local_ai_manager.
* @param {*} requestresult
* @param {*} question
* @param {*} contextid
* @param {*} options
* @returns {object}
*/
const errorHandling = async(requestresult, question, options) => {
const errorHandling = async(requestresult, question, contextid, options) => {

// If code 409, conversationid is already taken, try get new a one.
if (requestresult.code == 409) {
Expand All @@ -699,7 +699,7 @@ const errorHandling = async(requestresult, question, options) => {
displayException(error);
}
// Retry with new id.
requestresult = await manager.askLocalAiManager('chat', question, options);
requestresult = await manager.askLocalAiManager('chat', question, contextid, options);
return requestresult;
}
}
Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
$plugin->component = 'block_ai_chat';
$plugin->maturity = MATURITY_STABLE;
$plugin->dependencies = [
'local_ai_manager' => 2024122900,
'local_ai_manager' => 2025010701,
];

0 comments on commit a94b71e

Please sign in to comment.