add initiatives folder
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import { llm_gen } from './llm'
|
||||
import { detectImage } from 'gigachat';
|
||||
|
||||
export const generatePicture = async (prompt: string, GIGA_AUTH) => {
|
||||
const resp = await llm_gen(GIGA_AUTH).chat({
|
||||
messages: [
|
||||
{
|
||||
"role": "system",
|
||||
"content": "Ты — Василий Кандинский для жильцов многоквартирного дома"
|
||||
},
|
||||
{
|
||||
role: "user",
|
||||
content: `Старайся передать атмосферу уюта и безопасности.
|
||||
Нарисуй картинку подходящую для такого события: ${prompt}
|
||||
В картинке не должно быть текста, только изображение.`,
|
||||
},
|
||||
],
|
||||
function_call: 'auto',
|
||||
});
|
||||
|
||||
// Получение изображения по идентификатору
|
||||
const detectedImage = detectImage(resp.choices[0]?.message.content ?? '');
|
||||
|
||||
if (!detectedImage?.uuid) {
|
||||
throw new Error('Не удалось получить UUID изображения из ответа GigaChat');
|
||||
}
|
||||
|
||||
const image = await llm_gen(GIGA_AUTH).getImage(detectedImage.uuid);
|
||||
|
||||
// Возвращаем содержимое изображения, убеждаясь что это 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