Merge branch 'staging' into world_info_force_activate_expansion

a82dce7c87719975a496bb2e80c601a59126d07c

Cohee <18619528+Cohee1207@users.noreply.github.com>

5 files changed, +16 -17Showing whitespace changes
public/scripts/extensions/stable-diffusion/index.js+2 -4
@@ -2208,10 +2208,9 @@ function processReply(str) {
22082208
22092209 str = str.replaceAll('"', '');
22102210 str = str.replaceAll('“', '');
2211- str = str.replaceAll('.', ',');
22122211 str = str.replaceAll('\n', ', ');
22132212 str = str.normalize('NFD');
22142213 str = str.replace(/[^a-zA-Z0-9\.,:_(){}<>[\]\-']+/g, ' ');
22152214 str = str.replace(/\s+/g, ' '); // Collapse multiple whitespaces into one
22162215 str = str.trim();
22172216
@@ -2675,8 +2674,7 @@ async function generateTogetherAIImage(prompt, negativePrompt, signal) {
26752674 });
26762675
26772676 if (result.ok) {
26782677 const data =return await result.json();
2679- return { format: 'jpg', data: data?.output?.choices?.[0]?.image_base64 };
26802678 } else {
26812679 const text = await result.text();
26822680 throw new Error(text);
public/scripts/variables.js+2 -1
@@ -514,7 +514,8 @@ export function parseBooleanOperands(args) {
514514 return '';
515515 }
516516
517- const operandNumber = Number(operand);
517+ // parseFloat will return NaN for spaces.
518+ const operandNumber = parseFloat(operand);
518519
519520 if (!isNaN(operandNumber)) {
520521 return operandNumber;
public/scripts/world-info.js+2 -2
@@ -1686,8 +1686,8 @@ export function sortWorldInfoEntries(data, { customSort = null } = {}) {
16861686 } else if (sortRule === 'priority') {
16871687 // First constant, then normal, then disabled.
16881688 primarySort = (a, b) => {
16891689 const aValue = a.constantdisable ? 02 : a.disableconstant ? 20 : 1;
16901690 const bValue = b.constantdisable ? 02 : b.disableconstant ? 20 : 1;
16911691 return aValue - bValue;
16921692 };
16931693 } else {
src/endpoints/backends/chat-completions.js+1 -1
@@ -337,7 +337,7 @@ async function sendMakerSuiteRequest(request, response) {
337337 ? (stream ? 'streamGenerateContent' : 'generateContent')
338338 : (isText ? 'generateText' : 'generateMessage');
339339
340340 const generateResponse = await fetch(`${apiUrl.toString().replace(/\/$/, '')}/${apiVersion}/models/${model}:${responseType}?key=${apiKey}${stream ? '&alt=sse' : ''}`, {
341341 body: JSON.stringify(body),
342342 method: 'POST',
343343 headers: {
src/endpoints/stable-diffusion.js+9 -9
@@ -607,10 +607,9 @@ together.post('/generate', jsonParser, async (request, response) => {
607607
608608 console.log('TogetherAI request:', request.body);
609609
610610 const result = await fetch('https://api.together.xyz/apiv1/inferenceimages/generations', {
611611 method: 'POST',
612612 body: JSON.stringify({
613- request_type: 'image-model-inference',
614613 prompt: request.body.prompt,
615614 negative_prompt: request.body.negative_prompt,
616615 height: request.body.height,
@@ -620,8 +619,6 @@ together.post('/generate', jsonParser, async (request, response) => {
620619 n: 1,
621620 // Limited to 10000 on playground, works fine with more.
622621 seed: request.body.seed >= 0 ? request.body.seed : Math.floor(Math.random() * 10_000_000),
623- // Don't know if that's supposed to be random or not. It works either way.
624- sessionKey: getHexString(40),
625622 }),
626623 headers: {
627624 'Content-Type': 'application/json',
@@ -630,19 +627,22 @@ together.post('/generate', jsonParser, async (request, response) => {
630627 });
631628
632629 if (!result.ok) {
633630 console.log('TogetherAI returned an error.', { body: await result.text() });
634631 return response.sendStatus(500);
635632 }
636633
637634 const data = await result.json();
638635 console.log('TogetherAI response:', data);
639636
640- if (data.status !== 'finished') {
637+ const choice = data?.data?.[0];
641- console.log('TogetherAI job failed.');
638+ let b64_json = choice.b64_json;
642- return response.sendStatus(500);
639+
640+ if (!b64_json) {
641+ const buffer = await (await fetch(choice.url)).buffer();
642+ b64_json = buffer.toString('base64');
643643 }
644644
645645 return response.send({ format: 'jpg', data: b64_json });
646646 } catch (error) {
647647 console.log(error);
648648 return response.sendStatus(500);