Location>code7788 >text

preliminary

Popularity:225 ℃/2024-11-20 10:37:05

NET Conf on .

Steve Sanderson presented "AI Building Blocks - A new, unified AI layer" at this year's . The main points of the talk are as follows:

"Most .NET applications can be made more powerful and efficient with AI features such as semantic search, automatic categorization, summary generation, translation, data extraction, and even chat-based assistants. However, until now, there was no unified standard for representing AI concepts in .NET itself, so developers needed to use many unrelated APIs in combination. solves this problem by providing a new set of standard APIs for AI services, including Large Language Models (LLMs) running on local workstations or as hosted services, with integrated text embedding, vector storage, and more. In this talk, we will show how these new standard abstractions let you combine multiple services that can be easily replaced and changed over time, and how to access internal mechanisms in more advanced scenarios. With this presentation, you will be able to start experimenting with new AI features in your own applications."

youtube address:/watch?v=qcp6ufe_XYo&list=PLdo4fOcmZ0oXeSG8BgCVru3zQtw_K4ANY&index=3

Steve Sanderson described the following application scenarios:

image-20241120094958717

present (sb for a job etc)

On October 8, 2024, Luis Quintanilla posted an article titled "Introducing Preview - Unified AI Building Blocks for .NET" on the .NET Blog. NET Blog entitled "Introducing Preview - Unified AI Building Blocks for .

Article address:/dotnet/introducing-microsoft-extensions-ai-preview/

" is a set of core .NET libraries developed by developers in the .NET ecosystem, including the Semantic Kernel team. These libraries provide a unified C# abstraction layer for interacting with AI services such as small and large language models (SLM and LLM), embedded content, and middleware."

img

"Currently, our focus is on creating abstractions that can be implemented by a variety of services and all follow the same core concepts. We do not intend to release APIs for any specific service provider.Our goal is to act as a unifying layer in the .NET ecosystem, enabling developers to choose their preferred frameworks and libraries while ensuring seamless integration and collaboration across the ecosystem."

competitive edge

Provides a unified API abstraction for AI services, similar to our success with logging and dependency injection (DI) abstractions. Our goal is to provide standard implementations for caching, telemetry, tool calls, and other common tasks that are compatible with any provider.

The core strengths are the following:

Unified API: provides a consistent API 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 them adaptable to any provider.
Ease of Use: Enables .NET developers to try out different packages using the same underlying abstractions, maintaining a single API throughout the application.
Componentization: Simplifies the process of adding new features and facilitates componentization and testing of applications.

Simple Practice

Use can be seen in the introduction to the Nuget package.

Address:/packages//9.0.0-preview.9.24556.5

First, we will briefly take OpenAI as an example, and then, considering the inconvenience of using OpenAI in China, we will introduce how to access large language model providers compatible with the OpenAI format.

Simple conversation:

string OPENAI_API_KEY = "sk-sssss..." ;)

IChatClient client =
 new OpenAIClient(OPENAI_API_KEY); .AsChatClient(modelId: "gpt-4-o-mini")
.AsChatClient(modelId: "gpt-4o-mini");

var response = await ("Who are you?") ); var response = await ("Who are you?")

();

Effect:

image-20241120101114704

I'm more interested in the Function Calling feature to give it a brief try:

string OPENAI_API_KEY = "sk-sssss...";

[Description("Get the current time")]
 string GetCurrentTime() => ();

 IChatClient client = new ChatClientBuilder()
     .UseFunctionInvocation()
     .Use(new OpenAIClient(OPENAI_API_KEY).AsChatClient(modelId: "gpt-4o-mini"));

 var response = (
     "What time is it??",
     new() { Tools = [(GetCurrentTime)] });

 await foreach (var update in response)
 {
     (update);
 }

Effect:

image-20241120101404123

The current time was successfully obtained.

Since it is not convenient to use OpenAI in China, and there are also many big model providers in China that are compatible with OpenAI format, we will now take the domestic model providers as an example.

I'll use the silicon-based flow as an example with some credits on it.

Simple conversation:

 OpenAIClientOptions openAIClientOptions = new OpenAIClientOptions();
  = new Uri("/v1");

 // SiliconCloud API Key
 string mySiliconCloudAPIKey = "sk-lll...";


 OpenAIClient client = new OpenAIClient(new ApiKeyCredential(mySiliconCloudAPIKey), openAIClientOptions);
 IChatClient chatClient = ("Qwen/Qwen2.5-72B-Instruct-128K");
 var response = await ("Who are you??");
 ();

Effect:

image-20241120101803488

function call:

 OpenAIClientOptions openAIClientOptions = new OpenAIClientOptions();
  = new Uri("/v1");

 // SiliconCloud API Key
 string mySiliconCloudAPIKey = "sk-lll...";

  [Description("Get the current time")]
  string GetCurrentTime() => ();

  IChatClient client = new ChatClientBuilder()
      .UseFunctionInvocation()
      .Use(new OpenAIClient(new ApiKeyCredential(mySiliconCloudAPIKey), openAIClientOptions).AsChatClient("Qwen/Qwen2.5-72B-Instruct-128K"));

  var response = await (
      "What time is it??",
      new() { Tools = [(GetCurrentTime)] });

  (response);

image-20241120102258535

A successful function call was also made to get the current time.

Will find in fact and SemanticKernel is very similar, Steve Sanderson also confessed that these are from SemanticKernel "graduation" things, more use cases can be explored by the readers themselves.