Skip to content

OpenAIFileStore

Namespace: Vercel.AI.OpenAI

public sealed class OpenAIFileStore : IFileStore

OpenAI file store.

Inheritance: object

Implements: IFileStore

View source

public OpenAIFileStore(OpenAIProvider provider)

Creates a file store.

Parameters

Name Type Description
provider OpenAIProvider

View source

public string Provider { get; }

Provider id.

Value: string

View source

public string SpecificationVersion { get; }

Specification version.

Value: string

View source

DeleteAsync(OpenAIFileReference, CancellationToken)

Section titled “DeleteAsync(OpenAIFileReference, CancellationToken)”
public Task DeleteAsync(OpenAIFileReference file, CancellationToken cancellationToken)

Deletes a file.

Parameters

Name Type Description
file OpenAIFileReference
cancellationToken CancellationToken

Returns: Task

View source

DownloadAsync(OpenAIFileReference, CancellationToken)

Section titled “DownloadAsync(OpenAIFileReference, CancellationToken)”
public Task<(byte[] Data, string? MediaType)> DownloadAsync(OpenAIFileReference file, CancellationToken cancellationToken)

Downloads file bytes. The media type has parameters removed.

Parameters

Name Type Description
file OpenAIFileReference
cancellationToken CancellationToken

Returns: Task<(byte[] Data, string MediaType)>

View source

GetMetadataAsync(OpenAIFileReference, CancellationToken)

Section titled “GetMetadataAsync(OpenAIFileReference, CancellationToken)”
public Task<OpenAIFileMetadata> GetMetadataAsync(OpenAIFileReference file, CancellationToken cancellationToken)

Reads file metadata.

Parameters

Name Type Description
file OpenAIFileReference
cancellationToken CancellationToken

Returns: Task<OpenAIFileMetadata>

View source

public static string RequireId(OpenAIFileReference file)

Returns the OpenAI file id or throws when it is missing.

Parameters

Name Type Description
file OpenAIFileReference

Returns: string

View source

UploadAsync(Stream, string?, string, string?, int?, CancellationToken)

Section titled “UploadAsync(Stream, string?, string, string?, int?, CancellationToken)”
public Task<OpenAIFileMetadata> UploadAsync(Stream data, string? fileName, string mediaType, string? purpose, int? expiresAfterSeconds, CancellationToken cancellationToken)

Uploads a file from a stream without buffering it, and disposes the stream. The fields precede the file part, and the file name defaults to blob.

Parameters

Name Type Description
data Stream
fileName string
mediaType string
purpose string
expiresAfterSeconds int?
cancellationToken CancellationToken

Returns: Task<OpenAIFileMetadata>

View source

UploadAsync(string, byte[], string, string?, int?, CancellationToken)

Section titled “UploadAsync(string, byte[], string, string?, int?, CancellationToken)”
public Task<OpenAIFileMetadata> UploadAsync(string fileName, byte[] data, string mediaType, string? purpose, int? expiresAfterSeconds, CancellationToken cancellationToken)

Uploads a file. <code class=“paramref”>expiresAfterSeconds</code> sends expires_after.

Parameters

Name Type Description
fileName string
data byte[]
mediaType string
purpose string
expiresAfterSeconds int?
cancellationToken CancellationToken

Returns: Task<OpenAIFileMetadata>

View source

UploadFileAsync(string, byte[], string, CancellationToken)

Section titled “UploadFileAsync(string, byte[], string, CancellationToken)”
public Task<UploadedFile> UploadFileAsync(string fileName, byte[] data, string mediaType, CancellationToken cancellationToken)

Uploads a file.

Parameters

Name Type Description
fileName string
data byte[]
mediaType string
cancellationToken CancellationToken

Returns: Task<UploadedFile>

View source

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