Попытки в мультипарсинг

This commit is contained in:
2026-07-24 13:47:21 +04:00
parent b2a13528ee
commit eb8dac7627
22 changed files with 1486 additions and 37 deletions

View File

@@ -22,6 +22,28 @@ namespace CodeBase.Services
// Адрес нашего локального Python-сервиса
_httpClient.BaseAddress = new Uri("http://localhost:8000/");
}
private const int MaxCodeLength = 1500;
private string BuildSafeContext(CodeChunk chunk)
{
// Метаданные (оставляем всегда целиком)
string metadata = $"File: {chunk.FilePath}\nEntity: {chunk.EntityName}\nCode:\n";
// Вычисляем, сколько символов у нас осталось для самого кода
int remainingLength = MaxCodeLength - metadata.Length;
string code = chunk.Content;
// Если код слишком длинный — аккуратно отрезаем хвост
if (code.Length > remainingLength && remainingLength > 0)
{
code = code.Substring(0, remainingLength) + "\n...[TRUNCATED]";
Console.WriteLine($"[ВЕКТОРИЗАЦИЯ] Метод {chunk.EntityName} слишком длинный. Обрезан до {MaxCodeLength} символов.");
}
return metadata + code;
}
public async Task<float[]> GetVectorAsync(string text)
@@ -55,7 +77,7 @@ namespace CodeBase.Services
{
// 1. Склеиваем контекст
// Мы даем нейросети подсказку о том, где именно лежит этот код
string contextText = $"File: {chunk.FilePath}\nClass: {chunk.ClassName}\nMethod: {chunk.MethodName}\nCode:\n{chunk.Content}";
string contextText = BuildSafeContext(chunk);
var requestBody = new VectorizeRequest { text = contextText };
@@ -71,13 +93,13 @@ namespace CodeBase.Services
if (result != null && result.vector != null)
{
// 4. Сохраняем вектор прямо в наш объект в памяти
chunk.Vector = result.vector;
Console.WriteLine($"[+] Векторизован метод: {chunk.MethodName}");
chunk.Embedding = result.vector;
Console.WriteLine($"[+] Векторизована сущность: {chunk.EntityName}");
}
}
else
{
Console.WriteLine($"[-] Ошибка API для {chunk.MethodName}: {response.StatusCode}");
Console.WriteLine($"[-] Ошибка API для {chunk.EntityName}: {response.StatusCode}");
}
}