Files
CodeAnalizer/CodeBase/Services/LlmPromptBuilder.cs

50 lines
2.3 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<GraphNodeContext> graphContexts)
{
var promptBuilder = new StringBuilder();
promptBuilder.AppendLine("Ты — опытный C#-архитектор. Твоя задача — ответить на вопрос пользователя, опираясь ИСКЛЮЧИТЕЛЬНО на предоставленный граф вызовов и зависимостей кода. Не придумывай методы или классы, которых нет в контексте.");
promptBuilder.AppendLine("\nКонтекст из кодовой базы (Граф зависимостей):");
foreach (var node in graphContexts)
{
promptBuilder.AppendLine("--------------------------------------------------");
promptBuilder.AppendLine($"[ГЛАВНЫЙ УЗЕЛ]");
promptBuilder.AppendLine($"Имя: {node.MethodName}");
promptBuilder.AppendLine($"Файл: {node.FilePath}");
// Добавляем зависимости ВНИЗ (что использует метод)
if (node.OutgoingDependencies.Any())
{
promptBuilder.AppendLine("\n[ИСПОЛЬЗУЕТ ВНУТРИ СЕБЯ]:");
foreach (var dep in node.OutgoingDependencies.Distinct())
{
promptBuilder.AppendLine($"- {dep}");
}
}
// Добавляем зависимости ВВЕРХ (кто зависит от метода)
if (node.IncomingDependencies.Any())
{
promptBuilder.AppendLine("\n[ВЫЗЫВАЕТСЯ ИЗ]:");
foreach (var caller in node.IncomingDependencies.Distinct())
{
promptBuilder.AppendLine($"- {caller}");
}
}
promptBuilder.AppendLine("\nКод:");
promptBuilder.AppendLine(node.Content);
}
promptBuilder.AppendLine("--------------------------------------------------");
promptBuilder.AppendLine($"Вопрос пользователя: {userQuestion}");
return promptBuilder.ToString();
}
}