Merge branch 'staging' into world_info_force_activate_expansion

This commit is contained in:
Cohee
2024-10-11 21:52:55 +03:00
5 changed files with 16 additions and 17 deletions

View File

@ -2208,10 +2208,9 @@ function processReply(str) {
str = str.replaceAll('"', ''); str = str.replaceAll('"', '');
str = str.replaceAll('“', ''); str = str.replaceAll('“', '');
str = str.replaceAll('.', ',');
str = str.replaceAll('\n', ', '); str = str.replaceAll('\n', ', ');
str = str.normalize('NFD'); 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.replace(/\s+/g, ' '); // Collapse multiple whitespaces into one
str = str.trim(); str = str.trim();
@ -2675,8 +2674,7 @@ async function generateTogetherAIImage(prompt, negativePrompt, signal) {
}); });
if (result.ok) { if (result.ok) {
const data = await result.json(); return await result.json();
return { format: 'jpg', data: data?.output?.choices?.[0]?.image_base64 };
} else { } else {
const text = await result.text(); const text = await result.text();
throw new Error(text); throw new Error(text);

View File

@ -514,7 +514,8 @@ export function parseBooleanOperands(args) {
return ''; return '';
} }
const operandNumber = Number(operand); // parseFloat will return NaN for spaces.
const operandNumber = parseFloat(operand);
if (!isNaN(operandNumber)) { if (!isNaN(operandNumber)) {
return operandNumber; return operandNumber;

View File

@ -1686,8 +1686,8 @@ export function sortWorldInfoEntries(data, { customSort = null } = {}) {
} else if (sortRule === 'priority') { } else if (sortRule === 'priority') {
// First constant, then normal, then disabled. // First constant, then normal, then disabled.
primarySort = (a, b) => { primarySort = (a, b) => {
const aValue = a.constant ? 0 : a.disable ? 2 : 1; const aValue = a.disable ? 2 : a.constant ? 0 : 1;
const bValue = b.constant ? 0 : b.disable ? 2 : 1; const bValue = b.disable ? 2 : b.constant ? 0 : 1;
return aValue - bValue; return aValue - bValue;
}; };
} else { } else {

View File

@ -337,7 +337,7 @@ async function sendMakerSuiteRequest(request, response) {
? (stream ? 'streamGenerateContent' : 'generateContent') ? (stream ? 'streamGenerateContent' : 'generateContent')
: (isText ? 'generateText' : 'generateMessage'); : (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), body: JSON.stringify(body),
method: 'POST', method: 'POST',
headers: { headers: {

View File

@ -607,10 +607,9 @@ together.post('/generate', jsonParser, async (request, response) => {
console.log('TogetherAI request:', request.body); 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', method: 'POST',
body: JSON.stringify({ body: JSON.stringify({
request_type: 'image-model-inference',
prompt: request.body.prompt, prompt: request.body.prompt,
negative_prompt: request.body.negative_prompt, negative_prompt: request.body.negative_prompt,
height: request.body.height, height: request.body.height,
@ -620,8 +619,6 @@ together.post('/generate', jsonParser, async (request, response) => {
n: 1, n: 1,
// Limited to 10000 on playground, works fine with more. // Limited to 10000 on playground, works fine with more.
seed: request.body.seed >= 0 ? request.body.seed : Math.floor(Math.random() * 10_000_000), 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: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
@ -630,19 +627,22 @@ together.post('/generate', jsonParser, async (request, response) => {
}); });
if (!result.ok) { if (!result.ok) {
console.log('TogetherAI returned an error.'); console.log('TogetherAI returned an error.', { body: await result.text() });
return response.sendStatus(500); return response.sendStatus(500);
} }
const data = await result.json(); const data = await result.json();
console.log('TogetherAI response:', data); console.log('TogetherAI response:', data);
if (data.status !== 'finished') { const choice = data?.data?.[0];
console.log('TogetherAI job failed.'); let b64_json = choice.b64_json;
return response.sendStatus(500);
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) { } catch (error) {
console.log(error); console.log(error);
return response.sendStatus(500); return response.sendStatus(500);