Changes
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
using Api.Models.Requests;
|
||||
using Api.Models.Responses;
|
||||
|
||||
namespace Api.Clients.Api.Contracts;
|
||||
|
||||
public interface IRagApiClient
|
||||
{
|
||||
Task<RagIndexResponse> IndexCvPdfAsync(IFormFile file, CancellationToken ct);
|
||||
Task<RagIndexResponse> IndexJobTextAsync(string text, string? url, string? title, CancellationToken ct);
|
||||
Task<RagDocumentDetails?> GetDocumentAsync(string documentId, CancellationToken ct);
|
||||
Task<RagSearchResponse> SearchAsync(RagSearchRequest request, CancellationToken ct);
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using Refit;
|
||||
using Api.Models.Responses;
|
||||
using Api.Models.Requests;
|
||||
|
||||
namespace Api.Clients.Api.Contracts;
|
||||
|
||||
[Headers("Accept: application/json")]
|
||||
public interface IRefitRagApi
|
||||
{
|
||||
[Multipart]
|
||||
[Post("/api/rag/documents")]
|
||||
Task<RagIndexResponse> IndexDocumentAsync([AliasAs("file")] StreamPart file,
|
||||
[AliasAs("documentType")] string documentType,
|
||||
[AliasAs("title")] string title,
|
||||
CancellationToken ct = default);
|
||||
|
||||
[Multipart]
|
||||
[Post("/api/rag/documents")]
|
||||
Task<RagIndexResponse> IndexDocumentWithTextAsync([AliasAs("text")] string text,
|
||||
[AliasAs("documentType")] string documentType,
|
||||
[AliasAs("title")] string title,
|
||||
[AliasAs("sourceUrl")] string? sourceUrl = null,
|
||||
CancellationToken ct = default);
|
||||
|
||||
[Get("/api/rag/documents/{documentId}")]
|
||||
Task<RagDocumentDetails> GetDocumentAsync(string documentId, CancellationToken ct = default);
|
||||
|
||||
[Post("/api/rag/search")]
|
||||
Task<RagSearchResponse> SearchAsync([Body] RagSearchRequest request, CancellationToken ct = default);
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
using System.Net;
|
||||
using Refit;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Api.Clients.Api.Contracts;
|
||||
using Api.Models.Responses;
|
||||
using Api.Models.Settings;
|
||||
using Api.Models.Requests;
|
||||
|
||||
namespace Api.Clients.Api;
|
||||
|
||||
public sealed class RagApiClient : IRagApiClient
|
||||
{
|
||||
private readonly IRefitRagApi _refit;
|
||||
|
||||
public RagApiClient(IRefitRagApi refit, IOptions<RagApiSettings> options)
|
||||
{
|
||||
_refit = refit;
|
||||
}
|
||||
|
||||
public async Task<RagIndexResponse> IndexCvPdfAsync(IFormFile file, CancellationToken ct)
|
||||
{
|
||||
await using var stream = file.OpenReadStream();
|
||||
var part = new StreamPart(stream, file.FileName, "application/pdf");
|
||||
return await _refit.IndexDocumentAsync(part, "cv", file.FileName, ct);
|
||||
}
|
||||
|
||||
public async Task<RagIndexResponse> IndexJobTextAsync(string text, string? url, string? title, CancellationToken ct)
|
||||
{
|
||||
return await _refit.IndexDocumentWithTextAsync(text, "job", title ?? "Job description", url, ct);
|
||||
}
|
||||
|
||||
public async Task<RagDocumentDetails?> GetDocumentAsync(string documentId, CancellationToken ct)
|
||||
{
|
||||
try
|
||||
{
|
||||
return await _refit.GetDocumentAsync(documentId, ct);
|
||||
}
|
||||
catch (ApiException ex) when (ex.StatusCode == HttpStatusCode.NotFound)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<RagSearchResponse> SearchAsync(RagSearchRequest request, CancellationToken ct)
|
||||
{
|
||||
return await _refit.SearchAsync(request, ct);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user