[chore] Fix type errors
This commit is contained in:
parent
72138c632d
commit
4fcad0752f
|
@ -71,7 +71,6 @@
|
|||
"@types/lodash": "^4.17.10",
|
||||
"@types/mime-types": "^2.1.4",
|
||||
"@types/multer": "^1.4.12",
|
||||
"@types/node-fetch": "^2.6.11",
|
||||
"@types/node-persist": "^3.1.8",
|
||||
"@types/png-chunk-text": "^1.0.3",
|
||||
"@types/png-chunks-encode": "^1.0.2",
|
||||
|
|
|
@ -97,7 +97,6 @@
|
|||
"@types/lodash": "^4.17.10",
|
||||
"@types/mime-types": "^2.1.4",
|
||||
"@types/multer": "^1.4.12",
|
||||
"@types/node-fetch": "^2.6.11",
|
||||
"@types/node-persist": "^3.1.8",
|
||||
"@types/png-chunk-text": "^1.0.3",
|
||||
"@types/png-chunks-encode": "^1.0.2",
|
||||
|
|
|
@ -13,7 +13,7 @@ import PNGtext from 'png-chunk-text';
|
|||
* @returns {Buffer} PNG image buffer with metadata
|
||||
*/
|
||||
export const write = (image, data) => {
|
||||
const chunks = extract(image);
|
||||
const chunks = extract(new Uint8Array(image));
|
||||
const tEXtChunks = chunks.filter(chunk => chunk.name === 'tEXt');
|
||||
|
||||
// Remove existing tEXt chunks
|
||||
|
@ -52,7 +52,7 @@ export const write = (image, data) => {
|
|||
* @returns {string} Character data
|
||||
*/
|
||||
export const read = (image) => {
|
||||
const chunks = extract(image);
|
||||
const chunks = extract(new Uint8Array(image));
|
||||
|
||||
const textChunks = chunks.filter((chunk) => chunk.name === 'tEXt').map((chunk) => PNGtext.decode(chunk.data));
|
||||
|
||||
|
|
|
@ -42,7 +42,6 @@ router.post('/caption-image', jsonParser, async (request, response) => {
|
|||
'anthropic-version': '2023-06-01',
|
||||
'x-api-key': request.body.reverse_proxy ? request.body.proxy_password : readSecret(request.user.directories, SECRET_KEYS.CLAUDE),
|
||||
},
|
||||
timeout: 0,
|
||||
});
|
||||
|
||||
if (!result.ok) {
|
||||
|
@ -51,6 +50,7 @@ router.post('/caption-image', jsonParser, async (request, response) => {
|
|||
return response.status(result.status).send({ error: true });
|
||||
}
|
||||
|
||||
/** @type {any} */
|
||||
const generateResponseJson = await result.json();
|
||||
const caption = generateResponseJson.content[0].text;
|
||||
console.log('Claude response:', generateResponseJson);
|
||||
|
|
|
@ -152,7 +152,6 @@ async function sendClaudeRequest(request, response) {
|
|||
'x-api-key': apiKey,
|
||||
...additionalHeaders,
|
||||
},
|
||||
timeout: 0,
|
||||
});
|
||||
|
||||
if (request.body.stream) {
|
||||
|
@ -165,6 +164,7 @@ async function sendClaudeRequest(request, response) {
|
|||
return response.status(generateResponse.status).send({ error: true });
|
||||
}
|
||||
|
||||
/** @type {any} */
|
||||
const generateResponseJson = await generateResponse.json();
|
||||
const responseText = generateResponseJson?.content?.[0]?.text || '';
|
||||
console.log('Claude response:', generateResponseJson);
|
||||
|
@ -212,7 +212,6 @@ async function sendScaleRequest(request, response) {
|
|||
'Content-Type': 'application/json',
|
||||
'Authorization': `Basic ${apiKey}`,
|
||||
},
|
||||
timeout: 0,
|
||||
});
|
||||
|
||||
if (!generateResponse.ok) {
|
||||
|
@ -220,6 +219,7 @@ async function sendScaleRequest(request, response) {
|
|||
return response.status(500).send({ error: true });
|
||||
}
|
||||
|
||||
/** @type {any} */
|
||||
const generateResponseJson = await generateResponse.json();
|
||||
console.log('Scale response:', generateResponseJson);
|
||||
|
||||
|
@ -335,7 +335,6 @@ async function sendMakerSuiteRequest(request, response) {
|
|||
'Content-Type': 'application/json',
|
||||
},
|
||||
signal: controller.signal,
|
||||
timeout: 0,
|
||||
});
|
||||
// have to do this because of their busted ass streaming endpoint
|
||||
if (stream) {
|
||||
|
@ -354,6 +353,7 @@ async function sendMakerSuiteRequest(request, response) {
|
|||
return response.status(generateResponse.status).send({ error: true });
|
||||
}
|
||||
|
||||
/** @type {any} */
|
||||
const generateResponseJson = await generateResponse.json();
|
||||
|
||||
const candidates = generateResponseJson?.candidates;
|
||||
|
@ -676,6 +676,7 @@ router.post('/status', jsonParser, async function (request, response_getstatus_o
|
|||
});
|
||||
|
||||
if (response.ok) {
|
||||
/** @type {any} */
|
||||
const data = await response.json();
|
||||
response_getstatus_openai.send(data);
|
||||
|
||||
|
@ -979,7 +980,6 @@ router.post('/generate', jsonParser, function (request, response) {
|
|||
},
|
||||
body: JSON.stringify(requestBody),
|
||||
signal: controller.signal,
|
||||
timeout: 0,
|
||||
};
|
||||
|
||||
console.log(requestBody);
|
||||
|
@ -1005,6 +1005,7 @@ router.post('/generate', jsonParser, function (request, response) {
|
|||
}
|
||||
|
||||
if (fetchResponse.ok) {
|
||||
/** @type {any} */
|
||||
let json = await fetchResponse.json();
|
||||
response.send(json);
|
||||
console.log(json);
|
||||
|
|
|
@ -96,7 +96,7 @@ router.post('/generate', jsonParser, async function (request, response_generate)
|
|||
for (let i = 0; i < MAX_RETRIES; i++) {
|
||||
try {
|
||||
const url = request.body.streaming ? `${request.body.api_server}/extra/generate/stream` : `${request.body.api_server}/v1/generate`;
|
||||
const response = await fetch(url, { method: 'POST', timeout: 0, ...args });
|
||||
const response = await fetch(url, { method: 'POST', ...args });
|
||||
|
||||
if (request.body.streaming) {
|
||||
// Pipe remote SSE stream to Express response
|
||||
|
@ -156,6 +156,7 @@ router.post('/status', jsonParser, async function (request, response) {
|
|||
|
||||
const result = {};
|
||||
|
||||
/** @type {any} */
|
||||
const [koboldUnitedResponse, koboldExtraResponse, koboldModelResponse] = await Promise.all([
|
||||
// We catch errors both from the response not having a successful HTTP status and from JSON parsing failing
|
||||
|
||||
|
|
|
@ -70,7 +70,6 @@ router.post('/generate', jsonParser, async function (request, response) {
|
|||
'Content-Type': 'application/json',
|
||||
'cookie': `_jwt=${cookie}`,
|
||||
},
|
||||
timeout: 0,
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
|
||||
|
@ -80,6 +79,7 @@ router.post('/generate', jsonParser, async function (request, response) {
|
|||
return response.status(500).send({ error: { message: result.statusText } });
|
||||
}
|
||||
|
||||
/** @type {any} */
|
||||
const data = await result.json();
|
||||
const output = data?.result?.data?.json?.outputs?.[0] || '';
|
||||
|
||||
|
|
|
@ -28,6 +28,10 @@ export const router = express.Router();
|
|||
*/
|
||||
async function parseOllamaStream(jsonStream, request, response) {
|
||||
try {
|
||||
if (!jsonStream.body) {
|
||||
throw new Error('No body in the response');
|
||||
}
|
||||
|
||||
let partialData = '';
|
||||
jsonStream.body.on('data', (data) => {
|
||||
const chunk = data.toString();
|
||||
|
@ -153,6 +157,7 @@ router.post('/status', jsonParser, async function (request, response) {
|
|||
return response.status(400);
|
||||
}
|
||||
|
||||
/** @type {any} */
|
||||
let data = await modelsReply.json();
|
||||
|
||||
if (request.body.legacy_api) {
|
||||
|
@ -190,6 +195,7 @@ router.post('/status', jsonParser, async function (request, response) {
|
|||
const modelInfoReply = await fetch(modelInfoUrl, args);
|
||||
|
||||
if (modelInfoReply.ok) {
|
||||
/** @type {any} */
|
||||
const modelInfo = await modelInfoReply.json();
|
||||
console.log('Ooba model info:', modelInfo);
|
||||
|
||||
|
@ -206,6 +212,7 @@ router.post('/status', jsonParser, async function (request, response) {
|
|||
const modelInfoReply = await fetch(modelInfoUrl, args);
|
||||
|
||||
if (modelInfoReply.ok) {
|
||||
/** @type {any} */
|
||||
const modelInfo = await modelInfoReply.json();
|
||||
console.log('Tabby model info:', modelInfo);
|
||||
|
||||
|
@ -359,6 +366,7 @@ router.post('/generate', jsonParser, async function (request, response) {
|
|||
const completionsReply = await fetch(url, args);
|
||||
|
||||
if (completionsReply.ok) {
|
||||
/** @type {any} */
|
||||
const data = await completionsReply.json();
|
||||
console.log('Endpoint response:', data);
|
||||
|
||||
|
@ -415,7 +423,6 @@ ollama.post('/download', jsonParser, async function (request, response) {
|
|||
name: name,
|
||||
stream: false,
|
||||
}),
|
||||
timeout: 0,
|
||||
});
|
||||
|
||||
if (!fetchResponse.ok) {
|
||||
|
@ -448,7 +455,6 @@ ollama.post('/caption-image', jsonParser, async function (request, response) {
|
|||
images: [request.body.image],
|
||||
stream: false,
|
||||
}),
|
||||
timeout: 0,
|
||||
});
|
||||
|
||||
if (!fetchResponse.ok) {
|
||||
|
@ -456,6 +462,7 @@ ollama.post('/caption-image', jsonParser, async function (request, response) {
|
|||
return response.status(500).send({ error: true });
|
||||
}
|
||||
|
||||
/** @type {any} */
|
||||
const data = await fetchResponse.json();
|
||||
console.log('Ollama caption response:', data);
|
||||
|
||||
|
@ -487,7 +494,6 @@ llamacpp.post('/caption-image', jsonParser, async function (request, response) {
|
|||
const fetchResponse = await fetch(`${baseUrl}/completion`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
timeout: 0,
|
||||
body: JSON.stringify({
|
||||
prompt: `USER:[img-1]${String(request.body.prompt).trim()}\nASSISTANT:`,
|
||||
image_data: [{ data: request.body.image, id: 1 }],
|
||||
|
@ -502,6 +508,7 @@ llamacpp.post('/caption-image', jsonParser, async function (request, response) {
|
|||
return response.status(500).send({ error: true });
|
||||
}
|
||||
|
||||
/** @type {any} */
|
||||
const data = await fetchResponse.json();
|
||||
console.log('LlamaCpp caption response:', data);
|
||||
|
||||
|
@ -531,7 +538,6 @@ llamacpp.post('/props', jsonParser, async function (request, response) {
|
|||
|
||||
const fetchResponse = await fetch(`${baseUrl}/props`, {
|
||||
method: 'GET',
|
||||
timeout: 0,
|
||||
});
|
||||
|
||||
if (!fetchResponse.ok) {
|
||||
|
@ -566,7 +572,6 @@ llamacpp.post('/slots', jsonParser, async function (request, response) {
|
|||
if (request.body.action === 'info') {
|
||||
fetchResponse = await fetch(`${baseUrl}/slots`, {
|
||||
method: 'GET',
|
||||
timeout: 0,
|
||||
});
|
||||
} else {
|
||||
if (!/^\d+$/.test(request.body.id_slot)) {
|
||||
|
@ -579,7 +584,6 @@ llamacpp.post('/slots', jsonParser, async function (request, response) {
|
|||
fetchResponse = await fetch(`${baseUrl}/slots/${request.body.id_slot}?action=${request.body.action}`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
timeout: 0,
|
||||
body: JSON.stringify({
|
||||
filename: request.body.action !== 'erase' ? `${request.body.filename}` : undefined,
|
||||
}),
|
||||
|
@ -623,6 +627,7 @@ tabby.post('/download', jsonParser, async function (request, response) {
|
|||
});
|
||||
|
||||
if (permissionResponse.ok) {
|
||||
/** @type {any} */
|
||||
const permissionJson = await permissionResponse.json();
|
||||
|
||||
if (permissionJson['permission'] !== 'admin') {
|
||||
|
|
|
@ -380,6 +380,7 @@ async function downloadPygmalionCharacter(id) {
|
|||
throw new Error('Failed to download character');
|
||||
}
|
||||
|
||||
/** @type {any} */
|
||||
const jsonData = await result.json();
|
||||
const characterData = jsonData?.character;
|
||||
|
||||
|
@ -472,6 +473,7 @@ async function downloadJannyCharacter(uuid) {
|
|||
});
|
||||
|
||||
if (result.ok) {
|
||||
/** @type {any} */
|
||||
const downloadResult = await result.json();
|
||||
if (downloadResult.status === 'ok') {
|
||||
const imageResult = await fetch(downloadResult.downloadUrl);
|
||||
|
|
|
@ -40,7 +40,6 @@ router.post('/caption-image', jsonParser, async (request, response) => {
|
|||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
timeout: 0,
|
||||
});
|
||||
|
||||
if (!result.ok) {
|
||||
|
@ -49,6 +48,7 @@ router.post('/caption-image', jsonParser, async (request, response) => {
|
|||
return response.status(result.status).send({ error: true });
|
||||
}
|
||||
|
||||
/** @type {any} */
|
||||
const data = await result.json();
|
||||
console.log('Multimodal captioning response', data);
|
||||
|
||||
|
|
|
@ -68,7 +68,7 @@ router.post('/upload', jsonParser, async (request, response) => {
|
|||
|
||||
ensureDirectoryExistence(pathToNewFile);
|
||||
const imageBuffer = Buffer.from(base64Data, 'base64');
|
||||
await fs.promises.writeFile(pathToNewFile, imageBuffer);
|
||||
await fs.promises.writeFile(pathToNewFile, new Uint8Array(imageBuffer));
|
||||
response.send({ path: clientRelativePath(request.user.directories.root, pathToNewFile) });
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
|
|
|
@ -252,7 +252,7 @@ router.post('/generate', jsonParser, async function (req, res) {
|
|||
try {
|
||||
const baseURL = (req.body.model.includes('kayra') || req.body.model.includes('erato')) ? TEXT_NOVELAI : API_NOVELAI;
|
||||
const url = req.body.streaming ? `${baseURL}/ai/generate-stream` : `${baseURL}/ai/generate`;
|
||||
const response = await fetch(url, { method: 'POST', timeout: 0, ...args });
|
||||
const response = await fetch(url, { method: 'POST', ...args });
|
||||
|
||||
if (req.body.streaming) {
|
||||
// Pipe remote SSE stream to Express response
|
||||
|
@ -274,6 +274,7 @@ router.post('/generate', jsonParser, async function (req, res) {
|
|||
return res.status(response.status).send({ error: { message } });
|
||||
}
|
||||
|
||||
/** @type {any} */
|
||||
const data = await response.json();
|
||||
console.log('NovelAI Output', data?.output);
|
||||
return res.send(data);
|
||||
|
@ -416,7 +417,6 @@ router.post('/generate-voice', jsonParser, async (request, response) => {
|
|||
'Authorization': `Bearer ${token}`,
|
||||
'Accept': 'audio/mpeg',
|
||||
},
|
||||
timeout: 0,
|
||||
});
|
||||
|
||||
if (!result.ok) {
|
||||
|
@ -426,7 +426,7 @@ router.post('/generate-voice', jsonParser, async (request, response) => {
|
|||
}
|
||||
|
||||
const chunks = await readAllChunks(result.body);
|
||||
const buffer = Buffer.concat(chunks);
|
||||
const buffer = Buffer.concat(chunks.map(chunk => new Uint8Array(chunk)));
|
||||
response.setHeader('Content-Type', 'audio/mpeg');
|
||||
return response.send(buffer);
|
||||
}
|
||||
|
|
|
@ -154,7 +154,6 @@ router.post('/caption-image', jsonParser, async (request, response) => {
|
|||
...headers,
|
||||
},
|
||||
body: JSON.stringify(body),
|
||||
timeout: 0,
|
||||
});
|
||||
|
||||
if (!result.ok) {
|
||||
|
@ -163,6 +162,7 @@ router.post('/caption-image', jsonParser, async (request, response) => {
|
|||
return response.status(500).send(text);
|
||||
}
|
||||
|
||||
/** @type {any} */
|
||||
const data = await result.json();
|
||||
console.log('Multimodal captioning response', data);
|
||||
const caption = data?.choices[0]?.message?.content;
|
||||
|
@ -284,7 +284,6 @@ router.post('/generate-image', jsonParser, async (request, response) => {
|
|||
Authorization: `Bearer ${key}`,
|
||||
},
|
||||
body: JSON.stringify(request.body),
|
||||
timeout: 0,
|
||||
});
|
||||
|
||||
if (!result.ok) {
|
||||
|
|
|
@ -65,6 +65,7 @@ router.post('/upscalers', jsonParser, async (request, response) => {
|
|||
throw new Error('SD WebUI returned an error.');
|
||||
}
|
||||
|
||||
/** @type {any} */
|
||||
const data = await result.json();
|
||||
const names = data.map(x => x.name);
|
||||
return names;
|
||||
|
@ -85,6 +86,7 @@ router.post('/upscalers', jsonParser, async (request, response) => {
|
|||
throw new Error('SD WebUI returned an error.');
|
||||
}
|
||||
|
||||
/** @type {any} */
|
||||
const data = await result.json();
|
||||
const names = data.map(x => x.name);
|
||||
return names;
|
||||
|
@ -118,6 +120,7 @@ router.post('/vaes', jsonParser, async (request, response) => {
|
|||
throw new Error('SD WebUI returned an error.');
|
||||
}
|
||||
|
||||
/** @type {any} */
|
||||
const data = await result.json();
|
||||
const names = data.map(x => x.model_name);
|
||||
return response.send(names);
|
||||
|
@ -143,6 +146,7 @@ router.post('/samplers', jsonParser, async (request, response) => {
|
|||
throw new Error('SD WebUI returned an error.');
|
||||
}
|
||||
|
||||
/** @type {any} */
|
||||
const data = await result.json();
|
||||
const names = data.map(x => x.name);
|
||||
return response.send(names);
|
||||
|
@ -169,6 +173,7 @@ router.post('/schedulers', jsonParser, async (request, response) => {
|
|||
throw new Error('SD WebUI returned an error.');
|
||||
}
|
||||
|
||||
/** @type {any} */
|
||||
const data = await result.json();
|
||||
const names = data.map(x => x.name);
|
||||
return response.send(names);
|
||||
|
@ -194,6 +199,7 @@ router.post('/models', jsonParser, async (request, response) => {
|
|||
throw new Error('SD WebUI returned an error.');
|
||||
}
|
||||
|
||||
/** @type {any} */
|
||||
const data = await result.json();
|
||||
const models = data.map(x => ({ value: x.title, text: x.title }));
|
||||
return response.send(models);
|
||||
|
@ -214,6 +220,7 @@ router.post('/get-model', jsonParser, async (request, response) => {
|
|||
'Authorization': getBasicAuthHeader(request.body.auth),
|
||||
},
|
||||
});
|
||||
/** @type {any} */
|
||||
const data = await result.json();
|
||||
return response.send(data['sd_model_checkpoint']);
|
||||
} catch (error) {
|
||||
|
@ -233,7 +240,6 @@ router.post('/set-model', jsonParser, async (request, response) => {
|
|||
headers: {
|
||||
'Authorization': getBasicAuthHeader(request.body.auth),
|
||||
},
|
||||
timeout: 0,
|
||||
});
|
||||
const data = await result.json();
|
||||
return data;
|
||||
|
@ -253,7 +259,6 @@ router.post('/set-model', jsonParser, async (request, response) => {
|
|||
'Content-Type': 'application/json',
|
||||
'Authorization': getBasicAuthHeader(request.body.auth),
|
||||
},
|
||||
timeout: 0,
|
||||
});
|
||||
|
||||
if (!result.ok) {
|
||||
|
@ -264,6 +269,7 @@ router.post('/set-model', jsonParser, async (request, response) => {
|
|||
const CHECK_INTERVAL = 2000;
|
||||
|
||||
for (let attempt = 0; attempt < MAX_ATTEMPTS; attempt++) {
|
||||
/** @type {any} */
|
||||
const progressState = await getProgress();
|
||||
|
||||
const progress = progressState['progress'];
|
||||
|
@ -308,8 +314,6 @@ router.post('/generate', jsonParser, async (request, response) => {
|
|||
'Content-Type': 'application/json',
|
||||
'Authorization': getBasicAuthHeader(request.body.auth),
|
||||
},
|
||||
timeout: 0,
|
||||
// @ts-ignore
|
||||
signal: controller.signal,
|
||||
});
|
||||
|
||||
|
@ -345,6 +349,7 @@ router.post('/sd-next/upscalers', jsonParser, async (request, response) => {
|
|||
// Vlad doesn't provide Latent Upscalers in the API, so we have to hardcode them here
|
||||
const latentUpscalers = ['Latent', 'Latent (antialiased)', 'Latent (bicubic)', 'Latent (bicubic antialiased)', 'Latent (nearest)', 'Latent (nearest-exact)'];
|
||||
|
||||
/** @type {any} */
|
||||
const data = await result.json();
|
||||
const names = data.map(x => x.name);
|
||||
|
||||
|
@ -387,6 +392,7 @@ comfy.post('/samplers', jsonParser, async (request, response) => {
|
|||
throw new Error('ComfyUI returned an error.');
|
||||
}
|
||||
|
||||
/** @type {any} */
|
||||
const data = await result.json();
|
||||
return response.send(data.KSampler.input.required.sampler_name[0]);
|
||||
} catch (error) {
|
||||
|
@ -404,6 +410,7 @@ comfy.post('/models', jsonParser, async (request, response) => {
|
|||
if (!result.ok) {
|
||||
throw new Error('ComfyUI returned an error.');
|
||||
}
|
||||
/** @type {any} */
|
||||
const data = await result.json();
|
||||
return response.send(data.CheckpointLoaderSimple.input.required.ckpt_name[0].map(it => ({ value: it, text: it })));
|
||||
} catch (error) {
|
||||
|
@ -422,6 +429,7 @@ comfy.post('/schedulers', jsonParser, async (request, response) => {
|
|||
throw new Error('ComfyUI returned an error.');
|
||||
}
|
||||
|
||||
/** @type {any} */
|
||||
const data = await result.json();
|
||||
return response.send(data.KSampler.input.required.scheduler[0]);
|
||||
} catch (error) {
|
||||
|
@ -440,6 +448,7 @@ comfy.post('/vaes', jsonParser, async (request, response) => {
|
|||
throw new Error('ComfyUI returned an error.');
|
||||
}
|
||||
|
||||
/** @type {any} */
|
||||
const data = await result.json();
|
||||
return response.send(data.VAELoader.input.required.vae_name[0]);
|
||||
} catch (error) {
|
||||
|
@ -521,6 +530,7 @@ comfy.post('/generate', jsonParser, async (request, response) => {
|
|||
throw new Error('ComfyUI returned an error.');
|
||||
}
|
||||
|
||||
/** @type {any} */
|
||||
const data = await promptResult.json();
|
||||
const id = data.prompt_id;
|
||||
let item;
|
||||
|
@ -531,6 +541,7 @@ comfy.post('/generate', jsonParser, async (request, response) => {
|
|||
if (!result.ok) {
|
||||
throw new Error('ComfyUI returned an error.');
|
||||
}
|
||||
/** @type {any} */
|
||||
const history = await result.json();
|
||||
item = history[id];
|
||||
if (item) {
|
||||
|
@ -633,6 +644,7 @@ together.post('/generate', jsonParser, async (request, response) => {
|
|||
return response.sendStatus(500);
|
||||
}
|
||||
|
||||
/** @type {any} */
|
||||
const data = await result.json();
|
||||
console.log('TogetherAI response:', data);
|
||||
|
||||
|
@ -681,6 +693,8 @@ drawthings.post('/get-model', jsonParser, async (request, response) => {
|
|||
const result = await fetch(url, {
|
||||
method: 'GET',
|
||||
});
|
||||
|
||||
/** @type {any} */
|
||||
const data = await result.json();
|
||||
|
||||
return response.send(data['model']);
|
||||
|
@ -698,6 +712,8 @@ drawthings.post('/get-upscaler', jsonParser, async (request, response) => {
|
|||
const result = await fetch(url, {
|
||||
method: 'GET',
|
||||
});
|
||||
|
||||
/** @type {any} */
|
||||
const data = await result.json();
|
||||
|
||||
return response.send(data['upscaler']);
|
||||
|
@ -726,7 +742,6 @@ drawthings.post('/generate', jsonParser, async (request, response) => {
|
|||
'Content-Type': 'application/json',
|
||||
'Authorization': auth,
|
||||
},
|
||||
timeout: 0,
|
||||
});
|
||||
|
||||
if (!result.ok) {
|
||||
|
@ -848,7 +863,6 @@ stability.post('/generate', jsonParser, async (request, response) => {
|
|||
'Accept': 'image/*',
|
||||
},
|
||||
body: formData,
|
||||
timeout: 0,
|
||||
});
|
||||
|
||||
if (!result.ok) {
|
||||
|
|
|
@ -78,6 +78,7 @@ router.post('/libre', jsonParser, async (request, response) => {
|
|||
return response.sendStatus(result.status);
|
||||
}
|
||||
|
||||
/** @type {any} */
|
||||
const json = await result.json();
|
||||
console.log('Translated text: ' + json.translatedText);
|
||||
|
||||
|
@ -158,7 +159,6 @@ router.post('/yandex', jsonParser, async (request, response) => {
|
|||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
timeout: 0,
|
||||
});
|
||||
|
||||
if (!result.ok) {
|
||||
|
@ -167,6 +167,7 @@ router.post('/yandex', jsonParser, async (request, response) => {
|
|||
return response.sendStatus(500);
|
||||
}
|
||||
|
||||
/** @type {any} */
|
||||
const json = await result.json();
|
||||
const translated = json.text.join();
|
||||
console.log('Translated text: ' + translated);
|
||||
|
@ -264,7 +265,6 @@ router.post('/deepl', jsonParser, async (request, response) => {
|
|||
'Authorization': `DeepL-Auth-Key ${key}`,
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
timeout: 0,
|
||||
});
|
||||
|
||||
if (!result.ok) {
|
||||
|
@ -273,6 +273,7 @@ router.post('/deepl', jsonParser, async (request, response) => {
|
|||
return response.sendStatus(result.status);
|
||||
}
|
||||
|
||||
/** @type {any} */
|
||||
const json = await result.json();
|
||||
console.log('Translated text: ' + json.translations[0].text);
|
||||
|
||||
|
@ -317,7 +318,6 @@ router.post('/onering', jsonParser, async (request, response) => {
|
|||
|
||||
const result = await fetch(fetchUrl, {
|
||||
method: 'GET',
|
||||
timeout: 0,
|
||||
});
|
||||
|
||||
if (!result.ok) {
|
||||
|
@ -326,6 +326,7 @@ router.post('/onering', jsonParser, async (request, response) => {
|
|||
return response.sendStatus(result.status);
|
||||
}
|
||||
|
||||
/** @type {any} */
|
||||
const data = await result.json();
|
||||
console.log('Translated text: ' + data.result);
|
||||
|
||||
|
@ -373,7 +374,6 @@ router.post('/deeplx', jsonParser, async (request, response) => {
|
|||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
timeout: 0,
|
||||
});
|
||||
|
||||
if (!result.ok) {
|
||||
|
@ -382,6 +382,7 @@ router.post('/deeplx', jsonParser, async (request, response) => {
|
|||
return response.sendStatus(result.status);
|
||||
}
|
||||
|
||||
/** @type {any} */
|
||||
const json = await result.json();
|
||||
console.log('Translated text: ' + json.data);
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ import fs from 'node:fs';
|
|||
import process from 'node:process';
|
||||
import { Buffer } from 'node:buffer';
|
||||
|
||||
import { pipeline, env, RawImage, Pipeline } from 'sillytavern-transformers';
|
||||
import { pipeline, env, RawImage } from 'sillytavern-transformers';
|
||||
import { getConfigValue } from './util.js';
|
||||
|
||||
configureTransformers();
|
||||
|
@ -117,7 +117,7 @@ async function migrateCacheToDataDir() {
|
|||
* Gets the transformers.js pipeline for a given task.
|
||||
* @param {import('sillytavern-transformers').PipelineType} task The task to get the pipeline for
|
||||
* @param {string} forceModel The model to use for the pipeline, if any
|
||||
* @returns {Promise<Pipeline>} Pipeline for the task
|
||||
* @returns {Promise<import('sillytavern-transformers').Pipeline>} The transformers.js pipeline
|
||||
*/
|
||||
export async function getPipeline(task, forceModel = '') {
|
||||
await migrateCacheToDataDir();
|
||||
|
@ -137,6 +137,7 @@ export async function getPipeline(task, forceModel = '') {
|
|||
const instance = await pipeline(task, model, { cache_dir: cacheDir, quantized: tasks[task].quantized ?? true, local_files_only: localOnly });
|
||||
tasks[task].pipeline = instance;
|
||||
tasks[task].currentModel = model;
|
||||
// @ts-ignore
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
|
20
src/util.js
20
src/util.js
|
@ -441,17 +441,21 @@ export function forwardFetchResponse(from, to) {
|
|||
to.statusCode = statusCode;
|
||||
to.statusMessage = statusText;
|
||||
|
||||
from.body.pipe(to);
|
||||
if (from.body && to.socket) {
|
||||
from.body.pipe(to);
|
||||
|
||||
to.socket.on('close', function () {
|
||||
if (from.body instanceof Readable) from.body.destroy(); // Close the remote stream
|
||||
to.end(); // End the Express response
|
||||
});
|
||||
to.socket.on('close', function () {
|
||||
if (from.body instanceof Readable) from.body.destroy(); // Close the remote stream
|
||||
to.end(); // End the Express response
|
||||
});
|
||||
|
||||
from.body.on('end', function () {
|
||||
console.log('Streaming request finished');
|
||||
from.body.on('end', function () {
|
||||
console.log('Streaming request finished');
|
||||
to.end();
|
||||
});
|
||||
} else {
|
||||
to.end();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -38,6 +38,7 @@ export async function getCohereBatchVector(texts, isQuery, directories, model) {
|
|||
throw new Error('API request failed');
|
||||
}
|
||||
|
||||
/** @type {any} */
|
||||
const data = await response.json();
|
||||
if (!Array.isArray(data?.embeddings?.float)) {
|
||||
console.log('API response was not an array');
|
||||
|
|
|
@ -66,6 +66,7 @@ async function getExtrasVectorImpl(text, apiUrl, apiKey) {
|
|||
throw new Error('Extras request failed');
|
||||
}
|
||||
|
||||
/** @type {any} */
|
||||
const data = await response.json();
|
||||
const vector = data.embedding; // `embedding`: number[] (one text item), or number[][] (multiple text items).
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ export async function getLlamaCppBatchVector(texts, apiUrl, directories) {
|
|||
throw new Error(`LlamaCpp: Failed to get vector for text: ${response.statusText} ${responseText}`);
|
||||
}
|
||||
|
||||
/** @type {any} */
|
||||
const data = await response.json();
|
||||
|
||||
if (!Array.isArray(data?.data)) {
|
||||
|
|
|
@ -52,6 +52,7 @@ export async function getMakerSuiteVector(text, directories) {
|
|||
throw new Error('Google AI Studio request failed');
|
||||
}
|
||||
|
||||
/** @type {any} */
|
||||
const data = await response.json();
|
||||
// noinspection JSValidateTypes
|
||||
return data['embedding']['values'];
|
||||
|
|
|
@ -51,6 +51,7 @@ export async function getNomicAIBatchVector(texts, source, directories) {
|
|||
throw new Error('API request failed');
|
||||
}
|
||||
|
||||
/** @type {any} */
|
||||
const data = await response.json();
|
||||
if (!Array.isArray(data?.embeddings)) {
|
||||
console.log('API response was not an array');
|
||||
|
|
|
@ -54,6 +54,7 @@ export async function getOllamaVector(text, apiUrl, model, keep, directories) {
|
|||
throw new Error(`Ollama: Failed to get vector for text: ${response.statusText} ${responseText}`);
|
||||
}
|
||||
|
||||
/** @type {any} */
|
||||
const data = await response.json();
|
||||
|
||||
if (!Array.isArray(data?.embedding)) {
|
||||
|
|
|
@ -61,6 +61,7 @@ export async function getOpenAIBatchVector(texts, source, directories, model = '
|
|||
throw new Error('API request failed');
|
||||
}
|
||||
|
||||
/** @type {any} */
|
||||
const data = await response.json();
|
||||
|
||||
if (!Array.isArray(data?.data)) {
|
||||
|
|
|
@ -31,6 +31,7 @@ export async function getVllmBatchVector(texts, apiUrl, model, directories) {
|
|||
throw new Error(`VLLM: Failed to get vector for text: ${response.statusText} ${responseText}`);
|
||||
}
|
||||
|
||||
/** @type {any} */
|
||||
const data = await response.json();
|
||||
|
||||
if (!Array.isArray(data?.data)) {
|
||||
|
|
Loading…
Reference in New Issue