add ai_initiatives

This commit is contained in:
Дания
2025-06-12 19:39:57 +03:00
parent 8ade320440
commit 09174abaa4
3 changed files with 167 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
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;
}