Files
CodeAnalizer/CodeBase/Services/LlmPromptBuilder.cs

41 lines
1.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using CodeBase.Models;
using System.Collections.Generic;
using System.Text;
public class LlmPromptBuilder
{
public string BuildPrompt(string userQuestion, List<CodeChunk> foundChunks)
{
var sb = new StringBuilder();
// 1. Задаем жесткую роль и ограничения
sb.AppendLine("Ты — опытный разработчик и архитектор. Твоя задача — ответить на вопрос пользователя.");
sb.AppendLine("ОТВЕЧАЙ СТРОГО НА ОСНОВЕ ПРЕДОСТАВЛЕННОГО КОДА НИЖЕ.");
sb.AppendLine("Если в коде нет ответа на вопрос, честно скажи: «В данном фрагменте кода нет этой информации». Не придумывай функции, которых нет в тексте.");
sb.AppendLine("\n================ ПРЕДОСТАВЛЕННЫЙ КОД ================");
// 2. Вклеиваем найденные чанки с контекстом
foreach (var chunk in foundChunks)
{
sb.AppendLine($"Файл: {chunk.FilePath}");
sb.AppendLine($"Класс: {chunk.ClassName}");
sb.AppendLine($"Метод: {chunk.MethodName}");
if (!string.IsNullOrEmpty(chunk.Documentation))
{
sb.AppendLine($"Документация: {chunk.Documentation}");
}
sb.AppendLine("Код:");
sb.AppendLine("```csharp");
sb.AppendLine(chunk.Content);
sb.AppendLine("```");
sb.AppendLine("--------------------------------------------------");
}
// 3. Добавляем сам вопрос
sb.AppendLine("\n================ ВОПРОС ПОЛЬЗОВАТЕЛЯ ================");
sb.AppendLine(userQuestion);
return sb.ToString();
}
}