介绍适用于 .NET 的 Google Cloud Vertex AI 扩展

本文宣布了 Google.Cloud.VertexAI.Extensions 库的 Beta 版发布,该库为 Google Vertex AI 实现了 Microsoft.Extensions.AI 抽象。这使得 .NET 开发者能够利用统一的 API 进行聊天、嵌入和图像生成,从而方便地在 Google、OpenAI 和 Azure 等 AI 供应商之间进行切换。虽然现有的 Google Gen AI .NET SDK 仍然是专注于 Google 应用的首选,但这个新库是专门为在 .NET 生态系统中寻求架构灵活性和供应商无关代码的开发者设计的。




In October 2024, Microsoft announced the Microsoft.Extensions.AI.Abstractions and Microsoft.Extensions.AI libraries for .NET. These libraries provide the .NET ecosystem with essential abstractions for integrating AI services into .NET applications from various providers such as Open AI, Azure, Google.

Today, we’re happy to announce the Google.Cloud.VertexAI.Extensions library. This is the Vertex AI implementation of Microsoft.Extensions.AI. This library enables .NET developers to integrate Google Gemini models on Vertex AI via the Microsoft.Extensions.AI abstractions. 

Note: This library is currently in pre-release/beta pending user feedback. Please reach out with any feedback you might have. 

Core benefits

  • Unified API: Delivers a consistent set of APIs and conventions for integrating AI services into .NET applications.

  • Flexibility: Allows .NET library authors to use AI services without being tied to a specific provider, making it adaptable to any provider.

  • Ease of Use: Enables .NET developers to experiment with different packages using the same underlying abstractions, maintaining a single API throughout their application.

APIs and functionality

There are three core interfaces: 

  • The IChatClient interface defines a client abstraction responsible for interacting with AI services that provide chat capabilities.

  • The IEmbeddingGenerator interface represents a generic generator of embeddings.

  • The IImageGenerator interface (experimental) represents a generator for creating images from text prompts or other input.

What’s the Google.Cloud.VertexAI.Extensions library?

The Microsoft.Extensions.AI library supports  providers like OpenAI, Azure, and Ollama. The Google.Cloud.VertexAI.Extensions library is the Vertex AI implementation of Microsoft.Extensions.AI. It enables .NET developers to integrate with Google’s Gemini on Vertex AI via the Microsoft.Extensions.AI abstractions. 

What about the Google Gen AI .NET SDK? 

At this point, you might be wondering: Doesn’t Google already have a .NET SDK for Gemini?

You’re right. There’s the Google Gen AI .NET SDK that we announced back in October 2025. Developers building applications that will only use Google as an AI provider should continue to use the Google Gen AI .NET SDK. Developers building applications that may use different AI providers (Google, OpenAI, Azure ...) will benefit from the Google.Cloud.VertexAI.Extensions library.

Samples

Now that we understand the context, let’s take a look at some samples. 

Microsoft.Extensions.AI with Ollama

Before we look into Google.Cloud.VertexAI.Extensions, let’s actually look at the hello world chat sample with Ollama.

Let’s take a look at the details.

What’s the Microsoft.Extension.AI library?

Microsoft.Extensions.AI is a set of core .NET libraries that provide a unified layer of C# abstractions for interacting with AI services from different providers such as OpenAI, Azure AI Inference, Ollama.

https://storage.googleapis.com/gweb-cloudblog-publish/images/screenshot1_nGonzZI.max-1100x1100.png

This is Ollama using a Gemma3 model. That was easy enough! 

Getting started with Google.Cloud.VertexAI.Extensions

To use Google.Cloud.VertexAI.Extensions, first, you need to add the package to your project. It’s currently in preview, so make sure to check for the latest beta version.

dotnet add package Google.Cloud.VertexAI.Extensions --prerelease

You will also need the Microsoft.Extensions.AI package:

dotnet add package Microsoft.Extensions.AI

Chat

To use the IChatClient interface, first you need to initialize the client with Vertex AI specific initialization:

https://storage.googleapis.com/gweb-cloudblog-publish/images/screenshot2.max-1100x1100.png

Then, you can start asking questions to the model:

var response = await client.GetResponseAsync("Why is the sky blue?");

Console.WriteLine(response.Text);

Note that this sample is identical to the Ollama one and samples are the same across different providers. That’s the beauty of abstractions! The only unique part for Vertex AI is how the client is initialized.

You can also get back streaming responses:

https://storage.googleapis.com/gweb-cloudblog-publish/images/screenshot3.max-600x600.png
https://storage.googleapis.com/gweb-cloudblog-publish/images/screenshot4.max-900x900.png

You can also keep track of the chat history and send it along:

https://storage.googleapis.com/gweb-cloudblog-publish/images/screenshot5.max-1300x1300.png

Embeddings

For embeddings, create an embedding generator:

https://storage.googleapis.com/gweb-cloudblog-publish/images/screenshot6.max-700x700.png

Generate embeddings for several inputs:

https://storage.googleapis.com/gweb-cloudblog-publish/images/screenshot7.max-900x900.png

Image Generation

Image generation follows the same pattern. 

Create an image generator for Vertex AI:

https://storage.googleapis.com/gweb-cloudblog-publish/images/screenshot8.max-700x700.png

Generate an image:

https://storage.googleapis.com/gweb-cloudblog-publish/images/screenshot9.max-1100x1100.png

And you should see a cute baby sea otter!

https://storage.googleapis.com/gweb-cloudblog-publish/images/otter.max-1100x1100.png

The source code for all the samples is in my Google.Cloud.VertexAI.Extensions samples repo on GitHub.

Conclusion

In this blog post, we explored the Google.Cloud.VertexAI.Extensions library to enable .NET developers to Google’s Gemini models via the Microsoft.Extension.AI library. If you have any questions or feedback about the library, please reach out to me on X @meteatamel or LinkedIn meteatamel.

Here are some links to explore more:


AI 前线

超越聊天机器人:可信 AI 蓝图

2026-1-31 18:42:36

AI 前线

Spring AI 智能体模式(第五部分):利用 Agent2Agent (A2A) 协议构建互操作智能体

2026-1-31 18:42:41

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索