feat: integrate AI-driven selection panel with context-aware text summarization and quiz generation features.

This commit is contained in:
2026-04-26 20:36:08 +02:00
parent 82d726097f
commit 39a9ca5706
25 changed files with 819 additions and 219 deletions
@@ -15,25 +15,36 @@ public class WasmKnowledgeService : IKnowledgeService
}
public async Task<Result<KnowledgePacket>> GetKnowledgeAsync(string text, CancellationToken cancellationToken = default)
{
return await CallKnowledgeApiAsync("/api/knowledge", text, cancellationToken);
}
public async Task<Result<KnowledgePacket>> GetGraphDataAsync(string text, CancellationToken cancellationToken = default)
{
return await CallKnowledgeApiAsync("/api/knowledge/graph", text, cancellationToken);
}
public async Task<Result<KnowledgePacket>> GetSummaryAndQuizAsync(string text, CancellationToken cancellationToken = default)
{
return await CallKnowledgeApiAsync("/api/knowledge/summary", text, cancellationToken);
}
private async Task<Result<KnowledgePacket>> CallKnowledgeApiAsync(string endpoint, string text, CancellationToken cancellationToken)
{
try
{
Console.WriteLine($"[WasmKnowledgeService] Calling API for extraction (Text length: {text.Length})...");
var response = await _httpClient.PostAsJsonAsync("/api/knowledge", new { text }, cancellationToken);
var response = await _httpClient.PostAsJsonAsync(endpoint, new { text }, cancellationToken);
if (response.IsSuccessStatusCode)
{
Console.WriteLine("[WasmKnowledgeService] API Response success. Deserializing...");
var packet = await response.Content.ReadFromJsonAsync<KnowledgePacket>(cancellationToken: cancellationToken);
return packet != null ? Result.Ok(packet) : Result.Fail("Failed to deserialize knowledge packet.");
}
var errorBody = await response.Content.ReadAsStringAsync(cancellationToken);
Console.WriteLine($"[WasmKnowledgeService] API Error ({response.StatusCode}): {errorBody}");
return Result.Fail($"Server error ({response.StatusCode}): {errorBody}");
}
catch (Exception ex)
{
Console.WriteLine($"[WasmKnowledgeService] Exception: {ex.Message}");
return Result.Fail(new Error($"Network or parsing error: {ex.Message}").CausedBy(ex));
}
}