Skip to content

Commit

Permalink
chore: build and documentation for release
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Dec 28, 2024
1 parent a96ddd2 commit 2298b73
Show file tree
Hide file tree
Showing 50 changed files with 414 additions and 197 deletions.
155 changes: 112 additions & 43 deletions dist/maidr.js
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,13 @@ class Constants {

clientToken = null;

/**
* Mark and recall vars. Used to store the current mark and recall state of the chart.
* @type {Array<number>}
* @default Array(10).fill(null)
*/
mark = Array(10).fill(null);

/**
* Stops the autoplay if it is currently running.
*
Expand Down Expand Up @@ -2179,9 +2186,9 @@ class ChatLLM {
img = await constants.ConvertSVGtoJPG(singleMaidr.id, 'gemini');
}
if (constants.emailAuthKey) {
chatLLM.GeminiPromptAPI(text, img);
chatLLM.GeminiPromptRemote(text, img);
} else {
chatLLM.GeminiPrompt(text, img);
chatLLM.GeminiPromptLocal(text, img);
}
}

Expand Down Expand Up @@ -2304,10 +2311,10 @@ class ChatLLM {

if (model == 'openai') {
text = data.choices[0].message.content;
let i = this.requestJson.messages.length;
this.requestJson.messages[i] = {};
this.requestJson.messages[i].role = 'assistant';
this.requestJson.messages[i].content = text;
let i = this.requestJsonOpenAI.messages.length;
this.requestJsonOpenAI.messages[i] = {};
this.requestJsonOpenAI.messages[i].role = 'assistant';
this.requestJsonOpenAI.messages[i].content = text;

if (data.error) {
chatLLM.DisplayChatMessage(LLMName, 'Error processing request.', true);
Expand All @@ -2318,6 +2325,12 @@ class ChatLLM {
} else if (model == 'gemini') {
if (data.text()) {
text = data.text();
if (this.requestJsonGemini.contents.length > 2) {
let i = this.requestJsonGemini.contents.length;
this.requestJsonGemini.contents[i] = {};
this.requestJsonGemini.contents[i].role = 'model';
this.requestJsonGemini.contents[i].content = text;
}
chatLLM.DisplayChatMessage(LLMName, text);
} else {
if (!data.error) {
Expand Down Expand Up @@ -2360,7 +2373,7 @@ class ChatLLM {
*/
fakeLLMResponseData() {
let responseText = {};
if (this.requestJson.messages.length > 2) {
if (this.requestJsonOpenAI.messages.length > 2) {
// subsequent responses
responseText = {
id: 'chatcmpl-8Y44iRCRrohYbAqm8rfBbJqTUADC7',
Expand Down Expand Up @@ -2567,32 +2580,32 @@ class ChatLLM {
let backupMessage =
'Describe ' + singleMaidr.type + ' charts to a blind person';
// headers and sys message
if (!this.requestJson) {
this.requestJson = {};
//this.requestJson.model = 'gpt-4-vision-preview';
this.requestJson.model = 'gpt-4o-2024-11-20';
this.requestJson.max_tokens = constants.LLMmaxResponseTokens; // note: if this is too short (tested with less than 200), the response gets cut off
if (!this.requestJsonOpenAI) {
this.requestJsonOpenAI = {};
//this.requestJsonOpenAI.model = 'gpt-4-vision-preview';
this.requestJsonOpenAI.model = 'gpt-4o-2024-11-20';
this.requestJsonOpenAI.max_tokens = constants.LLMmaxResponseTokens; // note: if this is too short (tested with less than 200), the response gets cut off

// sys message
this.requestJson.messages = [];
this.requestJson.messages[0] = {};
this.requestJson.messages[0].role = 'system';
this.requestJson.messages[0].content = sysMessage;
this.requestJsonOpenAI.messages = [];
this.requestJsonOpenAI.messages[0] = {};
this.requestJsonOpenAI.messages[0].role = 'system';
this.requestJsonOpenAI.messages[0].content = sysMessage;
if (constants.LLMPreferences) {
this.requestJson.messages[1] = {};
this.requestJson.messages[1].role = 'system';
this.requestJson.messages[1].content = constants.LLMPreferences;
this.requestJsonOpenAI.messages[1] = {};
this.requestJsonOpenAI.messages[1].role = 'system';
this.requestJsonOpenAI.messages[1].content = constants.LLMPreferences;
}
}

// user message
// if we have an image (first time only), send the image and the text, otherwise just the text
let i = this.requestJson.messages.length;
this.requestJson.messages[i] = {};
this.requestJson.messages[i].role = 'user';
let i = this.requestJsonOpenAI.messages.length;
this.requestJsonOpenAI.messages[i] = {};
this.requestJsonOpenAI.messages[i].role = 'user';
if (img) {
// first message, include the img
this.requestJson.messages[i].content = [
this.requestJsonOpenAI.messages[i].content = [
{
type: 'text',
text: text,
Expand All @@ -2604,10 +2617,10 @@ class ChatLLM {
];
} else {
// just the text
this.requestJson.messages[i].content = text;
this.requestJsonOpenAI.messages[i].content = text;
}

return this.requestJson;
return this.requestJsonOpenAI;
}

GeminiJson(text, img = null) {
Expand Down Expand Up @@ -2672,7 +2685,7 @@ class ChatLLM {
return payload;
}

async GeminiPromptAPI(text, imgBase64 = null) {
async GeminiPromptRemote(text, imgBase64 = null) {
let url = constants.baseURL + 'gemini' + constants.code;

// Create the prompt
Expand All @@ -2689,15 +2702,28 @@ class ChatLLM {
}
constants.LLMImage = imgBase64;

let requestJson = chatLLM.GeminiJson(prompt, imgBase64);
if (!this.requestJsonGemini) {
// this is our first message, do the full construction
this.requestJsonGemini = chatLLM.GeminiJson(prompt, imgBase64);
} else {
// subsequent messages, just add the new user message
let i = this.requestJsonGemini.contents.length;
this.requestJsonGemini.contents[i] = {};
this.requestJsonGemini.contents[i].role = 'user';
this.requestJsonGemini.contents[i].parts = [
{
text: text,
},
];
}

const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authentication: constants.emailAuthKey + ' ' + constants.clientToken,
},
body: JSON.stringify(requestJson),
body: JSON.stringify(this.requestJsonGemini),
});
if (response.ok) {
const responseJson = await response.json();
Expand All @@ -2713,7 +2739,7 @@ class ChatLLM {
}
}

async GeminiPrompt(text, imgBase64 = null) {
async GeminiPromptLocal(text, imgBase64 = null) {
// https://ai.google.dev/docs/gemini_api_overview#node.js
try {
// Save the image for next time
Expand All @@ -2735,29 +2761,32 @@ class ChatLLM {
}); // old model was 'gemini-pro-vision'

// Create the prompt
let prompt = constants.LLMSystemMessage;
if (constants.LLMPreferences) {
prompt += constants.LLMPreferences;
if (!this.requestJsonGemini) {
// this is our first message, do the full construction
this.requestJsonGemini = chatLLM.GeminiJson(prompt, imgBase64);
} else {
// subsequent messages, just add the new user message
let i = this.requestJsonGemini.contents.length;
this.requestJsonGemini.contents[i] = {};
this.requestJsonGemini.contents[i].role = 'user';
this.requestJsonGemini.contents[i].parts = [
{
text: text,
},
];
}
prompt += '\n\n' + text; // Use the text parameter as the prompt
const image = {
inlineData: {
data: imgBase64, // Use the base64 image string
mimeType: 'image/png', // Or the appropriate mime type of your image
},
};

// Generate the content
//console.log('LLM request: ', prompt, image);
const result = await model.generateContent([prompt, image]);
const result = await model.generateContent(this.requestJsonGemini);
//console.log(result.response.text());

// Process the response
chatLLM.ProcessLLMResponse(result.response, 'gemini');
} catch (error) {
chatLLM.WaitingSound(false);
chatLLM.DisplayChatMessage('Gemini', 'Error processing request.', true);
console.error('Error in GeminiPrompt:', error);
console.error('Error in GeminiPromptLocal:', error);
throw error; // Rethrow the error for further handling if necessary
}
}
Expand Down Expand Up @@ -2822,7 +2851,7 @@ class ChatLLM {
document.getElementById('chatLLM_chat_history').innerHTML = '';

// reset the data
this.requestJson = null;
this.requestJsonOpenAI = null;
this.firstTime = true;

// and start over, if enabled, or window is open
Expand Down Expand Up @@ -9085,8 +9114,10 @@ class Control {
* @returns {void}
*/
async SetKeyControls() {
// home / end: first / last element
// not available in review mode
constants.events.push([
document,
[constants.chart, constants.brailleInput],
'keydown',
function (e) {
// ctrl/cmd: stop autoplay
Expand Down Expand Up @@ -9134,6 +9165,44 @@ class Control {
},
]);

// mark and recall
// mark with M + # (0-9), recall with m + # (0-9)
// available in chart and braille, not review
let lastKeytime = 0;
let lastKey = null;
constants.events.push([
[constants.chart, constants.brailleInput],
'keydown',
function (e) {
// setup
const now = new Date().getTime();
const key = e.key;

// check for keypress within threshold
if (now - lastKeytime < constants.keypressInterval) {
// mark with M
if (lastKey == 'M' && /[0-9]/.test(key)) {
const markIndex = parseInt(key, 10);
constants.mark[markIndex] = JSON.parse(JSON.stringify(position)); // deep copy
display.announceText('Marked position ' + markIndex);
}

// recall with m
if (lastKey == 'm' && /[0-9]/.test(key)) {
const recallIndex = parseInt(key, 10);
if (constants.mark[recallIndex]) {
position = constants.mark[recallIndex];
control.UpdateAll();
}
}
}

// update last key and time
lastKey = key;
lastKeytime = now;
},
]);

// Init a few things
let lastPlayed = '';
if ([].concat(singleMaidr.type).includes('bar')) {
Expand Down
2 changes: 1 addition & 1 deletion dist/maidr.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/AdvancedUserSettings.html
Original file line number Diff line number Diff line change
Expand Up @@ -1322,7 +1322,7 @@ <h5>Type:</h5>
<br class="clear">

<footer>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Fri Dec 27 2024 00:18:44 GMT+0000 (Coordinated Universal Time) using the Minami theme.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Sat Dec 28 2024 00:18:23 GMT+0000 (Coordinated Universal Time) using the Minami theme.
</footer>

<script>prettyPrint();</script>
Expand Down
2 changes: 1 addition & 1 deletion docs/Audio.html
Original file line number Diff line number Diff line change
Expand Up @@ -1396,7 +1396,7 @@ <h4 class="name" id="playTone"><span class="type-signature"></span>playTone<span
<br class="clear">

<footer>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Fri Dec 27 2024 00:18:44 GMT+0000 (Coordinated Universal Time) using the Minami theme.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Sat Dec 28 2024 00:18:23 GMT+0000 (Coordinated Universal Time) using the Minami theme.
</footer>

<script>prettyPrint();</script>
Expand Down
2 changes: 1 addition & 1 deletion docs/AudioProperties.html
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ <h5>Type:</h5>
<br class="clear">

<footer>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Fri Dec 27 2024 00:18:44 GMT+0000 (Coordinated Universal Time) using the Minami theme.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Sat Dec 28 2024 00:18:23 GMT+0000 (Coordinated Universal Time) using the Minami theme.
</footer>

<script>prettyPrint();</script>
Expand Down
2 changes: 1 addition & 1 deletion docs/BTSModes.html
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ <h5>Type:</h5>
<br class="clear">

<footer>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Fri Dec 27 2024 00:18:44 GMT+0000 (Coordinated Universal Time) using the Minami theme.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Sat Dec 28 2024 00:18:23 GMT+0000 (Coordinated Universal Time) using the Minami theme.
</footer>

<script>prettyPrint();</script>
Expand Down
2 changes: 1 addition & 1 deletion docs/BarChart.html
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,7 @@ <h4 class="name" id="UnSelectPrevious"><span class="type-signature"></span>UnSel
<br class="clear">

<footer>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Fri Dec 27 2024 00:18:44 GMT+0000 (Coordinated Universal Time) using the Minami theme.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Sat Dec 28 2024 00:18:23 GMT+0000 (Coordinated Universal Time) using the Minami theme.
</footer>

<script>prettyPrint();</script>
Expand Down
2 changes: 1 addition & 1 deletion docs/BasicChartProperties.html
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ <h5>Type:</h5>
<br class="clear">

<footer>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Fri Dec 27 2024 00:18:44 GMT+0000 (Coordinated Universal Time) using the Minami theme.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Sat Dec 28 2024 00:18:23 GMT+0000 (Coordinated Universal Time) using the Minami theme.
</footer>

<script>prettyPrint();</script>
Expand Down
2 changes: 1 addition & 1 deletion docs/BoxPlot.html
Original file line number Diff line number Diff line change
Expand Up @@ -1329,7 +1329,7 @@ <h5>Returns:</h5>
<br class="clear">

<footer>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Fri Dec 27 2024 00:18:44 GMT+0000 (Coordinated Universal Time) using the Minami theme.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Sat Dec 28 2024 00:18:23 GMT+0000 (Coordinated Universal Time) using the Minami theme.
</footer>

<script>prettyPrint();</script>
Expand Down
2 changes: 1 addition & 1 deletion docs/BoxplotRect.html
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ <h4 class="name" id="UpdateRect"><span class="type-signature"></span>UpdateRect<
<br class="clear">

<footer>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Fri Dec 27 2024 00:18:44 GMT+0000 (Coordinated Universal Time) using the Minami theme.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Sat Dec 28 2024 00:18:23 GMT+0000 (Coordinated Universal Time) using the Minami theme.
</footer>

<script>prettyPrint();</script>
Expand Down
Loading

0 comments on commit 2298b73

Please sign in to comment.