Table of Contents

Class PollingHttpClient<TRequest, TResponse>

Namespace
FoundationaLLM.Common.Clients
Assembly
FoundationaLLM.Common.dll

Provides a generic HTTP client that can be used to poll for a response.

public class PollingHttpClient<TRequest, TResponse> where TRequest : CompletionRequestBase where TResponse : CompletionResponseBase

Type Parameters

TRequest

The type of the payload to send to start the operation.

TResponse

The type of the response received when the operation is completed.

Inheritance
PollingHttpClient<TRequest, TResponse>
Inherited Members
Extension Methods

Constructors

PollingHttpClient(HttpClient, HttpClient, TRequest?, string, string, TimeSpan, TimeSpan, ILogger)

Provides a generic HTTP client that can be used to poll for a response.

public PollingHttpClient(HttpClient operationStarterHttpClient, HttpClient operationRetrieverHttpClient, TRequest? request, string operationStarterPath, string operationRetrieverPathTemplate, TimeSpan pollingInterval, TimeSpan maxWaitTime, ILogger logger)

Parameters

operationStarterHttpClient HttpClient

The HttpClient used to start the operation.

operationRetrieverHttpClient HttpClient

The HttpClient used to retrieve the operation (including its status).

request TRequest

The TRequest request to send to the service.

operationStarterPath string

The path used to start the operation.

operationRetrieverPathTemplate string

The path template used to retrieve the operation (including its status).

pollingInterval TimeSpan

The TimeSpan interval to poll for the response.

maxWaitTime TimeSpan

The TimeSpan maximum time to wait for the response.

logger ILogger

The logger used for logging.

Methods

ExecuteOperationAsync(CancellationToken)

Executes an operation and waits for the response using a polling mechanism. The polling mechanism is based on the following assumptions:

- The {operationStarterPath} endpoint will accept a POST with a TRequest object as payload and will return a 202 Accepted status code when the operation is started.
- The returned response will contain a LongRunningOperation object with the operation id.
- The polling endpoint is available at {operationStarterPath}/{operationId}/status.
- The polling endpoint will return a 200 status code when the operation is found.
- The returned response will contain a LongRunningOperation object with the current status of the operation, possibly including the result if the operation completed.
- The polling endpoint will return a 404 Not Found status code when the operation is not found.
public Task<TResponse?> ExecuteOperationAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

The CancellationToken indicating the need to cancel the process.

Returns

Task<TResponse>

The TResponse object containing the response.

Exceptions

InvalidOperationException

GetOperationStatusAsync(string, CancellationToken)

Gets the status of a running operation.

public Task<LongRunningOperation> GetOperationStatusAsync(string operationId, CancellationToken cancellationToken = default)

Parameters

operationId string

The identifier of the running operation.

cancellationToken CancellationToken

The CancellationToken indicating the need to cancel the process.

Returns

Task<LongRunningOperation>

A LongRunningOperationobject providing details about the running operation.

StartOperationAsync(CancellationToken)

Starts an operation and returns immediately.

public Task<LongRunningOperation> StartOperationAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

The CancellationToken indicating the need to cancel the process.

Returns

Task<LongRunningOperation>

A LongRunningOperationobject providing details about the newly started operation.