Skip to content

Commit

Permalink
Allowing for dynamically selecting model/type through callback
Browse files Browse the repository at this point in the history
  • Loading branch information
polterguy committed Sep 29, 2023
1 parent 700f59b commit 8ac078d
Showing 1 changed file with 50 additions and 38 deletions.
88 changes: 50 additions & 38 deletions backend/files/system/openai/front.files/chat/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ let ainiroStream = [[stream]];
// True if speech is turned on.
let aistaSpeech = [[speech]];

// Used for refernces.
// Used for references.
let ainiro_references = [];

// Type or model to use.
let ainiroChatbotType = '[[type]]';

// Downloading icofont, making sure we only download it once.
if (!window.ainiroHasDownloadIcofont) {
window.ainiroHasDownloadIcofont = true;
Expand Down Expand Up @@ -434,54 +437,57 @@ function ensureInitialQuestionnaireIsFetched() {
const inp = window.document.getElementsByClassName('aista-chat-prompt')[0];
inp.disabled = true;
ainiroHasFetchedQuestionnaire = true;
fetch('[[url]]/magic/system/openai/questionnaire?type=' + encodeURIComponent('[[type]]'))
.then(res => {
return res.text()
})
.then(res => {
if (window.getAiniroChatbotType) {
ainiroChatbotType = window.getAiniroChatbotType() ?? ainiroChatbotType;
}
fetch('[[url]]/magic/system/openai/questionnaire?type=' + encodeURIComponent(ainiroChatbotType))
.then(res => {
return res.text()
})
.then(res => {

// Storing initial questions.
ainiroQuestionnaire = JSON.parse(res || '{}');
// Storing initial questions.
ainiroQuestionnaire = JSON.parse(res || '{}');

// Need access to prompt input element.
const inp = window.document.getElementsByClassName('aista-chat-prompt')[0];
// Need access to prompt input element.
const inp = window.document.getElementsByClassName('aista-chat-prompt')[0];

// Enabling prompt input.
inp.disabled = false;
inp.focus();
// Enabling prompt input.
inp.disabled = false;
inp.focus();

// Checking if we have a questionnaire, and if not, returning early.
if (!ainiroQuestionnaire.name) {
return;
}
// Checking if we have a questionnaire, and if not, returning early.
if (!ainiroQuestionnaire.name) {
return;
}

/*
* Checking if this is a 'single-shot' type of questionnaire,
* at which point we drop it if user has answered it before.
*/
if (ainiroQuestionnaire.type === 'single-shot') {

/*
* Checking if this is a 'single-shot' type of questionnaire,
* at which point we drop it if user has answered it before.
*/
if (ainiroQuestionnaire.type === 'single-shot') {
// Checking local storage to see if user has answered before.
const previousQuestionnaire = localStorage.getItem('ainiro-questionnaire.' + ainiroQuestionnaire.name);
if (previousQuestionnaire !== null) {

// Checking local storage to see if user has answered before.
const previousQuestionnaire = localStorage.getItem('ainiro-questionnaire.' + ainiroQuestionnaire.name);
if (previousQuestionnaire !== null) {
// User has previously answered questionnaire, and it's a 'single-shot' questionnaire.
ainiroQuestionnaire = {};

// User has previously answered questionnaire, and it's a 'single-shot' questionnaire.
ainiroQuestionnaire = {};
} else {

// We've got a questionnaire
inp.value = '';
}
} else {

// We've got a questionnaire
inp.value = '';
}
} else {

// We've got a questionnaire
inp.value = '';
}

// Starting questionnaire loop.
askNextQuestion();
});
// Starting questionnaire loop.
askNextQuestion();
});
}

// Contains all action values for questionnaire.
Expand Down Expand Up @@ -671,9 +677,12 @@ function aista_invoke_prompt(msg, token, speech) {
// Creating our URL.
let url = `[[url]]/magic/system/openai/answer`;

// Creating our payload
// Creating our payload.
if (window.getAiniroChatbotType) {
ainiroChatbotType = window.getAiniroChatbotType() ?? ainiroChatbotType;
}
let payload = {
type: '[[type]]'
type: ainiroChatbotType
};
if (token) {
payload.recaptcha_response = token;
Expand Down Expand Up @@ -737,7 +746,10 @@ function aista_invoke_prompt(msg, token, speech) {
} else {

// Creating our URL.
let url = `[[url]]/magic/system/openai/chat?prompt=` + encodeURIComponent(msg) + '&type=[[type]]';
if (window.getAiniroChatbotType) {
ainiroChatbotType = window.getAiniroChatbotType() ?? ainiroChatbotType;
}
let url = `[[url]]/magic/system/openai/chat?prompt=` + encodeURIComponent(msg) + '&type=' + ainiroChatbotType;
if (token) {
url += '&recaptcha_response=' + encodeURIComponent(token);
}
Expand Down

0 comments on commit 8ac078d

Please sign in to comment.