Skip to content

BatchResultsApiBase

Namespace: Vercel.AI.ProviderUtils

public abstract class BatchResultsApiBase : IBatchApi

Batch API that downloads results. Start, status, cancel, and list throw unless a provider overrides them.

Inheritance: object

Implements: IBatchApi

Derived: AnthropicBatchApi, GatewayBatchApi, GoogleBatchApi, OpenAIBatchApi

View source

public virtual bool CanCancel { get; }

True when cancellation is implemented.

Value: bool

View source

public virtual bool CanList { get; }

True when listing is implemented.

Value: bool

View source

public abstract string Provider { get; }

Provider id.

Value: string

View source

ConvertRows(IAsyncEnumerable<JsonElement>, Func<JsonElement, BatchItem>, CancellationToken)

Section titled “ConvertRows(IAsyncEnumerable<JsonElement>, Func<JsonElement, BatchItem>, CancellationToken)”
protected static IAsyncEnumerable<BatchItem> ConvertRows(IAsyncEnumerable<JsonElement> rows, Func<JsonElement, BatchItem> convert, CancellationToken cancellationToken = default)

Converts each row of a JSON Lines download as it is read.

Parameters

Name Type Description
rows IAsyncEnumerable<JsonElement>
convert Func<JsonElement, BatchItem>
cancellationToken CancellationToken

Returns: IAsyncEnumerable<BatchItem>

View source

DoCancelAsync(BatchOperationCall, CancellationToken)

Section titled “DoCancelAsync(BatchOperationCall, CancellationToken)”
public virtual Task<BatchCancelResult> DoCancelAsync(BatchOperationCall call, CancellationToken cancellationToken)

Cancels a batch.

Parameters

Name Type Description
call BatchOperationCall
cancellationToken CancellationToken

Returns: Task<BatchCancelResult>

View source

DoGetResultsAsync(BatchOperationCall, CancellationToken)

Section titled “DoGetResultsAsync(BatchOperationCall, CancellationToken)”
public abstract Task<IAsyncEnumerable<BatchItem>> DoGetResultsAsync(BatchOperationCall call, CancellationToken cancellationToken)

Opens the result stream. Errors found while opening, such as a batch that is not complete, throw from the task. Errors found while reading, such as a malformed row, throw from the stream.

Parameters

Name Type Description
call BatchOperationCall
cancellationToken CancellationToken

Returns: Task<IAsyncEnumerable<BatchItem>>

View source

DoGetStatusAsync(BatchOperationCall, CancellationToken)

Section titled “DoGetStatusAsync(BatchOperationCall, CancellationToken)”
public virtual Task<BatchStatus> DoGetStatusAsync(BatchOperationCall call, CancellationToken cancellationToken)

Reads status.

Parameters

Name Type Description
call BatchOperationCall
cancellationToken CancellationToken

Returns: Task<BatchStatus>

View source

DoListAsync(BatchOperationCall, CancellationToken)

Section titled “DoListAsync(BatchOperationCall, CancellationToken)”
public virtual Task<BatchListResult> DoListAsync(BatchOperationCall call, CancellationToken cancellationToken)

Lists batches. The implementation is invoked on this instance.

Parameters

Name Type Description
call BatchOperationCall
cancellationToken CancellationToken

Returns: Task<BatchListResult>

View source

DoStartAsync(BatchOperationCall, CancellationToken)

Section titled “DoStartAsync(BatchOperationCall, CancellationToken)”
public virtual Task<BatchStartResult> DoStartAsync(BatchOperationCall call, CancellationToken cancellationToken)

Starts a batch.

Parameters

Name Type Description
call BatchOperationCall
cancellationToken CancellationToken

Returns: Task<BatchStartResult>

View source

protected static string? Str(JsonElement element, string name)

Text of a string property, or null.

Parameters

Name Type Description
element JsonElement
name string

Returns: string

View source

TextItem(string, IEnumerable<string>, string?, string?, string?)

Section titled “TextItem(string, IEnumerable<string>, string?, string?, string?)”
protected static BatchItem TextItem(string id, IEnumerable<string> texts, string? finishReason, string? responseId, string? modelId)

Builds a succeeded text item from joined text parts.

Parameters

Name Type Description
id string
texts IEnumerable<string>
finishReason string
responseId string
modelId string

Returns: BatchItem

View source

Apache-2.0 · Copyright 2023 Vercel, Inc. · unofficial community port, not an official Vercel product