diff --git a/dotnet/samples/Concepts/Concepts.csproj b/dotnet/samples/Concepts/Concepts.csproj index 63dabdd45eb6..a11241024bf9 100644 --- a/dotnet/samples/Concepts/Concepts.csproj +++ b/dotnet/samples/Concepts/Concepts.csproj @@ -73,7 +73,7 @@ - + @@ -120,8 +120,6 @@ - - @@ -145,58 +143,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -231,8 +177,6 @@ - - @@ -256,58 +200,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/dotnet/samples/Concepts/DependencyInjection/Kernel_Injecting.cs b/dotnet/samples/Concepts/DependencyInjection/Kernel_Injecting.cs index 4c6e38452fc6..21abae070cf0 100644 --- a/dotnet/samples/Concepts/DependencyInjection/Kernel_Injecting.cs +++ b/dotnet/samples/Concepts/DependencyInjection/Kernel_Injecting.cs @@ -14,7 +14,7 @@ public async Task RunAsync() { ServiceCollection collection = new(); collection.AddLogging(c => c.AddConsole().SetMinimumLevel(LogLevel.Information)); - collection.AddOpenAITextGeneration(TestConfiguration.OpenAI.ModelId, TestConfiguration.OpenAI.ApiKey); + collection.AddOpenAIChatCompletion(TestConfiguration.OpenAI.ChatModelId, TestConfiguration.OpenAI.ApiKey); collection.AddSingleton(); // Registering class that uses Kernel to execute a plugin diff --git a/dotnet/samples/Concepts/Functions/FunctionResult_StronglyTyped.cs b/dotnet/samples/Concepts/Functions/FunctionResult_StronglyTyped.cs index 0b50562583ea..79826de22bec 100644 --- a/dotnet/samples/Concepts/Functions/FunctionResult_StronglyTyped.cs +++ b/dotnet/samples/Concepts/Functions/FunctionResult_StronglyTyped.cs @@ -2,8 +2,8 @@ using System.Diagnostics; using System.Text.Json; -using Azure.AI.OpenAI; using Microsoft.SemanticKernel; +using OpenAI.Chat; namespace Functions; @@ -79,11 +79,11 @@ public FunctionResultTestDataGen(FunctionResult functionResult, long executionTi private TokenCounts? ParseTokenCounts() { - CompletionsUsage? usage = FunctionResult.Metadata?["Usage"] as CompletionsUsage; + var usage = FunctionResult.Metadata?["Usage"] as ChatTokenUsage; return new TokenCounts( - completionTokens: usage?.CompletionTokens ?? 0, - promptTokens: usage?.PromptTokens ?? 0, + completionTokens: usage?.OutputTokens ?? 0, + promptTokens: usage?.InputTokens ?? 0, totalTokens: usage?.TotalTokens ?? 0); } diff --git a/dotnet/samples/Concepts/Memory/TextChunkingAndEmbedding.cs b/dotnet/samples/Concepts/Memory/TextChunkingAndEmbedding.cs index 013bb4961621..96b3cb9431db 100644 --- a/dotnet/samples/Concepts/Memory/TextChunkingAndEmbedding.cs +++ b/dotnet/samples/Concepts/Memory/TextChunkingAndEmbedding.cs @@ -1,7 +1,7 @@ // Copyright (c) Microsoft. All rights reserved. using Microsoft.ML.Tokenizers; -using Microsoft.SemanticKernel.Connectors.OpenAI; +using Microsoft.SemanticKernel.Connectors.AzureOpenAI; using Microsoft.SemanticKernel.Text; namespace Memory; diff --git a/dotnet/samples/Concepts/Memory/TextMemoryPlugin_RecallJsonSerializationWithOptions.cs b/dotnet/samples/Concepts/Memory/TextMemoryPlugin_RecallJsonSerializationWithOptions.cs index fbc313adebf4..883195b68df9 100644 --- a/dotnet/samples/Concepts/Memory/TextMemoryPlugin_RecallJsonSerializationWithOptions.cs +++ b/dotnet/samples/Concepts/Memory/TextMemoryPlugin_RecallJsonSerializationWithOptions.cs @@ -4,7 +4,7 @@ using System.Text.Json; using System.Text.Unicode; using Microsoft.SemanticKernel; -using Microsoft.SemanticKernel.Connectors.OpenAI; +using Microsoft.SemanticKernel.Connectors.AzureOpenAI; using Microsoft.SemanticKernel.Memory; using Microsoft.SemanticKernel.Plugins.Memory; diff --git a/dotnet/samples/LearnResources/LearnResources.csproj b/dotnet/samples/LearnResources/LearnResources.csproj index d210f8effa91..72cff80ad017 100644 --- a/dotnet/samples/LearnResources/LearnResources.csproj +++ b/dotnet/samples/LearnResources/LearnResources.csproj @@ -51,7 +51,8 @@ - + + @@ -68,6 +69,6 @@ - + \ No newline at end of file diff --git a/dotnet/samples/LearnResources/MicrosoftLearn/AIServices.cs b/dotnet/samples/LearnResources/MicrosoftLearn/AIServices.cs index a56e6591f8ad..d957358cac77 100644 --- a/dotnet/samples/LearnResources/MicrosoftLearn/AIServices.cs +++ b/dotnet/samples/LearnResources/MicrosoftLearn/AIServices.cs @@ -45,25 +45,11 @@ public async Task RunAsync() .Build(); // - // You could instead create a kernel with a legacy Azure OpenAI text completion service - // - kernel = Kernel.CreateBuilder() - .AddAzureOpenAITextGeneration(textModelId, endpoint, apiKey) - .Build(); - // - // You can also create a kernel with a (non-Azure) OpenAI chat completion service // kernel = Kernel.CreateBuilder() .AddOpenAIChatCompletion(openAImodelId, openAIapiKey) .Build(); // - - // Or a kernel with a legacy OpenAI text completion service - // - kernel = Kernel.CreateBuilder() - .AddOpenAITextGeneration(openAItextModelId, openAIapiKey) - .Build(); - // } } diff --git a/dotnet/src/Connectors/Connectors.OpenAIV2/Extensions/OpenAIMemoryBuilderExtensions.cs b/dotnet/src/Connectors/Connectors.OpenAIV2/Extensions/OpenAIMemoryBuilderExtensions.cs new file mode 100644 index 000000000000..0ac425a15593 --- /dev/null +++ b/dotnet/src/Connectors/Connectors.OpenAIV2/Extensions/OpenAIMemoryBuilderExtensions.cs @@ -0,0 +1,44 @@ +// Copyright (c) Microsoft. All rights reserved. + +using System.Diagnostics.CodeAnalysis; +using System.Net.Http; +using Microsoft.SemanticKernel.Http; +using Microsoft.SemanticKernel.Memory; + +namespace Microsoft.SemanticKernel.Connectors.OpenAI; + +/// +/// Provides extension methods for the class to configure OpenAI connector. +/// +public static class OpenAIMemoryBuilderExtensions +{ + /// + /// Adds the OpenAI text embeddings service. + /// See https://platform.openai.com/docs for service details. + /// + /// The instance + /// OpenAI model name, see https://platform.openai.com/docs/models + /// OpenAI API key, see https://platform.openai.com/account/api-keys + /// OpenAI organization id. This is usually optional unless your account belongs to multiple organizations. + /// Custom for HTTP requests. + /// The number of dimensions the resulting output embeddings should have. Only supported in "text-embedding-3" and later models. + /// Self instance + [Experimental("SKEXP0010")] + public static MemoryBuilder WithOpenAITextEmbeddingGeneration( + this MemoryBuilder builder, + string modelId, + string apiKey, + string? orgId = null, + HttpClient? httpClient = null, + int? dimensions = null) + { + return builder.WithTextEmbeddingGeneration((loggerFactory, builderHttpClient) => + new OpenAITextEmbeddingGenerationService( + modelId, + apiKey, + orgId, + HttpClientProvider.GetHttpClient(httpClient ?? builderHttpClient), + loggerFactory, + dimensions)); + } +} diff --git a/dotnet/src/IntegrationTests/Connectors/OpenAI/OpenAIToolsTests.cs b/dotnet/src/IntegrationTests/Connectors/OpenAI/OpenAIToolsTests.cs index 049287fbbc14..243526fdfc82 100644 --- a/dotnet/src/IntegrationTests/Connectors/OpenAI/OpenAIToolsTests.cs +++ b/dotnet/src/IntegrationTests/Connectors/OpenAI/OpenAIToolsTests.cs @@ -13,7 +13,6 @@ using Microsoft.SemanticKernel; using Microsoft.SemanticKernel.ChatCompletion; using Microsoft.SemanticKernel.Connectors.OpenAI; -using SemanticKernel.IntegrationTests.Planners.Stepwise; using SemanticKernel.IntegrationTests.TestSettings; using Xunit; @@ -740,7 +739,7 @@ private Kernel InitializeKernel(bool importHelperPlugin = false) .AddJsonFile(path: "testsettings.json", optional: false, reloadOnChange: true) .AddJsonFile(path: "testsettings.development.json", optional: true, reloadOnChange: true) .AddEnvironmentVariables() - .AddUserSecrets() + .AddUserSecrets() .Build(); /// diff --git a/dotnet/src/IntegrationTests/IntegrationTests.csproj b/dotnet/src/IntegrationTests/IntegrationTests.csproj index df5afa473ce7..6d741d390c2e 100644 --- a/dotnet/src/IntegrationTests/IntegrationTests.csproj +++ b/dotnet/src/IntegrationTests/IntegrationTests.csproj @@ -18,6 +18,7 @@ + @@ -75,8 +76,9 @@ + - + @@ -151,6 +153,10 @@ + + + + Always diff --git a/dotnet/src/Planners/Planners.OpenAI/Planners.OpenAI.csproj b/dotnet/src/Planners/Planners.OpenAI/Planners.OpenAI.csproj index 194753a700ad..d6f5f1bb08e1 100644 --- a/dotnet/src/Planners/Planners.OpenAI/Planners.OpenAI.csproj +++ b/dotnet/src/Planners/Planners.OpenAI/Planners.OpenAI.csproj @@ -32,7 +32,7 @@ - +