Google.Cloud.VertexAI.Extensions - Class VertexAIExtensions (1.0.0-beta04)

public static class VertexAIExtensions

Reference documentation and code samples for the Google.Cloud.VertexAI.Extensions class VertexAIExtensions.

Provides extension methods for creating Microsoft.Extensions.AI clients for Vertex AI.

Inheritance

object > VertexAIExtensions

Namespace

Google.Cloud.VertexAI.Extensions

Assembly

Google.Cloud.VertexAI.Extensions.dll

Methods

AsAITool(Tool)

public static AITool AsAITool(this Tool tool)

Creates an Microsoft.Extensions.AI.AITool to represent a raw Tool.

Parameter
Name Description
tool Tool

The tool to wrap as an Microsoft.Extensions.AI.AITool.

Returns
Type Description
Microsoft.Extensions.AI.AITool

The tool wrapped as an Microsoft.Extensions.AI.AITool.

Remarks

The returned tool is only suitable for use with the Microsoft.Extensions.AI.IChatClient returned by BuildIChatClientAsync(PredictionServiceClientBuilder, string?, IServiceProvider?, CancellationToken) or BuildIChatClient(PredictionServiceClientBuilder, string?, IServiceProvider?) (or Microsoft.Extensions.AI.IChatClients that delegate to such an instance). It is likely to be ignored by any other Microsoft.Extensions.AI.IChatClient implementation.

When a tool has a corresponding Microsoft.Extensions.AI.AITool-derived type already defined in Microsoft.Extensions.AI, such as Microsoft.Extensions.AI.AIFunction or Microsoft.Extensions.AI.HostedWebSearchTool, those types should be preferred instead of this method, as they are more portable, capable of being respected by any Microsoft.Extensions.AI.IChatClient implementation. This method does not attempt to map the supplied Tool to any of those types, it simply wraps it as-is: the Microsoft.Extensions.AI.IChatClient returned by BuildIChatClientAsync(PredictionServiceClientBuilder, string?, IServiceProvider?, CancellationToken)/BuildIChatClient(PredictionServiceClientBuilder, string?, IServiceProvider?) will be able to unwrap the Tool when it processes the list of tools.

BuildIChatClient(PredictionServiceClientBuilder, string?, IServiceProvider?)

public static IChatClient BuildIChatClient(this PredictionServiceClientBuilder builder, string? defaultModelId = null, IServiceProvider? provider = null)

Builds a PredictionServiceClient and creates an Microsoft.Extensions.AI.IChatClient wrapper around it.

Parameters
Name Description
builder PredictionServiceClientBuilder

The PredictionServiceClientBuilder with which to build the PredictionServiceClient.

defaultModelId string

The default model ID to use for chat requests if not specified in Microsoft.Extensions.AI.ChatOptions.ModelId. This must be the full resource name of the model, e.g. "projects/{projectId}/locations/{location}/publishers/{publisher}/models/{model}".

provider IServiceProvider

An optional IServiceProvider from which services are requested when building the client.

Returns
Type Description
Microsoft.Extensions.AI.IChatClient

An Microsoft.Extensions.AI.IChatClient that wraps the built client.

Exceptions
Type Description
ArgumentNullException

builder is null.

BuildIChatClientAsync(PredictionServiceClientBuilder, string?, IServiceProvider?, CancellationToken)

public static Task<IChatClient> BuildIChatClientAsync(this PredictionServiceClientBuilder builder, string? defaultModelId = null, IServiceProvider? provider = null, CancellationToken cancellationToken = default)

Builds a PredictionServiceClient and creates an Microsoft.Extensions.AI.IChatClient wrapper around it.

Parameters
Name Description
builder PredictionServiceClientBuilder

The PredictionServiceClientBuilder with which to build the PredictionServiceClient.

defaultModelId string

The default model ID to use for chat requests if not specified in Microsoft.Extensions.AI.ChatOptions.ModelId. This must be the full resource name of the model, e.g. "projects/{projectId}/locations/{location}/publishers/{publisher}/models/{model}".

provider IServiceProvider

An optional IServiceProvider from which services are requested when building the client.

cancellationToken CancellationToken

A token to cancel the async operation.

Returns
Type Description
TaskMicrosoft.Extensions.AI.IChatClient

An Microsoft.Extensions.AI.IChatClient that wraps the built client.

Exceptions
Type Description
ArgumentNullException

builder is null.

BuildIEmbeddingGenerator(PredictionServiceClientBuilder, string?, int?, IServiceProvider?)

public static IEmbeddingGenerator<string, Embedding<float>> BuildIEmbeddingGenerator(this PredictionServiceClientBuilder builder, string? defaultModelId = null, int? defaultModelDimensions = null, IServiceProvider? provider = null)

Builds a PredictionServiceClient and creates an Microsoft.Extensions.AI.IEmbeddingGenerator<TInput, TEmbedding> wrapper around it.

