change file type and fix agents

This commit is contained in:
Дания
2025-06-14 02:01:19 +03:00
parent 39a62818e9
commit a7be793608
7 changed files with 157 additions and 181 deletions

View File

@@ -3,6 +3,7 @@ import { Agent } from 'node:https';
const httpsAgent = new Agent({
rejectUnauthorized: false,
timeout: 60000
});
export const llm = new GigaChat({
@@ -30,8 +31,19 @@ export const generatePicture = async (prompt: string) => {
// Получение изображения по идентификатору
const detectedImage = detectImage(resp.choices[0]?.message.content ?? '');
const image = await llm.getImage(detectedImage?.uuid ?? '');
if (!detectedImage?.uuid) {
throw new Error('Не удалось получить UUID изображения из ответа GigaChat');
}
const image = await llm.getImage(detectedImage.uuid);
// Возвращаем содержимое изображения
return image.content;
// Возвращаем содержимое изображения, убеждаясь что это Buffer
if (Buffer.isBuffer(image.content)) {
return image.content;
} else if (typeof image.content === 'string') {
return Buffer.from(image.content, 'binary');
} else {
throw new Error('Unexpected image content type: ' + typeof image.content);
}
}