fix(blog-topics): ai.chat returns object not string — extract .text before .replace
После обновления ai.js модуль возвращает { text, usage } вместо строки.
result.replace() падало с 'not a function'. Теперь берём .text если объект.
This commit is contained in:
+4
-2
@@ -628,12 +628,14 @@ router.post('/blog-topics/generate', async (req, res) => {
|
||||
|
||||
const userMsg = `Придумай ${count} уникальных тем.${existingTopics ? `\n\nИзбегай повторений:\n${existingTopics.slice(0,800)}` : ''}`;
|
||||
|
||||
const result = await ai.chat(
|
||||
const aiResult = await ai.chat(
|
||||
config.ai.models.topics || 'claude-haiku-4-5-20251001',
|
||||
system, userMsg, 0.9, 600
|
||||
);
|
||||
// ai.chat возвращает { text, usage } или строку (backward compat)
|
||||
const rawText = typeof aiResult === 'string' ? aiResult : aiResult.text;
|
||||
|
||||
const topics = JSON.parse(result.replace(/```json|```/g, '').trim());
|
||||
const topics = JSON.parse(rawText.replace(/```json|```/g, '').trim());
|
||||
let added = 0;
|
||||
for (const topic of topics.slice(0, count)) {
|
||||
if (!topic?.trim()) continue;
|
||||
|
||||
Reference in New Issue
Block a user