Parameters
Name Description
builder PredictionServiceClientBuilder

The PredictionServiceClientBuilder with which to build the PredictionServiceClient.

defaultModelId string

The default model ID to use for chat requests if not specified in Microsoft.Extensions.AI.EmbeddingGenerationOptions.ModelId. This must be the full resource name of the model, e.g. "projects/{projectId}/locations/{location}/publishers/{publisher}/models/{model}".

defaultModelDimensions System.Int32

The optional default output dimensions for the embeddings.

provider IServiceProvider

An optional IServiceProvider from which services are requested when building the client.

Returns
Type Description
Microsoft.Extensions.AI.IEmbeddingGenerator<TInput, TEmbedding>stringMicrosoft.Extensions.AI.Embedding`1System.Single

An Microsoft.Extensions.AI.IEmbeddingGenerator<TInput, TEmbedding> that wraps the built client.

Exceptions
Type Description
ArgumentNullException

builder is null.

BuildIEmbeddingGeneratorAsync(PredictionServiceClientBuilder, string?, int?, IServiceProvider?, CancellationToken)

public static Task<IEmbeddingGenerator<string, Embedding<float>>> BuildIEmbeddingGeneratorAsync(this PredictionServiceClientBuilder builder, string? defaultModelId = null, int? defaultModelDimensions = null, IServiceProvider? provider = null, CancellationToken cancellationToken = default)

Builds a PredictionServiceClient and creates an Microsoft.Extensions.AI.IEmbeddingGenerator<TInput, TEmbedding> wrapper around it.

Parameters
Name Description
builder PredictionServiceClientBuilder

The PredictionServiceClientBuilder with which to build the PredictionServiceClient.

defaultModelId string

The default model ID to use for chat requests if not specified in Microsoft.Extensions.AI.EmbeddingGenerationOptions.ModelId. This must be the full resource name of the model, e.g. "projects/{projectId}/locations/{location}/publishers/{publisher}/models/{model}".

defaultModelDimensions System.Int32

The optional default output dimensions for the embeddings.

provider IServiceProvider

An optional IServiceProvider from which services are requested when building the client.

cancellationToken CancellationToken

A token to cancel the async operation.

Returns
Type Description
TaskMicrosoft.Extensions.AI.IEmbeddingGenerator<TInput, TEmbedding>stringMicrosoft.Extensions.AI.Embedding`1System.Single

An Microsoft.Extensions.AI.IEmbeddingGenerator<TInput, TEmbedding> that wraps the built client.

Exceptions
Type Description
ArgumentNullException

builder is null.

BuildIImageGenerator(PredictionServiceClientBuilder, string?, IServiceProvider?)

public static IImageGenerator BuildIImageGenerator(this PredictionServiceClientBuilder builder, string? defaultModelId = null, IServiceProvider? provider = null)

Builds a PredictionServiceClient and creates an Microsoft.Extensions.AI.IImageGenerator wrapper around it.

Parameters
Name Description
builder PredictionServiceClientBuilder

The PredictionServiceClientBuilder with which to build the PredictionServiceClient.

defaultModelId string

The default model ID to use for chat requests if not specified in Microsoft.Extensions.AI.ImageGenerationOptions.ModelId. This must be the full resource name of the model, e.g. "projects/{projectId}/locations/{location}/publishers/{publisher}/models/{model}".

provider IServiceProvider

An optional IServiceProvider from which services are requested when building the client.

Returns
Type Description
Microsoft.Extensions.AI.IImageGenerator

An Microsoft.Extensions.AI.IImageGenerator that wraps the built client.

Exceptions
Type Description
ArgumentNullException

builder is null.

BuildIImageGeneratorAsync(PredictionServiceClientBuilder, string?, IServiceProvider?, CancellationToken)

public static Task<IImageGenerator> BuildIImageGeneratorAsync(this PredictionServiceClientBuilder builder, string? defaultModelId = null, IServiceProvider? provider = null, CancellationToken cancellationToken = default)

Builds a PredictionServiceClient and creates an Microsoft.Extensions.AI.IImageGenerator wrapper around it.

Parameters
Name Description
builder PredictionServiceClientBuilder

The PredictionServiceClientBuilder with which to build the PredictionServiceClient.

defaultModelId string

The default model ID to use for chat requests if not specified in Microsoft.Extensions.AI.ImageGenerationOptions.ModelId. This must be the full resource name of the model, e.g. "projects/{projectId}/locations/{location}/publishers/{publisher}/models/{model}".

provider IServiceProvider

An optional IServiceProvider from which services are requested when building the client.

cancellationToken CancellationToken

A token to cancel the async operation.

Returns
Type Description
TaskMicrosoft.Extensions.AI.IImageGenerator

An Microsoft.Extensions.AI.IImageGenerator that wraps the built client.

Exceptions
Type Description
ArgumentNullException

builder is null.