- XAIServiceBase: add PrepareChatRequirementsAsync as the single entry point for chat prerequisites (normalize RAG params, resolve default project/conversation, ingest attachments, retrieve RAG context, build history, persist prompt message) and return the new XPreparedChatContext; - XAIServiceBase: add NormalizeRagParams (topK / minScore / type) and use it in all Ask* methods instead of duplicated inline normalization; - XAIServiceBase: rework GetHistory - the single GetHistory(ChatMessage, bool) signature is replaced by two overloads GetHistory(prompt, forcePrompt) and GetHistory(prompt, context); the latter is used by the non-persisted chat path; - XAIServiceBase: remove AskLLMAsync; LLM invocation is now inlined in each Ask* method over prep.History; - XAIServiceBase: rewrite AskAsync and AskAsEnumerable on top of PrepareChatRequirementsAsync; streamed responses now use Role = Assistant, RespondTo = prep.PersistedPromptMessage.Id and Sequence++; - XAIServiceBase: use XAiApiConstants.XAiApiRagPromptName instead of configuration.RAGDescriptor.PromptName; - XAIServiceBase.LoadConversations: call the renamed GetDafaultProject; - Add Models/XPreparedChatContext.cs (Project, Conversation, History, Context, PersistedPromptMessage) as the shared context between actions; - XAiRAGService: wrap each file ingest in its own try/catch with logger.LogError so one bad file no longer aborts the whole ingest; - XAiRAGService: upload the file and add a scope reference (providedFor / forProvidedId) for the ingested scope; - XAiRAGService: remove stale vectors of the same document via RemoveVectorsAsync(identifierPrefix) when replaceExisting is set; - XInMemoryVectorStore: make session retrieval thread-safe via lock (found.SyncRoot) and ReferenceEquals check against concurrent removal; - XAiServiceControllerBase.Ask: pass the attached files to the AI service (was files: null) so RAG works on attachments; - XModelsExtensions: relax ChatWithDocuments ask validation - TopK and MinScore are optional again (defaults come from RAGDescriptor); - XAiModelProxyMiddleware: use logical OR instead of bitwise OR in the authentication check; - XAiEmbeddingServiceBase: do not dispose the embedding generator (removed `using` to avoid premature disposal); - ChatWithDocumentsController: reorder EmbedChunks parameters; - Remove Interfaces/IXAiEmbeddingServiceControllerBase.cs.
695 lines
22 KiB
C#
695 lines
22 KiB
C#
using System;
|
|
using System.Linq;
|
|
using xAiApi.Models;
|
|
using System.Threading;
|
|
using xAiApi.Interfaces;
|
|
using xAiApi.Extensions;
|
|
using xCommons.Providers;
|
|
using xCommons.Extensions;
|
|
using xAiApi.Configurations;
|
|
using xExceptions.Constants;
|
|
using xAiModels.Models.Dtos;
|
|
using System.Threading.Tasks;
|
|
using xHttpService.Extensions;
|
|
using xCommons.Configurations;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Http;
|
|
using System.Collections.Generic;
|
|
using xIdentityService.Interfaces;
|
|
using xIdentityService.Controllers;
|
|
using xAiApi.Interfaces.Extractors;
|
|
using Microsoft.Extensions.Logging;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
namespace xAiApi.Controllers
|
|
{
|
|
/// <summary>
|
|
/// Chat With Documents (In-Memory RAG) Controller ...
|
|
/// Flow: Ingest Files -> SessionId -> Ask / AskStream -> Delete Session
|
|
/// </summary>
|
|
[Authorize]
|
|
[Route("[controller]")]
|
|
public class ChatWithDocumentsController : XBaseIdentityApiV1Controller
|
|
{
|
|
/// <summary>
|
|
/// Default AI Service ...
|
|
/// </summary>
|
|
private readonly IXAiService aiService;
|
|
|
|
/// <summary>
|
|
/// Text Chunker Service ...
|
|
/// </summary>
|
|
private readonly IXTextChunker textChunker;
|
|
|
|
/// <summary>
|
|
/// In Memory Vector Store ...
|
|
/// </summary>
|
|
private readonly IXInMemoryVectorStore vectorStore;
|
|
|
|
/// <summary>
|
|
/// XAiApi Configuration ...
|
|
/// </summary>
|
|
private readonly XAiApiConfiguration apiConfiguration;
|
|
|
|
/// <summary>
|
|
/// Embedding Service ...
|
|
/// </summary>
|
|
private readonly IXAiEmbeddingService embeddingService;
|
|
|
|
/// <summary>
|
|
/// File Context Extractor Service ...
|
|
/// </summary>
|
|
private readonly IXFileContentExtractor fileContentExtractor;
|
|
|
|
public ChatWithDocumentsController(
|
|
IXAiService aiService,
|
|
IXTextChunker textChunker,
|
|
IXInMemoryVectorStore vectorStore,
|
|
XAppConfiguration appConfiguration,
|
|
IXIdentityProvider identityProvider,
|
|
XAiApiConfiguration apiConfiguration,
|
|
IXAiEmbeddingService embeddingService,
|
|
XValidationProvider validationProvider,
|
|
ILogger<ChatWithDocumentsController> logger,
|
|
IXFileContentExtractor fileContentExtractor
|
|
) : base(logger, appConfiguration, identityProvider, validationProvider)
|
|
{
|
|
//
|
|
this.aiService = aiService;
|
|
this.textChunker = textChunker;
|
|
this.vectorStore = vectorStore;
|
|
this.apiConfiguration = apiConfiguration;
|
|
this.embeddingService = embeddingService;
|
|
this.fileContentExtractor = fileContentExtractor;
|
|
}
|
|
|
|
//
|
|
#region Ingest ...
|
|
/// <summary>
|
|
/// Ingest Files into a (new or existing) In-Memory Session:
|
|
/// Extract -> Chunk -> Embed -> Store ...
|
|
/// </summary>
|
|
/// <param name="files"></param>
|
|
/// <param name="sessionId">Optional: Add to an Existing Session</param>
|
|
/// <param name="ttlMinutes">Optional: Session TTL in Minutes (only for new Session)</param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("Ingest")]
|
|
[Consumes("multipart/form-data")]
|
|
public async Task<ActionResult<XAiDocumentIngestResult>> Ingest(
|
|
[FromForm] IFormFileCollection files,
|
|
[FromForm] Guid? sessionId = null,
|
|
[FromForm] int? ttlMinutes = null,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
try
|
|
{
|
|
//
|
|
// Validate ...
|
|
if (!files.HasChild())
|
|
{
|
|
XException.InvalidArgs.Throw();
|
|
}
|
|
|
|
//
|
|
var userInfo = await GetUserInfo();
|
|
var ownerId = userInfo.UserId;
|
|
|
|
//
|
|
// Resolve Target Session ...
|
|
Guid targetSessionId;
|
|
if (sessionId.HasValue && sessionId.Value != Guid.Empty)
|
|
{
|
|
//
|
|
if (!vectorStore.TryGet(sessionId.Value, out _, ownerId))
|
|
{
|
|
XException.NotFound.Throw();
|
|
}
|
|
targetSessionId = sessionId.Value;
|
|
}
|
|
else
|
|
{
|
|
//
|
|
var ttl = TimeSpan.FromMinutes(
|
|
ttlMinutes.HasValue && ttlMinutes.Value > 0
|
|
? ttlMinutes.Value
|
|
: apiConfiguration.RAGDescriptor.DefaultTtlMinutes
|
|
);
|
|
targetSessionId = vectorStore.CreateSession(ownerId, ttl);
|
|
}
|
|
|
|
//
|
|
var result = new XAiDocumentIngestResult
|
|
{
|
|
SessionId = targetSessionId
|
|
};
|
|
|
|
//
|
|
// Extract -> Chunk -> Embed ...
|
|
var vectors = new List<XAiVectorDto>();
|
|
foreach (var file in files)
|
|
{
|
|
//
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
//
|
|
if (file.IsNull() || file.Length == 0)
|
|
{
|
|
result.SkippedFiles.Add(file?.FileName ?? "(null)");
|
|
continue;
|
|
}
|
|
|
|
//
|
|
var mimeType = file.ContentType?.ToLowerInvariant() ?? string.Empty;
|
|
if (!fileContentExtractor.CanExtract(mimeType))
|
|
{
|
|
result.SkippedFiles.Add(file.FileName);
|
|
continue;
|
|
}
|
|
|
|
//
|
|
var text = await ExtractText(file, mimeType, cancellationToken);
|
|
if (string.IsNullOrWhiteSpace(text))
|
|
{
|
|
result.SkippedFiles.Add(file.FileName);
|
|
continue;
|
|
}
|
|
|
|
//
|
|
var chunks = textChunker.Chunk(text, file.FileName);
|
|
if (!chunks.HasChild())
|
|
{
|
|
result.SkippedFiles.Add(file.FileName);
|
|
continue;
|
|
}
|
|
|
|
//
|
|
// Embed in Batches ...
|
|
var fileVectors = await EmbedChunks(
|
|
chunks: chunks,
|
|
fileName: file.FileName,
|
|
mimeType: mimeType,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
|
|
//
|
|
vectors.AddRange(fileVectors);
|
|
result.FilesCount++;
|
|
}
|
|
|
|
//
|
|
// Store ...
|
|
if (vectors.HasChild() &&
|
|
!vectorStore.Add(targetSessionId, vectors, ownerId))
|
|
{
|
|
XException.ActionFailed.Throw();
|
|
}
|
|
|
|
//
|
|
// Fill Result ...
|
|
result.ChunksCount = vectors.Count;
|
|
if (vectorStore.TryGet(targetSessionId, out var session, ownerId))
|
|
{
|
|
lock (session.SyncRoot)
|
|
{
|
|
result.TotalVectorsCount = session.Vectors.Count;
|
|
}
|
|
result.ExpiresAtUtc = session.LastAccessAtUtc.Add(session.Ttl);
|
|
}
|
|
|
|
//
|
|
return Ok(result);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
var result = GetExceptionActionResult(ex);
|
|
return result;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
//
|
|
#region Ask ...
|
|
/// <summary>
|
|
/// Ask a Question over Ingested Documents ...
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("Ask")]
|
|
public async Task<ActionResult<XAiDocumentAnswer>> Ask(
|
|
[FromBody] XAiDocumentAskRequest request,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
try
|
|
{
|
|
//
|
|
// Validate ...
|
|
if (!request.IsValid())
|
|
{
|
|
XException.InvalidArgs.Throw();
|
|
}
|
|
|
|
//
|
|
var userInfo = await GetUserInfo();
|
|
var ownerId = userInfo.UserId;
|
|
|
|
//
|
|
// Check Session ...
|
|
if (!vectorStore.TryGet(request.SessionId, out _, ownerId))
|
|
{
|
|
XException.NotFound.Throw();
|
|
}
|
|
|
|
//
|
|
// Retrieve ...
|
|
var context = await Retrieve(request, ownerId, cancellationToken);
|
|
|
|
//
|
|
var result = new XAiDocumentAnswer
|
|
{
|
|
SessionId = request.SessionId,
|
|
Sources = ToSources(context)
|
|
};
|
|
|
|
//
|
|
if (!context.HasChild())
|
|
{
|
|
result.NoContextFound = true;
|
|
return Ok(result);
|
|
}
|
|
|
|
//
|
|
// Generate ...
|
|
result.Answer = await aiService.AskTextByContextAsync(
|
|
context: context,
|
|
userInfo: userInfo,
|
|
prompt: request.Prompt,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
|
|
//
|
|
return Ok(result);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
var result = GetExceptionActionResult(ex);
|
|
return result;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ask a Question over Ingested Documents and Stream Response (SSE) ...
|
|
/// First Event Carries Sources, Next Events Carry Text Deltas, Last Event has IsFinal = true ...
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("AskStream")]
|
|
public async Task AskStream(
|
|
[FromBody] XAiDocumentAskRequest request,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
// Validate (before Stream Starts -> Proper Http Error) ...
|
|
if (!request.IsValid())
|
|
{
|
|
//
|
|
Response.StatusCode = StatusCodes.Status400BadRequest;
|
|
Response.ContentType = "application/json; charset=utf-8";
|
|
await Response.WriteAsync(XException.InvalidArgs.ToXError().ToJSON());
|
|
return;
|
|
}
|
|
|
|
//
|
|
try
|
|
{
|
|
//
|
|
var userInfo = await GetUserInfo();
|
|
var ownerId = userInfo.UserId;
|
|
|
|
//
|
|
// Check Session ...
|
|
if (!vectorStore.TryGet(request.SessionId, out _, ownerId))
|
|
{
|
|
XException.NotFound.Throw();
|
|
}
|
|
|
|
//
|
|
// Retrieve ...
|
|
var context = await Retrieve(request, ownerId, cancellationToken);
|
|
|
|
//
|
|
// Configure SSE Response ...
|
|
Response.PrepareSseResponse();
|
|
|
|
//
|
|
// First Event: Sources ...
|
|
var hasContext = context.HasChild();
|
|
await WriteChunk(new XAiDocumentAnswerChunk
|
|
{
|
|
Text = string.Empty,
|
|
IsFinal = !hasContext,
|
|
NoContextFound = !hasContext,
|
|
Sources = ToSources(context)
|
|
}, cancellationToken);
|
|
|
|
//
|
|
if (!hasContext)
|
|
{
|
|
await Response.WriteSseDoneAsync(cancellationToken);
|
|
return;
|
|
}
|
|
|
|
//
|
|
// Stream Deltas ...
|
|
var enumerable = aiService.AskTextByContextAsEnumerable(
|
|
context: context,
|
|
userInfo: userInfo,
|
|
prompt: request.Prompt,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
await foreach (var delta in enumerable)
|
|
{
|
|
//
|
|
if (delta.IsNullOrEmpty())
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
await WriteChunk(new XAiDocumentAnswerChunk
|
|
{
|
|
Text = delta
|
|
}, cancellationToken);
|
|
}
|
|
|
|
//
|
|
// Final Event ...
|
|
await WriteChunk(new XAiDocumentAnswerChunk
|
|
{
|
|
Text = string.Empty,
|
|
IsFinal = true
|
|
}, cancellationToken);
|
|
await Response.WriteSseDoneAsync(cancellationToken);
|
|
}
|
|
catch (Exception ex) when (ex.IsClientCancellation(cancellationToken))
|
|
{
|
|
// Client Disconnected ...
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
Logger.LogError(ex, "ChatWithDocuments: AskStream Failed");
|
|
if (!Response.HasStarted)
|
|
{
|
|
//
|
|
var result = GetExceptionActionResult(ex);
|
|
await result.ExecuteResultAsync(ControllerContext);
|
|
return;
|
|
}
|
|
|
|
//
|
|
await Response.WriteSseErrorAsync(ex.Message);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
//
|
|
#region Session ...
|
|
/// <summary>
|
|
/// Retrieve Session Info (without Embeddings) ...
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("Session/{id:guid}")]
|
|
public async Task<ActionResult<XAiDocumentSessionInfo>> GetSession(Guid id)
|
|
{
|
|
//
|
|
try
|
|
{
|
|
//
|
|
var userInfo = await GetUserInfo();
|
|
if (!vectorStore.TryGet(id, out var session, userInfo.UserId))
|
|
{
|
|
XException.NotFound.Throw();
|
|
}
|
|
|
|
//
|
|
IList<XAiVectorDto> vectors;
|
|
lock (session.SyncRoot)
|
|
{
|
|
vectors = session.Vectors.ToList();
|
|
}
|
|
|
|
//
|
|
var result = new XAiDocumentSessionInfo
|
|
{
|
|
Id = session.Id,
|
|
Ttl = session.Ttl,
|
|
VectorsCount = vectors.Count,
|
|
CreatedAtUtc = session.CreatedAtUtc,
|
|
LastAccessAtUtc = session.LastAccessAtUtc,
|
|
ExpiresAtUtc = session.LastAccessAtUtc.Add(session.Ttl),
|
|
Files = [.. vectors
|
|
.Select(v => v.Metadata.GetMetadata(apiConfiguration.RAGDescriptor.MetadataFileName))
|
|
.Where(f => !f.IsNullOrEmpty())
|
|
.Distinct()]
|
|
};
|
|
|
|
//
|
|
return Ok(result);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
var result = GetExceptionActionResult(ex);
|
|
return result;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Remove a Session and Free Memory ...
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
[HttpDelete("Session/{id:guid}")]
|
|
public async Task<ActionResult<bool>> DeleteSession(Guid id)
|
|
{
|
|
//
|
|
try
|
|
{
|
|
//
|
|
var userInfo = await GetUserInfo();
|
|
if (!vectorStore.Remove(id, userInfo.UserId))
|
|
{
|
|
XException.NotFound.Throw();
|
|
}
|
|
|
|
//
|
|
return Ok(true);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
var result = GetExceptionActionResult(ex);
|
|
return result;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
//
|
|
#region Private ...
|
|
/// <summary>
|
|
/// Extract Plain Text of a File (Text or Audio Transcript) ...
|
|
/// </summary>
|
|
private async Task<string> ExtractText(
|
|
IFormFile file,
|
|
string mimeType,
|
|
CancellationToken cancellationToken
|
|
)
|
|
{
|
|
//
|
|
try
|
|
{
|
|
//
|
|
using var stream = file.OpenReadStream();
|
|
var extraction = await fileContentExtractor.ExtractRichAsync(
|
|
fileStream: stream,
|
|
mimeType: mimeType,
|
|
fileName: file.FileName,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
|
|
//
|
|
var result = extraction?.Text;
|
|
if (string.IsNullOrWhiteSpace(result))
|
|
{
|
|
result = extraction?.AudioTranscript;
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
catch (OperationCanceledException)
|
|
{
|
|
throw;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Logger.LogWarning(ex, "ChatWithDocuments: Extraction Failed for {FileName}", file.FileName);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Embed Chunks in Batches and Build Vectors ...
|
|
/// </summary>
|
|
private async Task<IList<XAiVectorDto>> EmbedChunks(
|
|
IList<XTextChunk> chunks,
|
|
string fileName,
|
|
string mimeType,
|
|
CancellationToken cancellationToken
|
|
)
|
|
{
|
|
//
|
|
var result = new List<XAiVectorDto>(chunks.Count);
|
|
var batchSize = apiConfiguration.RAGDescriptor.EmbeddingBatchSize;
|
|
|
|
//
|
|
for (var offset = 0; offset < chunks.Count; offset += batchSize)
|
|
{
|
|
//
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
//
|
|
var batch = chunks.Skip(offset).Take(batchSize).ToList();
|
|
var embeddings = await embeddingService.Embeddings(
|
|
batch: batch.Select(c => c.Text).ToArray(),
|
|
cancellationToken: cancellationToken
|
|
);
|
|
|
|
//
|
|
if (embeddings.IsNullOrDefault() || embeddings.Count != batch.Count)
|
|
{
|
|
XException.ActionFailed.Throw();
|
|
}
|
|
|
|
//
|
|
for (var i = 0; i < batch.Count; i++)
|
|
{
|
|
//
|
|
var chunk = batch[i];
|
|
result.Add(new XAiVectorDto
|
|
{
|
|
Id = Guid.NewGuid(),
|
|
Text = chunk.Text,
|
|
Embedding = embeddings[i],
|
|
Identifier = chunk.Identifier,
|
|
Metadata = new Dictionary<string, string>
|
|
{
|
|
[apiConfiguration.RAGDescriptor.MetadataFileName] = fileName,
|
|
[apiConfiguration.RAGDescriptor.MetadataMimeType] = mimeType,
|
|
[apiConfiguration.RAGDescriptor.MetadataChunkIndex] = chunk.Index.ToString()
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Embed Prompt and Search Session ...
|
|
/// </summary>
|
|
private async Task<IList<XAiVectorSearchResult>> Retrieve(
|
|
XAiDocumentAskRequest request,
|
|
string ownerId,
|
|
CancellationToken cancellationToken
|
|
)
|
|
{
|
|
//
|
|
var topK = Math.Clamp(
|
|
request.TopK ?? apiConfiguration.RAGDescriptor.DefaultTopK,
|
|
1,
|
|
apiConfiguration.RAGDescriptor.MaxTopK
|
|
);
|
|
var minScore = request.MinScore ?? apiConfiguration.RAGDescriptor.DefaultMinScore;
|
|
|
|
//
|
|
var queryEmbedding = await embeddingService.Embedding(
|
|
content: request.Prompt,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
if (queryEmbedding.IsNullOrDefault() || queryEmbedding.Length == 0)
|
|
{
|
|
XException.ActionFailed.Throw();
|
|
}
|
|
|
|
//
|
|
var result = vectorStore.Search(
|
|
topK: topK,
|
|
ownerId: ownerId,
|
|
minScore: minScore,
|
|
sessionId: request.SessionId,
|
|
queryEmbedding: queryEmbedding
|
|
);
|
|
|
|
//
|
|
return result ?? [];
|
|
}
|
|
|
|
/// <summary>
|
|
/// Map Search Results to Public Sources ...
|
|
/// </summary>
|
|
private IList<XAiDocumentSource> ToSources(
|
|
IEnumerable<XAiVectorSearchResult> context
|
|
)
|
|
{
|
|
//
|
|
var result = (context ?? [])
|
|
.Select(c =>
|
|
{
|
|
//
|
|
var chunkIndexText = c.Metadata.GetMetadata(apiConfiguration.RAGDescriptor.MetadataChunkIndex);
|
|
var text = c.Text ?? string.Empty;
|
|
var snippetLength = Math.Min(text.Length, apiConfiguration.RAGDescriptor.SourceSnippetLength);
|
|
|
|
//
|
|
return new XAiDocumentSource
|
|
{
|
|
Score = c.Score,
|
|
Identifier = c.Identifier,
|
|
Snippet = text.Substring(0, snippetLength),
|
|
ChunkIndex = int.TryParse(chunkIndexText, out var idx) ? idx : null,
|
|
FileName = c.Metadata.GetMetadata(apiConfiguration.RAGDescriptor.MetadataFileName)
|
|
};
|
|
})
|
|
.ToList();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Write a SSE Event ...
|
|
/// </summary>
|
|
private Task WriteChunk(
|
|
XAiDocumentAnswerChunk chunk,
|
|
CancellationToken cancellationToken
|
|
)
|
|
{
|
|
//
|
|
return Response.WriteSseEventAsync(
|
|
data: chunk,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
}
|
|
#endregion
|
|
}
|
|
}
|