feat: расширенная анкета канала + промпт-инжиниринг для человечности

БД (новые таблицы):
- channel_style: тон/юмор/длина/структура/эмодзи/хэштеги/примеры постов/стоп-слова
- channel_schedule: расписание, рубрики, источники, auto_publish
- generation_jobs: добавлены user_id, tokens, cost, prompt_debug
- posts: связка с job, image_url, scheduling

Новый модуль services/promptBuilder.js:
- HUMANITY_RULES: правила живого текста (антипаттерны, личный голос, конкретика)
- buildPostSystemPrompt: собирает промпт из канала + few-shot примеров
- buildCritiquePrompt: self-critique для очистки от AI-следов

services/ai.js:
- generatePost теперь использует 2-step chain: генерация + critique
- temperature настроен (0.9 для разнообразия)
- возвращает usage/токены

services/channels.js: новый сервис, работа с тремя таблицами транзакционно
routes/channels.js: CRUD под расширенную модель
routes/generate.js: связка с channelId, передача в worker

Результат на тестах: пост следует стилю few-shot примеров, без AI-маркеров
This commit is contained in:
Alexey Pavlov
2026-05-30 22:01:38 +03:00
parent 36c02a9a0a
commit 5599de59ce
7 changed files with 733 additions and 151 deletions
+12 -7
View File
@@ -1,23 +1,28 @@
const express = require('express');
const router = express.Router();
const { query } = require('../config/db');
const channelsSvc = require('../services/channels');
const generationQueue = require('../workers/generation');
// POST /api/generate - create generation job
// POST /api/generate — создать задачу генерации
router.post('/', async (req, res) => {
try {
const { type, topic, tone = 'neutral', language = 'ru', channelContext = '', keywords = [], channelId } = req.body;
const { type, topic, channelId, rubric, keywords = [], useCritique = true } = req.body;
const userId = req.headers['x-user-id'] || null;
if (!type || !topic) return res.status(400).json({ error: 'type and topic are required' });
if (!type) return res.status(400).json({ error: 'type is required' });
if (!['post', 'article', 'topics'].includes(type)) return res.status(400).json({ error: 'Invalid type' });
if (type !== 'topics' && !topic) return res.status(400).json({ error: 'topic is required' });
if (type === 'post' && !channelId) return res.status(400).json({ error: 'channelId is required for posts' });
const { rows } = await query(
`INSERT INTO generation_jobs (type, channel_id, topic, status) VALUES ($1,$2,$3,'pending') RETURNING id`,
[type, channelId || null, topic]
`INSERT INTO generation_jobs (user_id, channel_id, type, topic, rubric, status)
VALUES ($1,$2,$3,$4,$5,'pending') RETURNING id`,
[userId, channelId || null, type, topic || null, rubric || null]
);
const jobId = rows[0].id;
await generationQueue.add({ jobId, type, topic, tone, language, channelContext, keywords });
await generationQueue.add({ jobId, type, topic, channelId, rubric, keywords, useCritique });
res.json({ jobId, status: 'pending' });
} catch (err) {
@@ -26,7 +31,7 @@ router.post('/', async (req, res) => {
}
});
// GET /api/generate/:id - get job status
// GET /api/generate/:id — статус и результат
router.get('/:id', async (req, res) => {
try {
const { rows } = await query(`SELECT * FROM generation_jobs WHERE id=$1`, [req.params.id]);