Skip to content

Ai

Namespace: Vercel.AI

public static class Ai

Static entry points. String model ids use the AI Gateway and AI_GATEWAY_API_KEY.

Inheritance: object

View source

ConvertToModelMessages(IReadOnlyList<UIMessage>, ConvertToModelMessagesOptions?)

Section titled “ConvertToModelMessages(IReadOnlyList<UIMessage>, ConvertToModelMessagesOptions?)”
public static IReadOnlyList<ModelMessage> ConvertToModelMessages(IReadOnlyList<UIMessage> messages, ConvertToModelMessagesOptions? options = null)

Converts UI messages from a chat UI into model messages. Maps to convertToModelMessages.

Parameters

Name Type Description
messages IReadOnlyList<UIMessage>
options ConvertToModelMessagesOptions

Returns: IReadOnlyList<ModelMessage>

View source

CosineSimilarity(IReadOnlyList<float>, IReadOnlyList<float>)

Section titled “CosineSimilarity(IReadOnlyList<float>, IReadOnlyList<float>)”
public static double CosineSimilarity(IReadOnlyList<float> left, IReadOnlyList<float> right)

Cosine similarity of two vectors.

Parameters

Name Type Description
left IReadOnlyList<float>
right IReadOnlyList<float>

Returns: double

View source

EmbedAsync(EmbedOptions, CancellationToken)

Section titled “EmbedAsync(EmbedOptions, CancellationToken)”
public static Task<float[]> EmbedAsync(EmbedOptions options, CancellationToken cancellationToken = default)

Embeds one value.

Parameters

Name Type Description
options EmbedOptions
cancellationToken CancellationToken

Returns: Task<float[]>

View source

EmbedManyAsync(EmbedOptions, CancellationToken)

Section titled “EmbedManyAsync(EmbedOptions, CancellationToken)”
public static Task<EmbeddingResult> EmbedManyAsync(EmbedOptions options, CancellationToken cancellationToken = default)

Embeds many values.

Parameters

Name Type Description
options EmbedOptions
cancellationToken CancellationToken

Returns: Task<EmbeddingResult>

View source

GenerateTextAsync(GenerateTextOptions, CancellationToken)

Section titled “GenerateTextAsync(GenerateTextOptions, CancellationToken)”
public static Task<GenerateTextResult> GenerateTextAsync(GenerateTextOptions options, CancellationToken cancellationToken = default)

Generates text.

Parameters

Name Type Description
options GenerateTextOptions
cancellationToken CancellationToken

Returns: Task<GenerateTextResult>

View source

public static IReadOnlyList<ModelMessage> PruneMessages(PruneMessagesOptions options)

Prunes reasoning, tool calls, results, errors, and approvals from messages. Maps to pruneMessages.

Parameters

Name Type Description
options PruneMessagesOptions

Returns: IReadOnlyList<ModelMessage>

View source

StreamTextAsync(StreamTextOptions, CancellationToken)

Section titled “StreamTextAsync(StreamTextOptions, CancellationToken)”
public static StreamTextResult StreamTextAsync(StreamTextOptions options, CancellationToken cancellationToken = default)

Streams text.

Parameters

Name Type Description
options StreamTextOptions
cancellationToken CancellationToken

Returns: StreamTextResult

View source

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