change moderate and initiatives
This commit is contained in:
@@ -1,32 +1,23 @@
|
||||
import { Agent } from 'node:https';
|
||||
import { GigaChat } from "langchain-gigachat";
|
||||
import { llm_mod } from './llm'
|
||||
import { z } from "zod";
|
||||
|
||||
const httpsAgent = new Agent({
|
||||
rejectUnauthorized: false,
|
||||
});
|
||||
|
||||
const llm = new GigaChat({
|
||||
credentials: process.env.GIGA_AUTH,
|
||||
temperature: 0.2,
|
||||
model: 'GigaChat-2',
|
||||
httpsAgent,
|
||||
});
|
||||
|
||||
// возвращаю комментарий + исправленное предложение + булево значение
|
||||
const moderationLlm = llm.withStructuredOutput(z.object({
|
||||
comment: z.string(),
|
||||
fixedText: z.string().optional(),
|
||||
isApproved: z.boolean(),
|
||||
}) as any)
|
||||
|
||||
export const moderationText = async (title: string, body: string): Promise<[string, string | undefined, boolean]> => {
|
||||
export const moderationText = async (title: string, description: string, GIGA_AUTH): Promise<[string, string | undefined, boolean]> => {
|
||||
|
||||
const moderationLlm = llm_mod(GIGA_AUTH).withStructuredOutput(z.object({
|
||||
comment: z.string(),
|
||||
fixedText: z.string().optional(),
|
||||
isApproved: z.boolean(),
|
||||
}) as any)
|
||||
|
||||
const prompt = `
|
||||
Представь, что ты модерируешь предложения от жильцов многоквартирного дома (это личная инициатива по улучшения,
|
||||
не имеющая отношения к Управляющей компании).
|
||||
|
||||
Заголовок: ${title}
|
||||
Основной текст: ${body}
|
||||
Основной текст: ${description}
|
||||
|
||||
Твои задачи:
|
||||
1. Проверь предложение и заголовок на спам.
|
||||
@@ -58,9 +49,9 @@ export const moderationText = async (title: string, body: string): Promise<[stri
|
||||
const result = await moderationLlm.invoke(prompt);
|
||||
console.log(result)
|
||||
// Дополнительная проверка
|
||||
if(!result.isApproved && result.comment.trim() === '' && result.fixedText.trim() === '') {
|
||||
if(!result.isApproved && result.comment.trim() === '' && (!result.fixedText || result.fixedText.trim() === '')) {
|
||||
result.comment = 'Предложение отклонено. Причина: несоблюдение требований к оформлению или содержанию.',
|
||||
result.fixedText = body
|
||||
result.fixedText = description
|
||||
}
|
||||
|
||||
return [result.comment, result.fixedText, result.isApproved];
|
||||
|
||||
Reference in New Issue
Block a user