Skip to content

Commit

Permalink
Feature serviceregistry (microsoft#993)
Browse files Browse the repository at this point in the history
### Motivation, Context and Description

This PR introduces several changes aimed to simplify the kernel and
enhancing its extensibility for AI services management. The changes
include the following:

1. Kernel simplification and extensibility: The code responsible for AI
services management, such as registration and resolution, has been moved
out of the Kernel and KernelConfig classes into a new class called
AIServiceProvider. This restructuring promotes the principle of Single
Responsibility, ensuring that each class has a clear and focused
purpose.

2. Hosting apps customization: With the introduction of the
AIServiceProvider, hosting applications now have the flexibility to
provide their own implementation of the provider if needed. This
promotes extensibility, allowing the hosting apps to tailor the AI
service management according to their specific requirements.

3. AI services registration improvements: A new method called
WithAiService has been added, which enables the registration of any new
AI service that is not currently supported.

4. Improved kernel builder interface: The Add* methods for AI services
registration have been moved from the KernelConfig class to the
KernelBuilder. This change aligns the interface with other KernelBilder
methods, such as WithLogger and WithMemory, creating a more cohesive and
intuitive kernel builder interface.

---------

Co-authored-by: Shawn Callegari <36091529+shawncal@users.noreply.github.com>
Co-authored-by: Lee Miller <lemiller@microsoft.com>
  • Loading branch information
3 people committed May 22, 2023
1 parent c0ab238 commit af03e00
Show file tree
Hide file tree
Showing 86 changed files with 2,453 additions and 460 deletions.
1 change: 0 additions & 1 deletion dotnet/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<!-- using Central Package Management feature -->
<!-- https://learn.microsoft.com/en-us/nuget/consume-packages/Central-Package-Management -->
<Sdk Name="Microsoft.Build.CentralPackageVersions" Version="2.1.3" />

<!-- Only run 'dotnet format' on dev machines, Release builds. Skip on GitHub Actions -->
<!-- as this runs in its own Actions job. -->
<Target Name="DotnetFormatOnBuild" BeforeTargets="Build"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Microsoft.SemanticKernel.Connectors.AI.HuggingFace.TextEmbedding;
/// <summary>
/// HuggingFace embedding generation service.
/// </summary>
public sealed class HuggingFaceTextEmbeddingGeneration : IEmbeddingGeneration<string, float>, IDisposable
public sealed class HuggingFaceTextEmbeddingGeneration : ITextEmbeddingGeneration, IDisposable
{
private const string HttpUserAgent = "Microsoft Semantic Kernel";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<!-- THIS PROPERTY GROUP MUST COME FIRST -->
Expand All @@ -20,7 +20,7 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\SemanticKernel.Abstractions\SemanticKernel.Abstractions.csproj" />
<ProjectReference Include="..\..\SemanticKernel\SemanticKernel.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) Microsoft. All rights reserved.

using System;
using System.Net.Http;
using Azure.Core;
using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -34,6 +35,7 @@ public static class KernelConfigOpenAIExtensions
/// <param name="httpClient">Custom <see cref="HttpClient"/> for HTTP requests.</param>
/// <param name="logger">Application logger</param>
/// <returns>Self instance</returns>
[Obsolete("This method is deprecated and will be removed in one of the next SK SDK versions. Please use the corresponding extension method in the KernelBuilder class instead.")]
public static KernelConfig AddAzureTextCompletionService(this KernelConfig config,
string deploymentName,
string endpoint,
Expand Down Expand Up @@ -66,6 +68,7 @@ public static KernelConfig AddAzureTextCompletionService(this KernelConfig confi
/// <param name="httpClient">Custom <see cref="HttpClient"/> for HTTP requests.</param>
/// <param name="logger">Application logger</param>
/// <returns>Self instance</returns>
[Obsolete("This method is deprecated and will be removed in one of the next SK SDK versions. Please use the corresponding extension method in the KernelBuilder class instead.")]
public static KernelConfig AddAzureTextCompletionService(this KernelConfig config,
string deploymentName,
string endpoint,
Expand Down Expand Up @@ -98,6 +101,7 @@ public static KernelConfig AddAzureTextCompletionService(this KernelConfig confi
/// <param name="httpClient">Custom <see cref="HttpClient"/> for HTTP requests.</param>
/// <param name="logger">Application logger</param>
/// <returns>Self instance</returns>
[Obsolete("This method is deprecated and will be removed in one of the next SK SDK versions. Please use the corresponding extension method in the KernelBuilder class instead.")]
public static KernelConfig AddOpenAITextCompletionService(this KernelConfig config,
string modelId,
string apiKey,
Expand Down Expand Up @@ -134,6 +138,7 @@ public static KernelConfig AddOpenAITextCompletionService(this KernelConfig conf
/// <param name="httpClient">Custom <see cref="HttpClient"/> for HTTP requests.</param>
/// <param name="logger">Application logger</param>
/// <returns>Self instance</returns>
[Obsolete("This method is deprecated and will be removed in one of the next SK SDK versions. Please use the corresponding extension method in the KernelBuilder class instead.")]
public static KernelConfig AddAzureTextEmbeddingGenerationService(this KernelConfig config,
string deploymentName,
string endpoint,
Expand Down Expand Up @@ -166,6 +171,7 @@ public static KernelConfig AddAzureTextEmbeddingGenerationService(this KernelCon
/// <param name="httpClient">Custom <see cref="HttpClient"/> for HTTP requests.</param>
/// <param name="logger">Application logger</param>
/// <returns>Self instance</returns>
[Obsolete("This method is deprecated and will be removed in one of the next SK SDK versions. Please use the corresponding extension method in the KernelBuilder class instead.")]
public static KernelConfig AddAzureTextEmbeddingGenerationService(this KernelConfig config,
string deploymentName,
string endpoint,
Expand Down Expand Up @@ -198,6 +204,7 @@ public static KernelConfig AddAzureTextEmbeddingGenerationService(this KernelCon
/// <param name="httpClient">Custom <see cref="HttpClient"/> for HTTP requests.</param>
/// <param name="logger">Application logger</param>
/// <returns>Self instance</returns>
[Obsolete("This method is deprecated and will be removed in one of the next SK SDK versions. Please use the corresponding extension method in the KernelBuilder class instead.")]
public static KernelConfig AddOpenAITextEmbeddingGenerationService(this KernelConfig config,
string modelId,
string apiKey,
Expand Down Expand Up @@ -235,6 +242,7 @@ public static KernelConfig AddOpenAITextEmbeddingGenerationService(this KernelCo
/// <param name="httpClient">Custom <see cref="HttpClient"/> for HTTP requests.</param>
/// <param name="logger">Application logger</param>
/// <returns>Self instance</returns>
[Obsolete("This method is deprecated and will be removed in one of the next SK SDK versions. Please use the corresponding extension method in the KernelBuilder class instead.")]
public static KernelConfig AddAzureChatCompletionService(this KernelConfig config,
string deploymentName,
string endpoint,
Expand Down Expand Up @@ -278,6 +286,7 @@ public static KernelConfig AddAzureChatCompletionService(this KernelConfig confi
/// <param name="httpClient">Custom <see cref="HttpClient"/> for HTTP requests.</param>
/// <param name="logger">Application logger</param>
/// <returns>Self instance</returns>
[Obsolete("This method is deprecated and will be removed in one of the next SK SDK versions. Please use the corresponding extension method in the KernelBuilder class instead.")]
public static KernelConfig AddAzureChatCompletionService(this KernelConfig config,
string deploymentName,
string endpoint,
Expand Down Expand Up @@ -325,6 +334,7 @@ public static KernelConfig AddAzureChatCompletionService(this KernelConfig confi
/// <param name="httpClient">Custom <see cref="HttpClient"/> for HTTP requests.</param>
/// <param name="logger">Application logger</param>
/// <returns>Self instance</returns>
[Obsolete("This method is deprecated and will be removed in one of the next SK SDK versions. Please use the corresponding extension method in the KernelBuilder class instead.")]
public static KernelConfig AddOpenAIChatCompletionService(this KernelConfig config,
string modelId,
string apiKey,
Expand Down Expand Up @@ -373,6 +383,7 @@ public static KernelConfig AddOpenAIChatCompletionService(this KernelConfig conf
/// <param name="httpClient">Custom <see cref="HttpClient"/> for HTTP requests.</param>
/// <param name="logger">Application logger</param>
/// <returns>Self instance</returns>
[Obsolete("This method is deprecated and will be removed in one of the next SK SDK versions. Please use the corresponding extension method in the KernelBuilder class instead.")]
public static KernelConfig AddOpenAIImageGenerationService(this KernelConfig config,
string apiKey,
string? orgId = null,
Expand Down
Loading

0 comments on commit af03e00

Please sign in to comment.