Skip to content
Merged
110 changes: 1 addition & 109 deletions dotnet/samples/Concepts/Concepts.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
<ProjectReference Include="..\..\src\Functions\Functions.OpenApi\Functions.OpenApi.csproj" />
<ProjectReference Include="..\..\src\Functions\Functions.Prompty\Functions.Prompty.csproj" />
<ProjectReference Include="..\..\src\Planners\Planners.Handlebars\Planners.Handlebars.csproj" />
<!--ProjectReference Include="..\..\src\Planners\Planners.OpenAI\Planners.OpenAI.csproj" /-->
<ProjectReference Include="..\..\src\Planners\Planners.OpenAI\Planners.OpenAI.csproj" />
<ProjectReference Include="..\..\src\Plugins\Plugins.Core\Plugins.Core.csproj" />
<ProjectReference Include="..\..\src\Plugins\Plugins.Memory\Plugins.Memory.csproj" />
<ProjectReference Include="..\..\src\Plugins\Plugins.MsGraph\Plugins.MsGraph.csproj" />
Expand Down Expand Up @@ -120,8 +120,6 @@
<Compile Remove="Agents\OpenAIAssistant_FileManipulation.cs" />
<Compile Remove="Agents\OpenAIAssistant_FileService.cs" />
<Compile Remove="Agents\OpenAIAssistant_Retrieval.cs" />
<Compile Remove="AudioToText\OpenAI_AudioToText.cs" />
<Compile Remove="Caching\SemanticCachingWithFilters.cs" />
<Compile Remove="ChatCompletion\AzureOpenAIWithData_ChatCompletion.cs" />
<Compile Remove="ChatCompletion\ChatHistoryAuthorName.cs" />
<Compile Remove="ChatCompletion\ChatHistorySerialization.cs" />
Expand All @@ -145,58 +143,6 @@
<Compile Remove="ChatCompletion\OpenAI_ReasonedFunctionCalling.cs" />
<Compile Remove="ChatCompletion\OpenAI_RepeatedFunctionCalling.cs" />
<Compile Remove="ChatCompletion\OpenAI_UsingLogitBias.cs" />
<Compile Remove="ChatPrompts\SafeChatPrompts.cs" />
<Compile Remove="DependencyInjection\HttpClient_Registration.cs" />
<Compile Remove="DependencyInjection\HttpClient_Resiliency.cs" />
<Compile Remove="DependencyInjection\Kernel_Building.cs" />
<Compile Remove="DependencyInjection\Kernel_Injecting.cs" />
<Compile Remove="Filtering\AutoFunctionInvocationFiltering.cs" />
<Compile Remove="Filtering\FunctionInvocationFiltering.cs" />
<Compile Remove="Filtering\Legacy_KernelHooks.cs" />
<Compile Remove="Filtering\PIIDetection.cs" />
<Compile Remove="Filtering\PromptRenderFiltering.cs" />
<Compile Remove="Filtering\RetryWithFilters.cs" />
<Compile Remove="Filtering\TelemetryWithFilters.cs" />
<Compile Remove="FunctionCalling\Gemini_FunctionCalling.cs" />
<Compile Remove="FunctionCalling\OpenAI_FunctionCalling.cs" />
<Compile Remove="Functions\Arguments.cs" />
<Compile Remove="Functions\FunctionResult_Metadata.cs" />
<Compile Remove="Functions\FunctionResult_StronglyTyped.cs" />
<Compile Remove="Functions\MethodFunctions.cs" />
<Compile Remove="Functions\MethodFunctions_Advanced.cs" />
<Compile Remove="Functions\MethodFunctions_Types.cs" />
<Compile Remove="Functions\MethodFunctions_Yaml.cs" />
<Compile Remove="Functions\PromptFunctions_Inline.cs" />
<Compile Remove="Functions\PromptFunctions_MultipleArguments.cs" />
<Compile Remove="ImageToText\HuggingFace_ImageToText.cs" />
<Compile Remove="Kernel\BuildingKernel.cs" />
<Compile Remove="Kernel\ConfigureExecutionSettings.cs" />
<Compile Remove="Kernel\CustomAIServiceSelector.cs" />
<Compile Remove="LocalModels\HuggingFace_ChatCompletionWithTGI.cs" />
<Compile Remove="LocalModels\MultipleProviders_ChatCompletion.cs" />
<Compile Remove="Memory\HuggingFace_EmbeddingGeneration.cs" />
<Compile Remove="Memory\HuggingFace_TextEmbeddingCustomHttpHandler.cs" />
<Compile Remove="Memory\MemoryStore_CustomReadOnly.cs" />
<Compile Remove="Memory\SemanticTextMemory_Building.cs" />
<Compile Remove="Memory\TextChunkerUsage.cs" />
<Compile Remove="Memory\TextChunkingAndEmbedding.cs" />
<Compile Remove="Memory\TextMemoryPlugin_GeminiEmbeddingGeneration.cs" />
<Compile Remove="Memory\TextMemoryPlugin_MultipleMemoryStore.cs" />
<Compile Remove="Memory\TextMemoryPlugin_RecallJsonSerializationWithOptions.cs" />
<Compile Remove="Optimization\FrugalGPTWithFilters.cs" />
<Compile Remove="Optimization\PluginSelectionWithFilters.cs" />
<Compile Remove="Planners\FunctionCallStepwisePlanning.cs" />
<Compile Remove="Planners\HandlebarsPlanning.cs" />
<Compile Remove="Plugins\ApiManifestBasedPlugins.cs" />
<Compile Remove="Plugins\ConversationSummaryPlugin.cs" />
<Compile Remove="Plugins\CreatePluginFromOpenAI_AzureKeyVault.cs" />
<Compile Remove="Plugins\CreatePluginFromOpenApiSpec_Github.cs" />
<Compile Remove="Plugins\CreatePluginFromOpenApiSpec_Jira.cs" />
<Compile Remove="Plugins\CreatePluginFromOpenApiSpec_Klarna.cs" />
<Compile Remove="Plugins\CustomMutablePlugin.cs" />
<Compile Remove="Plugins\DescribeAllPluginsAndFunctions.cs" />
<Compile Remove="Plugins\GroundednessChecks.cs" />
<Compile Remove="Plugins\ImportPluginFromGrpc.cs" />
<Compile Remove="PromptTemplates\ChatCompletionPrompts.cs" />
<Compile Remove="PromptTemplates\ChatWithPrompts.cs" />
<Compile Remove="PromptTemplates\LiquidPrompts.cs" />
Expand Down Expand Up @@ -231,8 +177,6 @@
<None Include="Agents\OpenAIAssistant_FileManipulation.cs" />
<None Include="Agents\OpenAIAssistant_FileService.cs" />
<None Include="Agents\OpenAIAssistant_Retrieval.cs" />
<None Include="AudioToText\OpenAI_AudioToText.cs" />
<None Include="Caching\SemanticCachingWithFilters.cs" />
<None Include="ChatCompletion\AzureOpenAIWithData_ChatCompletion.cs" />
<None Include="ChatCompletion\ChatHistoryAuthorName.cs" />
<None Include="ChatCompletion\ChatHistorySerialization.cs" />
Expand All @@ -256,58 +200,6 @@
<None Include="ChatCompletion\OpenAI_ReasonedFunctionCalling.cs" />
<None Include="ChatCompletion\OpenAI_RepeatedFunctionCalling.cs" />
<None Include="ChatCompletion\OpenAI_UsingLogitBias.cs" />
<None Include="ChatPrompts\SafeChatPrompts.cs" />
<None Include="DependencyInjection\HttpClient_Registration.cs" />
<None Include="DependencyInjection\HttpClient_Resiliency.cs" />
<None Include="DependencyInjection\Kernel_Building.cs" />
<None Include="DependencyInjection\Kernel_Injecting.cs" />
<None Include="Filtering\AutoFunctionInvocationFiltering.cs" />
<None Include="Filtering\FunctionInvocationFiltering.cs" />
<None Include="Filtering\Legacy_KernelHooks.cs" />
<None Include="Filtering\PIIDetection.cs" />
<None Include="Filtering\PromptRenderFiltering.cs" />
<None Include="Filtering\RetryWithFilters.cs" />
<None Include="Filtering\TelemetryWithFilters.cs" />
<None Include="FunctionCalling\Gemini_FunctionCalling.cs" />
<None Include="FunctionCalling\OpenAI_FunctionCalling.cs" />
<None Include="Functions\Arguments.cs" />
<None Include="Functions\FunctionResult_Metadata.cs" />
<None Include="Functions\FunctionResult_StronglyTyped.cs" />
<None Include="Functions\MethodFunctions.cs" />
<None Include="Functions\MethodFunctions_Advanced.cs" />
<None Include="Functions\MethodFunctions_Types.cs" />
<None Include="Functions\MethodFunctions_Yaml.cs" />
<None Include="Functions\PromptFunctions_Inline.cs" />
<None Include="Functions\PromptFunctions_MultipleArguments.cs" />
<None Include="ImageToText\HuggingFace_ImageToText.cs" />
<None Include="Kernel\BuildingKernel.cs" />
<None Include="Kernel\ConfigureExecutionSettings.cs" />
<None Include="Kernel\CustomAIServiceSelector.cs" />
<None Include="LocalModels\HuggingFace_ChatCompletionWithTGI.cs" />
<None Include="LocalModels\MultipleProviders_ChatCompletion.cs" />
<None Include="Memory\HuggingFace_EmbeddingGeneration.cs" />
<None Include="Memory\HuggingFace_TextEmbeddingCustomHttpHandler.cs" />
<None Include="Memory\MemoryStore_CustomReadOnly.cs" />
<None Include="Memory\SemanticTextMemory_Building.cs" />
<None Include="Memory\TextChunkerUsage.cs" />
<None Include="Memory\TextChunkingAndEmbedding.cs" />
<None Include="Memory\TextMemoryPlugin_GeminiEmbeddingGeneration.cs" />
<None Include="Memory\TextMemoryPlugin_MultipleMemoryStore.cs" />
<None Include="Memory\TextMemoryPlugin_RecallJsonSerializationWithOptions.cs" />
<None Include="Optimization\FrugalGPTWithFilters.cs" />
<None Include="Optimization\PluginSelectionWithFilters.cs" />
<None Include="Planners\FunctionCallStepwisePlanning.cs" />
<None Include="Planners\HandlebarsPlanning.cs" />
<None Include="Plugins\ApiManifestBasedPlugins.cs" />
<None Include="Plugins\ConversationSummaryPlugin.cs" />
<None Include="Plugins\CreatePluginFromOpenAI_AzureKeyVault.cs" />
<None Include="Plugins\CreatePluginFromOpenApiSpec_Github.cs" />
<None Include="Plugins\CreatePluginFromOpenApiSpec_Jira.cs" />
<None Include="Plugins\CreatePluginFromOpenApiSpec_Klarna.cs" />
<None Include="Plugins\CustomMutablePlugin.cs" />
<None Include="Plugins\DescribeAllPluginsAndFunctions.cs" />
<None Include="Plugins\GroundednessChecks.cs" />
<None Include="Plugins\ImportPluginFromGrpc.cs" />
<None Include="PromptTemplates\ChatCompletionPrompts.cs" />
<None Include="PromptTemplates\ChatWithPrompts.cs" />
<None Include="PromptTemplates\LiquidPrompts.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Kernel>();

