Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/Mindee/V2/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,13 @@ InputSource inputSource
/// <param name="ct"></param>
/// <returns></returns>
public async Task<TAnnotationResponse> UploadRagDocumentAsync<TAnnotationResponse>(
LocalInputSource inputSource, RagDocumentUploadParameters parameters, CancellationToken ct = default)
LocalInputSource inputSource
, BaseRagDocumentUploadParameters<TAnnotationResponse> parameters
, CancellationToken ct = default)
Comment thread
ianardee marked this conversation as resolved.
where TAnnotationResponse : BaseRagAnnotationResponse, new()
{
_logger?.LogInformation("Adding a document to the RAG database");
return await _mindeeApi.ReqPostRagDocumentAsync<TAnnotationResponse>(parameters, inputSource, ct);
return await _mindeeApi.ReqPostRagDocumentAsync(parameters, inputSource, ct);
}

/// <summary>
Expand All @@ -255,15 +257,14 @@ public async Task<TAnnotationResponse> UploadRagDocumentAsync<TAnnotationRespons
/// <returns></returns>
public async Task<TAnnotationResponse> UploadAndGetRagDocumentPollAsync<TAnnotationResponse>(
LocalInputSource inputSource
, RagDocumentUploadParameters parameters
, BaseRagDocumentUploadParameters<TAnnotationResponse> parameters
, PollingOptions pollingOptions = null
, CancellationToken ct = default)
where TAnnotationResponse : BaseRagAnnotationResponse, new()
{
pollingOptions ??= new PollingOptions();

var initialResponse = await UploadRagDocumentAsync<TAnnotationResponse>(
inputSource, parameters, ct);
var initialResponse = await UploadRagDocumentAsync(inputSource, parameters, ct);

return await PollForRagDocumentAsync<TAnnotationResponse>(
initialResponse, pollingOptions, ct);
Expand Down Expand Up @@ -303,8 +304,7 @@ string documentId
return initialResponse;

pollingOptions ??= new PollingOptions();
return await PollForRagDocumentAsync<TAnnotationResponse>(
initialResponse, pollingOptions, ct);
return await PollForRagDocumentAsync<TAnnotationResponse>(initialResponse, pollingOptions, ct);
}

/// <summary>
Expand All @@ -314,11 +314,11 @@ string documentId
/// <param name="ct"></param>
/// <returns></returns>
public async Task<TAnnotationResponse> UpdateRagAnnotationAsync<TAnnotationResponse>(
BaseAnnotationParameters parameters, CancellationToken ct = default)
BaseAnnotationParameters<TAnnotationResponse> parameters, CancellationToken ct = default)
where TAnnotationResponse : BaseRagAnnotationResponse, new()
{
_logger?.LogInformation("Updating RAG document ID: {DocumentId}", parameters.DocumentId);
return await _mindeeApi.ReqPatchRagAnnotationAsync<TAnnotationResponse>(parameters, ct);
return await _mindeeApi.ReqPatchRagAnnotationAsync(parameters, ct);
}

