699просмотров
14 февраля 2025 г.
📷 ФотоScore: 769
Полезное дополнение к draw.io для отрисовки схем https://app.eraser.io/. Архитектура решения:
Fullstack Next.js 15
Mongodb + prisma
Typescript + zod
Redis + bullmq
LLM deepseek-r1:1.5b В процессе разработки решения и прикручивания ML, столкнулись с проблемой парсинга результатов и передачей их на анализ. Если чекнуть медиум.ком, то обычно это плагин openapi и API чатгпт, но шелекей нам жалко, поэтому смотрим в сторону localhost. Для локальной работы плагин так же можно юзать от опенапи, просто меняем адрес нейронки. Но что оказалось, так это слабые нейрокни до 8b не могут нормально обработать промпт "Верни объект json" и возвращают все что угодно, сначала танцевали с регулярками для очистки вывода, но это продолжалось до конца. И как будто бы должно быть другое решение? И его нашли для себя. Ollama добавила возможность жестко указать тип возвращаемых данных ответа. Вместо openapi берем плагин ламы и задаём чат с ним. https://ollama.com/blog/structured-outputs
To pass structured outputs to the model, the format parameter can be used in the Python or JavaScript libraries. import ollama from "ollama"; async function fetchJsonResponseForSingleIssue(issue, prompt) { const response = await ollama.chat({ model: process.env.LLM || "deepseek-r1:7b", stream: false, format: { type: "object", properties: { path: { type: "string" }, threat: { type: "boolean" }, recommendations: { type: "array", items: { type: "string" } }, vulnerability: { type: "string" } }, required: ["path", "threat", "recommendations", "vulnerability"] }, messages: [ { role: "system", content: You are an expert in API and OpenAPI security. Your task is to analyze the results of the OpenAPI security linter according to the OWASP API Security rules. You will be provided with:
1. The linter output containing detected security issues. Your objective:
- Carefully analyze the linter's findings. - Extract relevant security issues and recommendations for mitigation.
- set the threat field TRUE if the defect is considered positive, FALSE if not }, { role: "user", content: JSON.stringify(issue, null, 2) }, // Отправляем один элемент { role: "user", content: prompt } ] }); return JSON.parse(response.message.content); } Получаем jsonы для парсинга. 😎