Files
multy-stub/server/routers/kfu-m-24-1/sber_mobile/initiatives-ai-agents/picture.ts
2025-06-12 19:39:57 +03:00

38 lines
1.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { GigaChat, detectImage } from 'gigachat';
import { Agent } from 'node:https';
const httpsAgent = new Agent({
rejectUnauthorized: false,
});
export const llm = new GigaChat({
credentials: process.env.GIGA_AUTH,
model: 'GigaChat-2',
httpsAgent,
});
export const generatePicture = async (prompt: string) => {
const resp = await llm.chat({
messages: [
{
"role": "system",
"content": "Ты — Василий Кандинский для жильцов многоквартирного дома"
},
{
role: "user",
content: `Старайся передать атмосферу уюта и безопасности.
Нарисуй картинку подходящую для такого события: ${prompt}
В картинке не должно быть текста, только изображение.`,
},
],
function_call: 'auto',
});
// Получение изображения по идентификатору
const detectedImage = detectImage(resp.choices[0]?.message.content ?? '');
const image = await llm.getImage(detectedImage?.uuid ?? '');
// Возвращаем содержимое изображения
return image.content;
}