// Registering class that uses Kernel to execute a plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

using System.Diagnostics;
using System.Text.Json;
using Azure.AI.OpenAI;
using Microsoft.SemanticKernel;
using OpenAI.Chat;

namespace Functions;

Expand Down Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion dotnet/samples/Concepts/Memory/TextChunkingAndEmbedding.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
5 changes: 3 additions & 2 deletions dotnet/samples/LearnResources/LearnResources.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
<Import Project="$(RepoRoot)/dotnet/src/InternalUtilities/samples/SamplesInternalUtilities.props" />

<ItemGroup>
<ProjectReference Include="..\..\src\Connectors\Connectors.OpenAI\Connectors.OpenAI.csproj" />
<ProjectReference Include="..\..\src\Connectors\Connectors.AzureOpenAI\Connectors.AzureOpenAI.csproj" />
<ProjectReference Include="..\..\src\Connectors\Connectors.OpenAIV2\Connectors.OpenAIV2.csproj" />
<ProjectReference Include="..\..\src\Planners\Planners.Handlebars\Planners.Handlebars.csproj" />
<ProjectReference Include="..\..\src\Planners\Planners.OpenAI\Planners.OpenAI.csproj" />
<ProjectReference Include="..\..\src\SemanticKernel.Abstractions\SemanticKernel.Abstractions.csproj" />
Expand All @@ -68,6 +69,6 @@
</ItemGroup>
<ItemGroup>
<Using Include="Xunit" />
<Using Include="Xunit.Abstractions"/>
<Using Include="Xunit.Abstractions" />
</ItemGroup>
</Project>
14 changes: 0 additions & 14 deletions dotnet/samples/LearnResources/MicrosoftLearn/AIServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,11 @@ public async Task RunAsync()
.Build();
// </TypicalKernelCreation>

