feat: implement AI-driven text streaming and dynamic knowledge graph generation in AiAssistantBubble
This commit is contained in:
@@ -2,4 +2,6 @@ using NexusReader.Application.Abstractions.Messaging;
|
||||
|
||||
namespace NexusReader.Application.Queries.Graph;
|
||||
|
||||
public record GetKnowledgeGraphQuery : IQuery<GraphDataDto>;
|
||||
/// <param name="Text">Chapter or page content to extract the graph from.</param>
|
||||
public record GetKnowledgeGraphQuery(string Text) : IQuery<GraphDataDto>;
|
||||
|
||||
|
||||
@@ -1,15 +1,42 @@
|
||||
using FluentResults;
|
||||
using NexusReader.Application.Abstractions.Messaging;
|
||||
using NexusReader.Application.Abstractions.Services;
|
||||
|
||||
namespace NexusReader.Application.Queries.Graph;
|
||||
|
||||
internal sealed class GetKnowledgeGraphQueryHandler : IQueryHandler<GetKnowledgeGraphQuery, GraphDataDto>
|
||||
{
|
||||
public Task<Result<GraphDataDto>> Handle(GetKnowledgeGraphQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var nodes = new List<GraphNodeDto>();
|
||||
var links = new List<GraphLinkDto>();
|
||||
private readonly IKnowledgeService _knowledgeService;
|
||||
|
||||
return Task.FromResult(Result.Ok(new GraphDataDto { Nodes = nodes, Links = links }));
|
||||
public GetKnowledgeGraphQueryHandler(IKnowledgeService knowledgeService)
|
||||
{
|
||||
_knowledgeService = knowledgeService;
|
||||
}
|
||||
|
||||
public async Task<Result<GraphDataDto>> Handle(GetKnowledgeGraphQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(request.Text))
|
||||
return Result.Ok(new GraphDataDto());
|
||||
|
||||
var result = await _knowledgeService.GetGraphDataAsync(request.Text, cancellationToken);
|
||||
|
||||
if (result.IsFailed)
|
||||
return Result.Fail<GraphDataDto>(result.Errors);
|
||||
|
||||
var graph = result.Value.Graph;
|
||||
|
||||
if (graph is null)
|
||||
return Result.Ok(new GraphDataDto());
|
||||
|
||||
var nodes = graph.Nodes
|
||||
.Select(n => new GraphNodeDto(n.Id, n.Label, n.Group))
|
||||
.ToList();
|
||||
|
||||
var links = graph.Links
|
||||
.Select(l => new GraphLinkDto(l.Source, l.Target, l.Value))
|
||||
.ToList();
|
||||
|
||||
return Result.Ok(new GraphDataDto { Nodes = nodes, Links = links });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user