Merge branch 'staging' into world_info_force_activate_expansion
| @@ -2208,10 +2208,9 @@ function processReply(str) { | |||
| 2208 | 2208 | ||
| 2209 | str = str.replaceAll('"', ''); | 2209 | str = str.replaceAll('"', ''); |
| 2210 | str = str.replaceAll('“', ''); | 2210 | str = str.replaceAll('“', ''); |
| 2211 | str = str.replaceAll('.', ','); | ||
| 2212 | str = str.replaceAll('\n', ', '); | 2211 | str = str.replaceAll('\n', ', '); |
| 2213 | str = str.normalize('NFD'); | 2212 | str = str.normalize('NFD'); |
| 2214 | str = str.replace(/[^a-zA-Z0-9,:_(){}<>[\]\-']+/g, ' '); | 2213 | str = str.replace(/[^a-zA-Z0-9\.,:_(){}<>[\]\-']+/g, ' '); |
| 2215 | str = str.replace(/\s+/g, ' '); // Collapse multiple whitespaces into one | 2214 | str = str.replace(/\s+/g, ' '); // Collapse multiple whitespaces into one |
| 2216 | str = str.trim(); | 2215 | str = str.trim(); |
| 2217 | 2216 | ||
| @@ -2675,8 +2674,7 @@ async function generateTogetherAIImage(prompt, negativePrompt, signal) { | |||
| 2675 | }); | 2674 | }); |
| 2676 | 2675 | ||
| 2677 | if (result.ok) { | 2676 | if (result.ok) { |
| 2678 | const data = await result.json(); | 2677 | return await result.json(); |
| 2679 | return { format: 'jpg', data: data?.output?.choices?.[0]?.image_base64 }; | ||
| 2680 | } else { | 2678 | } else { |
| 2681 | const text = await result.text(); | 2679 | const text = await result.text(); |
| 2682 | throw new Error(text); | 2680 | throw new Error(text); |
| @@ -514,7 +514,8 @@ export function parseBooleanOperands(args) { | |||
| 514 | return ''; | 514 | return ''; |
| 515 | } | 515 | } |
| 516 | 516 | ||
| 517 | const operandNumber = Number(operand); | 517 | // parseFloat will return NaN for spaces. |
| 518 | const operandNumber = parseFloat(operand); | ||
| 518 | 519 | ||
| 519 | if (!isNaN(operandNumber)) { | 520 | if (!isNaN(operandNumber)) { |
| 520 | return operandNumber; | 521 | return operandNumber; |
| @@ -1686,8 +1686,8 @@ export function sortWorldInfoEntries(data, { customSort = null } = {}) { | |||
| 1686 | } else if (sortRule === 'priority') { | 1686 | } else if (sortRule === 'priority') { |
| 1687 | // First constant, then normal, then disabled. | 1687 | // First constant, then normal, then disabled. |
| 1688 | primarySort = (a, b) => { | 1688 | primarySort = (a, b) => { |
| 1689 | const aValue = a.constant ? 0 : a.disable ? 2 : 1; | 1689 | const aValue = a.disable ? 2 : a.constant ? 0 : 1; |
| 1690 | const bValue = b.constant ? 0 : b.disable ? 2 : 1; | 1690 | const bValue = b.disable ? 2 : b.constant ? 0 : 1; |
| 1691 | return aValue - bValue; | 1691 | return aValue - bValue; |
| 1692 | }; | 1692 | }; |
| 1693 | } else { | 1693 | } else { |
| @@ -337,7 +337,7 @@ async function sendMakerSuiteRequest(request, response) { | |||
| 337 | ? (stream ? 'streamGenerateContent' : 'generateContent') | 337 | ? (stream ? 'streamGenerateContent' : 'generateContent') |
| 338 | : (isText ? 'generateText' : 'generateMessage'); | 338 | : (isText ? 'generateText' : 'generateMessage'); |
| 339 | 339 | ||
| 340 | const generateResponse = await fetch(`${apiUrl}/${apiVersion}/models/${model}:${responseType}?key=${apiKey}${stream ? '&alt=sse' : ''}`, { | 340 | const generateResponse = await fetch(`${apiUrl.toString().replace(/\/$/, '')}/${apiVersion}/models/${model}:${responseType}?key=${apiKey}${stream ? '&alt=sse' : ''}`, { |
| 341 | body: JSON.stringify(body), | 341 | body: JSON.stringify(body), |
| 342 | method: 'POST', | 342 | method: 'POST', |
| 343 | headers: { | 343 | headers: { |
| @@ -607,10 +607,9 @@ together.post('/generate', jsonParser, async (request, response) => { | |||
| 607 | 607 | ||
| 608 | console.log('TogetherAI request:', request.body); | 608 | console.log('TogetherAI request:', request.body); |
| 609 | 609 | ||
| 610 | const result = await fetch('https://api.together.xyz/api/inference', { | 610 | const result = await fetch('https://api.together.xyz/v1/images/generations', { |
| 611 | method: 'POST', | 611 | method: 'POST', |
| 612 | body: JSON.stringify({ | 612 | body: JSON.stringify({ |
| 613 | request_type: 'image-model-inference', | ||
| 614 | prompt: request.body.prompt, | 613 | prompt: request.body.prompt, |
| 615 | negative_prompt: request.body.negative_prompt, | 614 | negative_prompt: request.body.negative_prompt, |
| 616 | height: request.body.height, | 615 | height: request.body.height, |
| @@ -620,8 +619,6 @@ together.post('/generate', jsonParser, async (request, response) => { | |||
| 620 | n: 1, | 619 | n: 1, |
| 621 | // Limited to 10000 on playground, works fine with more. | 620 | // Limited to 10000 on playground, works fine with more. |
| 622 | seed: request.body.seed >= 0 ? request.body.seed : Math.floor(Math.random() * 10_000_000), | 621 | 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), | ||
| 625 | }), | 622 | }), |
| 626 | headers: { | 623 | headers: { |
| 627 | 'Content-Type': 'application/json', | 624 | 'Content-Type': 'application/json', |
| @@ -630,19 +627,22 @@ together.post('/generate', jsonParser, async (request, response) => { | |||
| 630 | }); | 627 | }); |
| 631 | 628 | ||
| 632 | if (!result.ok) { | 629 | if (!result.ok) { |
| 633 | console.log('TogetherAI returned an error.'); | 630 | console.log('TogetherAI returned an error.', { body: await result.text() }); |
| 634 | return response.sendStatus(500); | 631 | return response.sendStatus(500); |
| 635 | } | 632 | } |
| 636 | 633 | ||
| 637 | const data = await result.json(); | 634 | const data = await result.json(); |
| 638 | console.log('TogetherAI response:', data); | 635 | console.log('TogetherAI response:', data); |
| 639 | 636 | ||
| 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'); | ||
| 643 | } | 643 | } |
| 644 | 644 | ||
| 645 | return response.send(data); | 645 | return response.send({ format: 'jpg', data: b64_json }); |
| 646 | } catch (error) { | 646 | } catch (error) { |
| 647 | console.log(error); | 647 | console.log(error); |
| 648 | return response.sendStatus(500); | 648 | return response.sendStatus(500); |