Skip to content

Commit

Permalink
.Net: planner tests openai (#4318)
Browse files Browse the repository at this point in the history
- Changing function calling integration tests to use OpenAI gpt-4 until
issues with OAI function calling are resolved.
- Added description to some kernel functions using in tests to improve
stability of function calling.

<!-- Before submitting this PR, please make sure: -->

- [ ] The code builds clean without any errors or warnings
- [ ] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [ ] All unit tests pass, and I have added new tests where possible
- [ ] I didn't break anyone 😄

---------

Co-authored-by: Ben Thomas <[email protected]>
  • Loading branch information
alliscode and Ben Thomas authored Dec 15, 2023
1 parent 425fcdf commit 65e20a6
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/dotnet-build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ jobs:
Planners__AzureOpenAI__ApiKey: ${{ secrets.PLANNERS__AZUREOPENAI__APIKEY }}
Planners__AzureOpenAI__Endpoint: ${{ secrets.PLANNERS__AZUREOPENAI__ENDPOINT }}
Planners__AzureOpenAI__DeploymentName: ${{ vars.PLANNERS__AZUREOPENAI__DEPLOYMENTNAME }}
Planners__OpenAI__ApiKey: ${{ secrets.PLANNERS__OPENAI__APIKEY }}
Planners__OpenAI__ModelId: ${{ vars.PLANNERS__OPENAI__MODELID }}
Bing__ApiKey: ${{ secrets.BING__APIKEY }}
OpenAI__ApiKey: ${{ secrets.OPENAI__APIKEY }}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static async Task RunAsync()
// Add a plugin with some helper functions we want to allow the model to utilize.
kernel.Plugins.Add(KernelPluginFactory.CreateFromFunctions("HelperFunctions", new[]
{
kernel.CreateFunctionFromMethod(() => DateTime.UtcNow.ToString("R"), "GetCurrentUtcTime"),
kernel.CreateFunctionFromMethod(() => DateTime.UtcNow.ToString("R"), "GetCurrentUtcTime", "Retrieves the current time in UTC."),
kernel.CreateFunctionFromMethod((string cityName) =>
cityName switch
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.

using System;
using System.ComponentModel;
using System.Threading.Tasks;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Connectors.OpenAI;
Expand Down Expand Up @@ -38,6 +39,7 @@ public static async Task RunAsync()
public class TimeInformation
{
[KernelFunction]
[Description("Retrieves the current time in UTC.")]
public string GetCurrentUtcTime() => DateTime.UtcNow.ToString("R");
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.

using System;
using System.ComponentModel;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -56,6 +57,7 @@ public TimeInformation(ILoggerFactory loggerFactory)
}

[KernelFunction]
[Description("Retrieves the current time in UTC.")]
public string GetCurrentUtcTime()
{
var utcNow = DateTime.UtcNow.ToString("R");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.

using System;
using System.ComponentModel;
using System.Threading.Tasks;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Connectors.OpenAI;
Expand Down Expand Up @@ -58,6 +59,7 @@ void MyInvokedHandler(object? sender, FunctionInvokedEventArgs e)
public class TimeInformation
{
[KernelFunction]
[Description("Retrieves the current time in UTC.")]
public string GetCurrentUtcTime() => DateTime.UtcNow.ToString("R");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using Microsoft.SemanticKernel;
Expand Down Expand Up @@ -53,14 +54,13 @@ void MyInvokingHandler(object? sender, FunctionInvokingEventArgs e)

private Kernel InitializeKernel()
{
AzureOpenAIConfiguration? azureOpenAIConfiguration = this._configuration.GetSection("Planners:AzureOpenAI").Get<AzureOpenAIConfiguration>();
Assert.NotNull(azureOpenAIConfiguration);
OpenAIConfiguration? openAIConfiguration = this._configuration.GetSection("Planners:OpenAI").Get<OpenAIConfiguration>();
Assert.NotNull(openAIConfiguration);

IKernelBuilder builder = Kernel.CreateBuilder()
.AddAzureOpenAIChatCompletion(
deploymentName: azureOpenAIConfiguration.ChatDeploymentName!,
endpoint: azureOpenAIConfiguration.Endpoint,
apiKey: azureOpenAIConfiguration.ApiKey);
.AddOpenAIChatCompletion(
modelId: openAIConfiguration.ModelId,
apiKey: openAIConfiguration.ApiKey);

var kernel = builder.Build();

Expand Down Expand Up @@ -95,6 +95,7 @@ private void Dispose(bool disposing)
public class TimeInformation
{
[KernelFunction]
[Description("Retrieves the current time in UTC.")]
public string GetCurrentUtcTime() => DateTime.UtcNow.ToString("R");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,13 @@ public async Task CanExecuteStepwisePlanAsync(string prompt, string[] expectedFu

private Kernel InitializeKernel()
{
AzureOpenAIConfiguration? azureOpenAIConfiguration = this._configuration.GetSection("Planners:AzureOpenAI").Get<AzureOpenAIConfiguration>();
Assert.NotNull(azureOpenAIConfiguration);
OpenAIConfiguration? openAIConfiguration = this._configuration.GetSection("Planners:OpenAI").Get<OpenAIConfiguration>();
Assert.NotNull(openAIConfiguration);

IKernelBuilder builder = Kernel.CreateBuilder()
.AddAzureOpenAIChatCompletion(
deploymentName: azureOpenAIConfiguration.ChatDeploymentName!,
endpoint: azureOpenAIConfiguration.Endpoint,
apiKey: azureOpenAIConfiguration.ApiKey);
.AddOpenAIChatCompletion(
modelId: openAIConfiguration.ModelId,
apiKey: openAIConfiguration.ApiKey);

var kernel = builder.Build();

Expand Down
4 changes: 2 additions & 2 deletions dotnet/src/IntegrationTests/testsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
"ApiKey": ""
},
"OpenAI": {
"ServiceId": "text-davinci-003",
"ModelId": "text-davinci-003",
"ServiceId": "openai-gpt-4",
"ModelId": "gpt-4",
"ApiKey": ""
}
}
Expand Down

0 comments on commit 65e20a6

Please sign in to comment.