/// <summary>
Expand All @@ -329,13 +329,13 @@ public async Task<TAnnotationResponse> UpdateRagAnnotationAsync<TAnnotationRespo
/// <param name="ct"></param>
/// <returns></returns>
public async Task<TAnnotationResponse> UpdateAndGetRagAnnotationPollAsync<TAnnotationResponse>(
BaseAnnotationParameters parameters
BaseAnnotationParameters<TAnnotationResponse> parameters
, PollingOptions pollingOptions = null
, CancellationToken ct = default)
where TAnnotationResponse : ExtractionRagAnnotationResponse, new()
{
_logger?.LogInformation("Updating RAG document ID: {DocumentId}", parameters.DocumentId);
var initialResponse = await _mindeeApi.ReqPatchRagAnnotationAsync<TAnnotationResponse>(parameters, ct);
var initialResponse = await _mindeeApi.ReqPatchRagAnnotationAsync(parameters, ct);
if (initialResponse.Status != "Processing")
return initialResponse;

Expand Down
4 changes: 3 additions & 1 deletion src/Mindee/V2/ClientOptions/BaseAnnotationParameters.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using System;
using System.Collections.Generic;
using Mindee.V2.Parsing;

namespace Mindee.V2.ClientOptions
{
/// <summary>
/// Base parameters for document annotations.
/// </summary>
public abstract class BaseAnnotationParameters
public abstract class BaseAnnotationParameters<TAnnotationResponse>
where TAnnotationResponse : BaseRagAnnotationResponse
Comment thread
ianardee marked this conversation as resolved.
{
/// <summary>
/// UUID of the annotated document.
Expand Down
39 changes: 39 additions & 0 deletions src/Mindee/V2/ClientOptions/BaseRagDocumentUploadParameters.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using Mindee.V2.Parsing;

namespace Mindee.V2.ClientOptions
{
/// <summary>
/// Base parameters for document upload operations.
/// </summary>
public abstract class BaseRagDocumentUploadParameters<TAnnotationResponse>
where TAnnotationResponse : BaseRagAnnotationResponse
Comment thread
ianardee marked this conversation as resolved.
{
/// <summary>
/// UUID of the model that the uploaded RAG document is linked to.
/// </summary>
public string ModelId { get; }

/// <summary>
/// Default constructor.
/// </summary>
/// <param name="modelId"><see cref="ModelId"/></param>
protected BaseRagDocumentUploadParameters(string modelId)
{
if (string.IsNullOrWhiteSpace(modelId))
throw new ArgumentException("ModelId cannot be null or whitespace.", nameof(modelId));
ModelId = modelId.Trim();
}

/// <summary>
/// Gets the request parameters for the upload request.
/// </summary>
public virtual Dictionary<string, string> GetRequestParameters()
{
var parameters = new Dictionary<string, string>();
parameters.Add("model_id", ModelId);
return parameters;
}
}
}
4 changes: 2 additions & 2 deletions src/Mindee/V2/Http/HttpApiV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public abstract Task<TSearchResponse> ReqGetSearchAsync<TSearchResponse>(
/// <param name="localInputSource"></param>
/// <param name="cancellationToken"></param>
public abstract Task<TAnnotationResponse> ReqPostRagDocumentAsync<TAnnotationResponse>(
RagDocumentUploadParameters parameters
BaseRagDocumentUploadParameters<TAnnotationResponse> parameters
, LocalInputSource localInputSource
, CancellationToken cancellationToken = default)
where TAnnotationResponse : BaseRagAnnotationResponse, new();
Comment thread
ianardee marked this conversation as resolved.
Expand All @@ -115,7 +115,7 @@ public abstract Task<TAnnotationResponse> ReqGetRagAnnotationAsync<TAnnotationRe
/// <param name="parameters"></param>
/// <param name="cancellationToken"></param>
public abstract Task<TAnnotationResponse> ReqPatchRagAnnotationAsync<TAnnotationResponse>(
BaseAnnotationParameters parameters, CancellationToken cancellationToken = default)
BaseAnnotationParameters<TAnnotationResponse> parameters, CancellationToken cancellationToken = default)
where TAnnotationResponse : BaseRagAnnotationResponse, new();

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions src/Mindee/V2/Http/MindeeApiV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public override async Task<TSearchResponse> ReqGetSearchAsync<TSearchResponse>(
}

public override async Task<TAnnotationResponse> ReqPostRagDocumentAsync<TAnnotationResponse>(
RagDocumentUploadParameters parameters
BaseRagDocumentUploadParameters<TAnnotationResponse> parameters
, LocalInputSource localInputSource
, CancellationToken cancellationToken = default)
{
Expand All @@ -120,7 +120,7 @@ public override async Task<TAnnotationResponse> ReqGetRagAnnotationAsync<TAnnota
}

public override async Task<TAnnotationResponse> ReqPatchRagAnnotationAsync<TAnnotationResponse>(
BaseAnnotationParameters parameters, CancellationToken cancellationToken = default)
BaseAnnotationParameters<TAnnotationResponse> parameters, CancellationToken cancellationToken = default)
{
var request = new RestRequest(
$"/v2/products/extraction/rag-documents/{parameters.DocumentId}", Method.Patch);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Mindee.V2.Product.Extraction.RagDocuments.Params
/// <summary>
/// Annotation parameters for RAG documents.
/// </summary>
public class RagDocumentAnnotationParameters : BaseAnnotationParameters
public class RagDocumentAnnotationParameters : BaseAnnotationParameters<ExtractionRagAnnotationResponse>
{
/// <summary>
/// New public status to apply to the document (for example, to deactivate it).
Expand All @@ -23,7 +23,9 @@ public class RagDocumentAnnotationParameters : BaseAnnotationParameters
/// <summary>
/// Default constructor.
/// </summary>
/// <param name="documentId"><see cref="BaseAnnotationParameters.DocumentId"/></param>
/// <param name="documentId">
/// <see cref="BaseAnnotationParameters{TAnnotationResponse}.DocumentId"/>
/// </param>
/// <param name="status"><see cref="Status"/></param>
/// <param name="annotation"><see cref="Annotation"/></param>
public RagDocumentAnnotationParameters(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,19 @@
using System;
using System.Collections.Generic;
using Mindee.V2.ClientOptions;

namespace Mindee.V2.Product.Extraction.RagDocuments.Params
{
/// <summary>
/// Upload parameters for RAG documents.
/// </summary>
public class RagDocumentUploadParameters
public class RagDocumentUploadParameters : BaseRagDocumentUploadParameters<ExtractionRagAnnotationResponse>
{
/// <summary>
/// UUID of the extraction model that the uploaded RAG document is linked to.
/// <inheritdoc/>
/// </summary>
public string ModelId { get; }

/// <summary>
/// Default constructor.
/// </summary>
/// <param name="modelId"><see cref="ModelId"/></param>
public RagDocumentUploadParameters(string modelId)
{
if (string.IsNullOrWhiteSpace(modelId))
throw new ArgumentException("ModelId cannot be null or whitespace.", nameof(modelId));
ModelId = modelId.Trim();
}

/// <summary>
/// Gets the request parameters for the upload request.
/// </summary>
public virtual Dictionary<string, string> GetRequestParameters()
{
var parameters = new Dictionary<string, string>();
parameters.Add("model_id", ModelId);
return parameters;
}
/// <param name="modelId"><inheritdoc/></param>
public RagDocumentUploadParameters(string modelId) : base(modelId)
{ }
}
}
Loading