Merge branch 'staging' into es-modules
| @@ -2208,10 +2208,9 @@ function processReply(str) { | ||
| 2208 | 2208 | |
| 2209 | 2209 | str = str.replaceAll('"', ''); |
| 2210 | 2210 | str = str.replaceAll('“', ''); |
| 2211 | - str = str.replaceAll('.', ','); | |
| 2212 | 2211 | str = str.replaceAll('\n', ', '); |
| 2213 | 2212 | str = str.normalize('NFD'); |
| 2214 | 2213 | str = str.replace(/[^a-zA-Z0-9\.,:_(){}<>[\]\-']+/g, ' '); |
| 2215 | 2214 | str = str.replace(/\s+/g, ' '); // Collapse multiple whitespaces into one |
| 2216 | 2215 | str = str.trim(); |
| 2217 | 2216 | |
| @@ -2675,8 +2674,7 @@ async function generateTogetherAIImage(prompt, negativePrompt, signal) { | ||
| 2675 | 2674 | }); |
| 2676 | 2675 | |
| 2677 | 2676 | if (result.ok) { |
| 2678 | 2677 | const data =return await result.json(); |
| 2679 | - return { format: 'jpg', data: data?.output?.choices?.[0]?.image_base64 }; | |
| 2680 | 2678 | } else { |
| 2681 | 2679 | const text = await result.text(); |
| 2682 | 2680 | throw new Error(text); |
| @@ -328,7 +328,7 @@ async function sendMakerSuiteRequest(request, response) { | ||
| 328 | 328 | ? (stream ? 'streamGenerateContent' : 'generateContent') |
| 329 | 329 | : (isText ? 'generateText' : 'generateMessage'); |
| 330 | 330 | |
| 331 | 331 | const generateResponse = await fetch(`${apiUrl.toString().replace(/\/$/, '')}/${apiVersion}/models/${model}:${responseType}?key=${apiKey}${stream ? '&alt=sse' : ''}`, { |
| 332 | 332 | body: JSON.stringify(body), |
| 333 | 333 | method: 'POST', |
| 334 | 334 | headers: { |
| @@ -609,10 +609,9 @@ together.post('/generate', jsonParser, async (request, response) => { | ||
| 609 | 609 | |
| 610 | 610 | console.log('TogetherAI request:', request.body); |
| 611 | 611 | |
| 612 | 612 | const result = await fetch('https://api.together.xyz/apiv1/inferenceimages/generations', { |
| 613 | 613 | method: 'POST', |
| 614 | 614 | body: JSON.stringify({ |
| 615 | - request_type: 'image-model-inference', | |
| 616 | 615 | prompt: request.body.prompt, |
| 617 | 616 | negative_prompt: request.body.negative_prompt, |
| 618 | 617 | height: request.body.height, |
| @@ -622,8 +621,6 @@ together.post('/generate', jsonParser, async (request, response) => { | ||
| 622 | 621 | n: 1, |
| 623 | 622 | // Limited to 10000 on playground, works fine with more. |
| 624 | 623 | seed: request.body.seed >= 0 ? request.body.seed : Math.floor(Math.random() * 10_000_000), |
| 625 | - // Don't know if that's supposed to be random or not. It works either way. | |
| 626 | - sessionKey: getHexString(40), | |
| 627 | 624 | }), |
| 628 | 625 | headers: { |
| 629 | 626 | 'Content-Type': 'application/json', |
| @@ -632,19 +629,22 @@ together.post('/generate', jsonParser, async (request, response) => { | ||
| 632 | 629 | }); |
| 633 | 630 | |
| 634 | 631 | if (!result.ok) { |
| 635 | 632 | console.log('TogetherAI returned an error.', { body: await result.text() }); |
| 636 | 633 | return response.sendStatus(500); |
| 637 | 634 | } |
| 638 | 635 | |
| 639 | 636 | const data = await result.json(); |
| 640 | 637 | console.log('TogetherAI response:', data); |
| 641 | 638 | |
| 642 | - if (data.status !== 'finished') { | |
| 639 | + const choice = data?.data?.[0]; | |
| 643 | - console.log('TogetherAI job failed.'); | |
| 640 | + let b64_json = choice.b64_json; | |
| 644 | - return response.sendStatus(500); | |
| 641 | + | |
| 642 | + if (!b64_json) { | |
| 643 | + const buffer = await (await fetch(choice.url)).buffer(); | |
| 644 | + b64_json = buffer.toString('base64'); | |
| 645 | 645 | } |
| 646 | 646 | |
| 647 | 647 | return response.send({ format: 'jpg', data: b64_json }); |
| 648 | 648 | } catch (error) { |
| 649 | 649 | console.log(error); |
| 650 | 650 | return response.sendStatus(500); |