// You could instead create a kernel with a legacy Azure OpenAI text completion service
// <TextCompletionKernelCreation>
kernel = Kernel.CreateBuilder()
.AddAzureOpenAITextGeneration(textModelId, endpoint, apiKey)
.Build();
// </TextCompletionKernelCreation>

// You can also create a kernel with a (non-Azure) OpenAI chat completion service
// <OpenAIKernelCreation>
kernel = Kernel.CreateBuilder()
.AddOpenAIChatCompletion(openAImodelId, openAIapiKey)
.Build();
// </OpenAIKernelCreation>

// Or a kernel with a legacy OpenAI text completion service
// <OpenAITextCompletionKernelCreation>
kernel = Kernel.CreateBuilder()
.AddOpenAITextGeneration(openAItextModelId, openAIapiKey)
.Build();
// </OpenAITextCompletionKernelCreation>
}
}
Original file line number Diff line number Diff line change
@@ -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;

/// <summary>
/// Provides extension methods for the <see cref="MemoryBuilder"/> class to configure OpenAI connector.
/// </summary>
public static class OpenAIMemoryBuilderExtensions
{
/// <summary>
/// Adds the OpenAI text embeddings service.
/// See https://platform.openai.com/docs for service details.
/// </summary>
/// <param name="builder">The <see cref="MemoryBuilder"/> instance</param>
/// <param name="modelId">OpenAI model name, see https://platform.openai.com/docs/models</param>
/// <param name="apiKey">OpenAI API key, see https://platform.openai.com/account/api-keys</param>
/// <param name="orgId">OpenAI organization id. This is usually optional unless your account belongs to multiple organizations.</param>
/// <param name="httpClient">Custom <see cref="HttpClient"/> for HTTP requests.</param>
/// <param name="dimensions">The number of dimensions the resulting output embeddings should have. Only supported in "text-embedding-3" and later models.</param>
/// <returns>Self instance</returns>
[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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<FunctionCallingStepwisePlannerTests>()
.AddUserSecrets<OpenAIToolsTests>()
.Build();

/// <summary>
Expand Down
8 changes: 7 additions & 1 deletion dotnet/src/IntegrationTests/IntegrationTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
</ItemGroup>
<ItemGroup>
<Compile Remove="Planners\PlanTests.cs" />
<Compile Remove="Planners\Stepwise\FunctionCallingStepwisePlannerTests.cs" />
</ItemGroup>
<ItemGroup>
<None Remove="CrossLanguage\Data\LightBulbApi.json" />
Expand Down Expand Up @@ -75,8 +76,9 @@
<ProjectReference Include="..\Connectors\Connectors.Memory.SqlServer\Connectors.Memory.SqlServer.csproj" />
<ProjectReference Include="..\Connectors\Connectors.Memory.Weaviate\Connectors.Memory.Weaviate.csproj" />
<ProjectReference Include="..\Extensions\PromptTemplates.Handlebars\PromptTemplates.Handlebars.csproj" />
<ProjectReference Include="..\Functions\Functions.Yaml\Functions.Yaml.csproj" />
<ProjectReference Include="..\Planners\Planners.Handlebars\Planners.Handlebars.csproj" />
<ProjectReference Include="..\Planners\Planners.OpenAI\Planners.OpenAI.csproj" />
<!--ProjectReference Include="..\Planners\Planners.OpenAI\Planners.OpenAI.csproj" /-->
<ProjectReference Include="..\Plugins\Plugins.Core\Plugins.Core.csproj" />
<ProjectReference Include="..\Plugins\Plugins.Memory\Plugins.Memory.csproj" />
<ProjectReference Include="..\Functions\Functions.OpenApi\Functions.OpenApi.csproj" />
Expand Down Expand Up @@ -151,6 +153,10 @@
</Content>
</ItemGroup>

<ItemGroup>
<None Include="Planners\Stepwise\FunctionCallingStepwisePlannerTests.cs" />
</ItemGroup>

<ItemGroup>
<None Update="TestData\*">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/Planners/Planners.OpenAI/Planners.OpenAI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Connectors\Connectors.OpenAI\Connectors.OpenAI.csproj" />
<ProjectReference Include="..\..\Connectors\Connectors.OpenAIV2\Connectors.OpenAIV2.csproj" />
<ProjectReference Include="..\..\Functions\Functions.Yaml\Functions.Yaml.csproj" />
<ProjectReference Include="..\..\SemanticKernel.Core\SemanticKernel.Core.csproj" />
</ItemGroup>
Expand Down