change file type and fix agents
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user