Skip to content
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

MBS-9809: Provide component and context id #16

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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' => 2024092700,
'local_ai_manager' => 2025010701,
];