From 28861660ef5986223f31d8cf54da4c18406a7c2c Mon Sep 17 00:00:00 2001 From: Khreed <135299775+KhreedAI@users.noreply.github.com> Date: Wed, 9 Oct 2024 19:17:42 -0400 Subject: [PATCH 1/7] Fix Priority Sort Corrected and expanded priority sort logic to sort by: First constant, then normal, then disabled, then by comment. --- public/scripts/world-info.js | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/public/scripts/world-info.js b/public/scripts/world-info.js index 6aad5d92e..a36d405c2 100644 --- a/public/scripts/world-info.js +++ b/public/scripts/world-info.js @@ -1678,11 +1678,34 @@ export function sortWorldInfoEntries(data, { customSort = null } = {}) { return aValue - bValue; }; } else if (sortRule === 'priority') { - // First constant, then normal, then disabled. + // First constant, then normal, then disabled, then by comment. primarySort = (a, b) => { - const aValue = a.constant ? 0 : a.disable ? 2 : 1; - const bValue = b.constant ? 0 : b.disable ? 2 : 1; - return aValue - bValue; + // Determine priority based on disable and constant flags + const aPriority = a.disable ? 2 : a.constant ? 0 : 1; + const bPriority = b.disable ? 2 : b.constant ? 0 : 1; + + // Compare priorities first + if (aPriority !== bPriority) { + return aPriority - bPriority; + } + + // Normalize comments for comparison, handling null/undefined + const commentA = a.comment ? a.comment.toLowerCase() : ''; + const commentB = b.comment ? b.comment.toLowerCase() : ''; + + // Assign constant values for further comparison + const constantA = a.constant ? 0 : 1; + const constantB = b.constant ? 0 : 1; + + // If priorities are equal, compare constants + if (aPriority === bPriority) { + if (constantA !== constantB) { + return constantA - constantB; + } + } + + // Finally, compare comments alphabetically + return commentA.localeCompare(commentB); }; } else { primarySort = (a, b) => { From efb63c7f24d1d1dd456b9d39c5340dcf67131de6 Mon Sep 17 00:00:00 2001 From: Khreed <135299775+KhreedAI@users.noreply.github.com> Date: Thu, 10 Oct 2024 10:19:16 -0400 Subject: [PATCH 2/7] Re-evaluate world info entry - simplified priority sort order Changed priority primarySort ternary to check disabled first, then constant, then normal. --- public/scripts/world-info.js | 31 ++++--------------------------- 1 file changed, 4 insertions(+), 27 deletions(-) diff --git a/public/scripts/world-info.js b/public/scripts/world-info.js index a36d405c2..8cd3c8187 100644 --- a/public/scripts/world-info.js +++ b/public/scripts/world-info.js @@ -1678,34 +1678,11 @@ export function sortWorldInfoEntries(data, { customSort = null } = {}) { return aValue - bValue; }; } else if (sortRule === 'priority') { - // First constant, then normal, then disabled, then by comment. + // First constant, then normal, then disabled. primarySort = (a, b) => { - // Determine priority based on disable and constant flags - const aPriority = a.disable ? 2 : a.constant ? 0 : 1; - const bPriority = b.disable ? 2 : b.constant ? 0 : 1; - - // Compare priorities first - if (aPriority !== bPriority) { - return aPriority - bPriority; - } - - // Normalize comments for comparison, handling null/undefined - const commentA = a.comment ? a.comment.toLowerCase() : ''; - const commentB = b.comment ? b.comment.toLowerCase() : ''; - - // Assign constant values for further comparison - const constantA = a.constant ? 0 : 1; - const constantB = b.constant ? 0 : 1; - - // If priorities are equal, compare constants - if (aPriority === bPriority) { - if (constantA !== constantB) { - return constantA - constantB; - } - } - - // Finally, compare comments alphabetically - return commentA.localeCompare(commentB); + const aValue = a.disable ? 2 : a.constant ? 0 : 1; + const bValue = b.disable ? 2 : b.constant ? 0 : 1; + return aValue - bValue; }; } else { primarySort = (a, b) => { From ac05840b8177e45a2d47460492cd79a757d26661 Mon Sep 17 00:00:00 2001 From: Honey Tree Date: Thu, 10 Oct 2024 14:58:03 -0300 Subject: [PATCH 3/7] Remove a trailing slash from the API URL in case it gets added in by URL.toString --- src/endpoints/backends/chat-completions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/endpoints/backends/chat-completions.js b/src/endpoints/backends/chat-completions.js index c190e6f71..4a4b187ce 100644 --- a/src/endpoints/backends/chat-completions.js +++ b/src/endpoints/backends/chat-completions.js @@ -337,7 +337,7 @@ async function sendMakerSuiteRequest(request, response) { ? (stream ? 'streamGenerateContent' : 'generateContent') : (isText ? 'generateText' : 'generateMessage'); - const generateResponse = await fetch(`${apiUrl}/${apiVersion}/models/${model}:${responseType}?key=${apiKey}${stream ? '&alt=sse' : ''}`, { + const generateResponse = await fetch(`${apiUrl.toString().replace(/\/$/, '')}/${apiVersion}/models/${model}:${responseType}?key=${apiKey}${stream ? '&alt=sse' : ''}`, { body: JSON.stringify(body), method: 'POST', headers: { From fe33519422c8a62cd73aad33ec5473fe07314597 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Fri, 11 Oct 2024 15:32:45 +0000 Subject: [PATCH 4/7] Image Generation: Don't replace dots with commas --- public/scripts/extensions/stable-diffusion/index.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/public/scripts/extensions/stable-diffusion/index.js b/public/scripts/extensions/stable-diffusion/index.js index e9d3a7632..8e96370c3 100644 --- a/public/scripts/extensions/stable-diffusion/index.js +++ b/public/scripts/extensions/stable-diffusion/index.js @@ -2208,10 +2208,9 @@ function processReply(str) { str = str.replaceAll('"', ''); str = str.replaceAll('“', ''); - str = str.replaceAll('.', ','); str = str.replaceAll('\n', ', '); str = str.normalize('NFD'); - str = str.replace(/[^a-zA-Z0-9,:_(){}<>[\]\-']+/g, ' '); + str = str.replace(/[^a-zA-Z0-9\.,:_(){}<>[\]\-']+/g, ' '); str = str.replace(/\s+/g, ' '); // Collapse multiple whitespaces into one str = str.trim(); From ed8e379e542e926a5f823abb6b1723f2197a889f Mon Sep 17 00:00:00 2001 From: Devin Bayer Date: Fri, 11 Oct 2024 17:48:33 +0200 Subject: [PATCH 5/7] support new together.ai image generation api --- .../extensions/stable-diffusion/index.js | 3 +-- src/endpoints/stable-diffusion.js | 18 +++++++++--------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/public/scripts/extensions/stable-diffusion/index.js b/public/scripts/extensions/stable-diffusion/index.js index e9d3a7632..58e69f4f2 100644 --- a/public/scripts/extensions/stable-diffusion/index.js +++ b/public/scripts/extensions/stable-diffusion/index.js @@ -2675,8 +2675,7 @@ async function generateTogetherAIImage(prompt, negativePrompt, signal) { }); if (result.ok) { - const data = await result.json(); - return { format: 'jpg', data: data?.output?.choices?.[0]?.image_base64 }; + return await result.json(); } else { const text = await result.text(); throw new Error(text); diff --git a/src/endpoints/stable-diffusion.js b/src/endpoints/stable-diffusion.js index b6348b8b2..0ac395a4d 100644 --- a/src/endpoints/stable-diffusion.js +++ b/src/endpoints/stable-diffusion.js @@ -607,10 +607,9 @@ together.post('/generate', jsonParser, async (request, response) => { console.log('TogetherAI request:', request.body); - const result = await fetch('https://api.together.xyz/api/inference', { + const result = await fetch('https://api.together.xyz/v1/images/generations', { method: 'POST', body: JSON.stringify({ - request_type: 'image-model-inference', prompt: request.body.prompt, negative_prompt: request.body.negative_prompt, height: request.body.height, @@ -620,8 +619,6 @@ together.post('/generate', jsonParser, async (request, response) => { n: 1, // Limited to 10000 on playground, works fine with more. seed: request.body.seed >= 0 ? request.body.seed : Math.floor(Math.random() * 10_000_000), - // Don't know if that's supposed to be random or not. It works either way. - sessionKey: getHexString(40), }), headers: { 'Content-Type': 'application/json', @@ -630,19 +627,22 @@ together.post('/generate', jsonParser, async (request, response) => { }); if (!result.ok) { - console.log('TogetherAI returned an error.'); + console.log('TogetherAI returned an error.', { body: await result.text() }); return response.sendStatus(500); } const data = await result.json(); console.log('TogetherAI response:', data); - if (data.status !== 'finished') { - console.log('TogetherAI job failed.'); - return response.sendStatus(500); + const choice = data?.data?.[0]; + let b64_json = choice.b64_json; + + if(! b64_json) { + const buffer = await (await fetch(choice.url)).buffer(); + b64_json = buffer.toString('base64'); } - return response.send(data); + return response.send({ format: 'jpg', data: b64_json }); } catch (error) { console.log(error); return response.sendStatus(500); From 34b1fa2cffbef30e10b122bcc0502895b24893e1 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Fri, 11 Oct 2024 20:28:54 +0300 Subject: [PATCH 6/7] [chore] Run code format --- src/endpoints/stable-diffusion.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/endpoints/stable-diffusion.js b/src/endpoints/stable-diffusion.js index 0ac395a4d..986774d93 100644 --- a/src/endpoints/stable-diffusion.js +++ b/src/endpoints/stable-diffusion.js @@ -637,7 +637,7 @@ together.post('/generate', jsonParser, async (request, response) => { const choice = data?.data?.[0]; let b64_json = choice.b64_json; - if(! b64_json) { + if (!b64_json) { const buffer = await (await fetch(choice.url)).buffer(); b64_json = buffer.toString('base64'); } From 161fc7f0f091395f7ec34a9ace91596651363ad5 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Fri, 11 Oct 2024 21:01:32 +0300 Subject: [PATCH 7/7] STscript: don't parse boolean operands as 0 for strings containing just spaces --- public/scripts/variables.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/public/scripts/variables.js b/public/scripts/variables.js index f2c340541..7fc12aa54 100644 --- a/public/scripts/variables.js +++ b/public/scripts/variables.js @@ -514,7 +514,8 @@ export function parseBooleanOperands(args) { return ''; } - const operandNumber = Number(operand); + // parseFloat will return NaN for spaces. + const operandNumber = parseFloat(operand); if (!isNaN(operandNumber)) { return operandNumber;