feat: изменил логику анализа отзывов
Backend CI / build-and-test (push) Failing after 14m19s
🚀 Create and publish a Docker image / Detect changes in backend and frontend (push) Failing after 12m5s
Frontend CI / build-and-check (push) Failing after 17m58s
🚀 Create and publish a Docker image / Build & publish frontend image (push) Failing after 10m11s
🚀 Create and publish a Docker image / Build & publish backend image (push) Failing after 11m3s
🚀 Create and publish a Docker image / Update stack on Portainer (push) Failing after 14m58s

This commit is contained in:
2026-05-22 01:30:41 +03:00
parent 168d6af860
commit 8ac593d36f
36 changed files with 858 additions and 457 deletions
@@ -1,5 +1,6 @@
using System.Net.Http.Json;
using System.Text.Json;
using System.Text.Json.Serialization;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using UniVerse.Application.Interfaces;
@@ -49,11 +50,37 @@ public class LlmClient : ILlmClient
var json = await response.Content.ReadFromJsonAsync<JsonElement>();
var content = json.GetProperty("choices")[0].GetProperty("message").GetProperty("content").GetString()!;
var analysis = JsonSerializer.Deserialize<LlmRawResponse>(content,
var analysisJson = NormalizeJsonContent(content);
var analysis = JsonSerializer.Deserialize<LlmRawResponse>(analysisJson,
new JsonSerializerOptions { PropertyNameCaseInsensitive = true })!;
return new LlmReviewAnalysis(analysis.QualityScore, analysis.Sentiment, analysis.Tags, analysis.IsInformative);
return new LlmReviewAnalysis(
Math.Clamp(analysis.QualityScore, 0, 1),
analysis.Sentiment ?? "",
analysis.Tags ?? [],
analysis.IsInformative,
content);
}
private record LlmRawResponse(double QualityScore, string Sentiment, string[] Tags, bool IsInformative);
private static string NormalizeJsonContent(string content)
{
var trimmed = content.Trim();
if (!trimmed.StartsWith("```", StringComparison.Ordinal))
return trimmed;
var firstNewLine = trimmed.IndexOf('\n');
if (firstNewLine < 0)
return trimmed;
var lastFence = trimmed.LastIndexOf("```", StringComparison.Ordinal);
return lastFence > firstNewLine
? trimmed[(firstNewLine + 1)..lastFence].Trim()
: trimmed[(firstNewLine + 1)..].Trim();
}
private record LlmRawResponse(
[property: JsonPropertyName("quality_score")] double QualityScore,
string? Sentiment,
string[]? Tags,
[property: JsonPropertyName("is_informative")] bool IsInformative);
}