chore: import upstream snapshot with attribution
This commit is contained in:
+86
@@ -0,0 +1,86 @@
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
#pragma warning disable IDE0005 // Using directive is unnecessary
|
||||
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.SemanticKernel;
|
||||
using Microsoft.SemanticKernel.ChatCompletion;
|
||||
using Microsoft.SemanticKernel.Connectors.OpenAI;
|
||||
using StepwisePlannerMigration.Models;
|
||||
using StepwisePlannerMigration.Plugins;
|
||||
using StepwisePlannerMigration.Services;
|
||||
|
||||
#pragma warning restore IDE0005 // Using directive is unnecessary
|
||||
|
||||
namespace StepwisePlannerMigration.Controllers;
|
||||
|
||||
/// <summary>
|
||||
/// This controller shows a new recommended approach how to use planning capability by using Auto Function Calling.
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[Route("auto-function-calling")]
|
||||
public class AutoFunctionCallingController : ControllerBase
|
||||
{
|
||||
private readonly Kernel _kernel;
|
||||
private readonly IChatCompletionService _chatCompletionService;
|
||||
private readonly IPlanProvider _planProvider;
|
||||
|
||||
public AutoFunctionCallingController(
|
||||
Kernel kernel,
|
||||
IChatCompletionService chatCompletionService,
|
||||
IPlanProvider planProvider)
|
||||
{
|
||||
this._kernel = kernel;
|
||||
this._chatCompletionService = chatCompletionService;
|
||||
this._planProvider = planProvider;
|
||||
|
||||
this._kernel.ImportPluginFromType<TimePlugin>();
|
||||
this._kernel.ImportPluginFromType<WeatherPlugin>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Action to generate a plan. Generated plan will be populated in <see cref="ChatHistory"/> object.
|
||||
/// </summary>
|
||||
[HttpPost, Route("generate-plan")]
|
||||
public async Task<IActionResult> GeneratePlanAsync(PlanRequest request)
|
||||
{
|
||||
ChatHistory chatHistory = [];
|
||||
chatHistory.AddUserMessage(request.Goal);
|
||||
|
||||
OpenAIPromptExecutionSettings executionSettings = new() { FunctionChoiceBehavior = FunctionChoiceBehavior.Auto() };
|
||||
|
||||
await this._chatCompletionService.GetChatMessageContentAsync(chatHistory, executionSettings, this._kernel);
|
||||
|
||||
return this.Ok(chatHistory);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Action to execute a new plan. When generated plan is not needed,
|
||||
/// planning result can be obtained directly with <see cref="Kernel"/> object.
|
||||
/// </summary>
|
||||
[HttpPost, Route("execute-new-plan")]
|
||||
public async Task<IActionResult> ExecuteNewPlanAsync(PlanRequest request)
|
||||
{
|
||||
OpenAIPromptExecutionSettings executionSettings = new() { FunctionChoiceBehavior = FunctionChoiceBehavior.Auto() };
|
||||
|
||||
FunctionResult result = await this._kernel.InvokePromptAsync(request.Goal, new(executionSettings));
|
||||
|
||||
return this.Ok(result.ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Action to execute existing plan. Generated plans can be stored in permanent storage for reusability.
|
||||
/// In this demo application it is stored in file.
|
||||
/// </summary>
|
||||
[HttpPost, Route("execute-existing-plan")]
|
||||
public async Task<IActionResult> ExecuteExistingPlanAsync()
|
||||
{
|
||||
ChatHistory chatHistory = this._planProvider.GetPlan("auto-function-calling-plan.json");
|
||||
OpenAIPromptExecutionSettings executionSettings = new() { FunctionChoiceBehavior = FunctionChoiceBehavior.Auto() };
|
||||
|
||||
ChatMessageContent result = await this._chatCompletionService.GetChatMessageContentAsync(chatHistory, executionSettings, this._kernel);
|
||||
|
||||
return this.Ok(result.Content);
|
||||
}
|
||||
}
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
#pragma warning disable IDE0005 // Using directive is unnecessary
|
||||
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.SemanticKernel;
|
||||
using Microsoft.SemanticKernel.ChatCompletion;
|
||||
using Microsoft.SemanticKernel.Planning;
|
||||
using StepwisePlannerMigration.Models;
|
||||
using StepwisePlannerMigration.Plugins;
|
||||
using StepwisePlannerMigration.Services;
|
||||
|
||||
#pragma warning restore IDE0005 // Using directive is unnecessary
|
||||
|
||||
namespace StepwisePlannerMigration.Controllers;
|
||||
|
||||
/// <summary>
|
||||
/// This controller shows the old way how to use planning capability by using FunctionCallingStepwisePlanner.
|
||||
/// A new recommended approach is demonstrated in <see cref="AutoFunctionCallingController"/>.
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[Route("stepwise-planner")]
|
||||
public class StepwisePlannerController : ControllerBase
|
||||
{
|
||||
private readonly Kernel _kernel;
|
||||
private readonly FunctionCallingStepwisePlanner _planner;
|
||||
private readonly IPlanProvider _planProvider;
|
||||
|
||||
public StepwisePlannerController(
|
||||
Kernel kernel,
|
||||
FunctionCallingStepwisePlanner planner,
|
||||
IPlanProvider planProvider)
|
||||
{
|
||||
this._kernel = kernel;
|
||||
this._planner = planner;
|
||||
this._planProvider = planProvider;
|
||||
|
||||
this._kernel.ImportPluginFromType<TimePlugin>();
|
||||
this._kernel.ImportPluginFromType<WeatherPlugin>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Action to generate a plan. Generated plan will be populated in <see cref="ChatHistory"/> object.
|
||||
/// </summary>
|
||||
[HttpPost, Route("generate-plan")]
|
||||
public async Task<IActionResult> GeneratePlanAsync(PlanRequest request)
|
||||
{
|
||||
FunctionCallingStepwisePlannerResult result = await this._planner.ExecuteAsync(this._kernel, request.Goal);
|
||||
|
||||
return this.Ok(result.ChatHistory);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Action to execute a new plan.
|
||||
/// </summary>
|
||||
[HttpPost, Route("execute-new-plan")]
|
||||
public async Task<IActionResult> ExecuteNewPlanAsync(PlanRequest request)
|
||||
{
|
||||
FunctionCallingStepwisePlannerResult result = await this._planner.ExecuteAsync(this._kernel, request.Goal);
|
||||
|
||||
return this.Ok(result.FinalAnswer);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Action to execute existing plan. Generated plans can be stored in permanent storage for reusability.
|
||||
/// In this demo application it is stored in file.
|
||||
/// </summary>
|
||||
[HttpPost, Route("execute-existing-plan")]
|
||||
public async Task<IActionResult> ExecuteExistingPlanAsync(PlanRequest request)
|
||||
{
|
||||
ChatHistory chatHistory = this._planProvider.GetPlan("stepwise-plan.json");
|
||||
FunctionCallingStepwisePlannerResult result = await this._planner.ExecuteAsync(this._kernel, request.Goal, chatHistory);
|
||||
|
||||
return this.Ok(result.FinalAnswer);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace StepwisePlannerMigration.Extensions;
|
||||
|
||||
/// <summary>
|
||||
/// Class with extension methods for app configuration.
|
||||
/// </summary>
|
||||
public static class ConfigurationExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns <typeparamref name="TOptions"/> if it's valid or throws <see cref="ValidationException"/>.
|
||||
/// </summary>
|
||||
public static TOptions GetValid<TOptions>(this IConfigurationRoot configurationRoot, string sectionName)
|
||||
{
|
||||
var options = configurationRoot.GetSection(sectionName).Get<TOptions>()!;
|
||||
|
||||
Validator.ValidateObject(options, new(options));
|
||||
|
||||
return options;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
namespace StepwisePlannerMigration.Models;
|
||||
|
||||
/// <summary>
|
||||
/// Request model for planning endpoints.
|
||||
/// </summary>
|
||||
public class PlanRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// A goal which should be achieved after plan execution.
|
||||
/// </summary>
|
||||
public string Goal { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace StepwisePlannerMigration.Options;
|
||||
|
||||
/// <summary>
|
||||
/// Configuration for OpenAI chat completion service.
|
||||
/// </summary>
|
||||
public class OpenAIOptions
|
||||
{
|
||||
public const string SectionName = "OpenAI";
|
||||
|
||||
[Required]
|
||||
public string ChatModelId { get; set; }
|
||||
|
||||
[Required]
|
||||
public string ApiKey { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
#pragma warning disable IDE0005 // Using directive is unnecessary
|
||||
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using Microsoft.SemanticKernel;
|
||||
|
||||
#pragma warning restore IDE0005 // Using directive is unnecessary
|
||||
|
||||
namespace StepwisePlannerMigration.Plugins;
|
||||
|
||||
/// <summary>
|
||||
/// Sample plugin which provides time information.
|
||||
/// </summary>
|
||||
public sealed class TimePlugin
|
||||
{
|
||||
[KernelFunction]
|
||||
[Description("Retrieves the current time in UTC")]
|
||||
public string GetCurrentUtcTime() => DateTime.UtcNow.ToString("R");
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
#pragma warning disable IDE0005 // Using directive is unnecessary
|
||||
|
||||
using System.ComponentModel;
|
||||
using Microsoft.SemanticKernel;
|
||||
|
||||
#pragma warning restore IDE0005 // Using directive is unnecessary
|
||||
|
||||
namespace StepwisePlannerMigration.Plugins;
|
||||
|
||||
/// <summary>
|
||||
/// Sample plugin which provides fake weather information.
|
||||
/// </summary>
|
||||
public sealed class WeatherPlugin
|
||||
{
|
||||
[KernelFunction]
|
||||
[Description("Gets the current weather for the specified city")]
|
||||
public string GetWeatherForCity(string cityName) =>
|
||||
cityName switch
|
||||
{
|
||||
"Boston" => "61 and rainy",
|
||||
"London" => "55 and cloudy",
|
||||
"Miami" => "80 and sunny",
|
||||
"Paris" => "60 and rainy",
|
||||
"Tokyo" => "50 and sunny",
|
||||
"Sydney" => "75 and sunny",
|
||||
"Tel Aviv" => "80 and sunny",
|
||||
_ => "31 and snowing",
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
using System.IO;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.SemanticKernel;
|
||||
using Microsoft.SemanticKernel.Planning;
|
||||
using StepwisePlannerMigration.Extensions;
|
||||
using StepwisePlannerMigration.Options;
|
||||
using StepwisePlannerMigration.Services;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Get configuration
|
||||
var config = new ConfigurationBuilder()
|
||||
.SetBasePath(Directory.GetCurrentDirectory())
|
||||
.AddJsonFile("appsettings.json")
|
||||
.AddJsonFile("appsettings.Development.json", true)
|
||||
.AddUserSecrets<Program>()
|
||||
.Build();
|
||||
|
||||
var openAIOptions = config.GetValid<OpenAIOptions>(OpenAIOptions.SectionName);
|
||||
|
||||
// Add services to the container.
|
||||
builder.Services.AddControllers();
|
||||
builder.Services.AddLogging(loggingBuilder => loggingBuilder.AddConsole());
|
||||
builder.Services.AddTransient<IPlanProvider, PlanProvider>();
|
||||
|
||||
// Add Semantic Kernel
|
||||
builder.Services.AddKernel();
|
||||
builder.Services.AddOpenAIChatCompletion(openAIOptions.ChatModelId, openAIOptions.ApiKey);
|
||||
|
||||
builder.Services.AddTransient<FunctionCallingStepwisePlanner>();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
app.UseAuthorization();
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
app.Run();
|
||||
@@ -0,0 +1,132 @@
|
||||
# Function Calling Stepwise Planner Migration
|
||||
|
||||
This demo application shows how to migrate from FunctionCallingStepwisePlanner to a new recommended approach for planning capability - Auto Function Calling.
|
||||
The new approach produces the results more reliably and uses fewer tokens compared to FunctionCallingStepwisePlanner.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
1. [OpenAI](https://platform.openai.com/docs/introduction) subscription.
|
||||
2. Update `appsettings.Development.json` file with your configuration for `OpenAI` section or use .NET [Secret Manager](https://learn.microsoft.com/en-us/aspnet/core/security/app-secrets) (recommended approach):
|
||||
|
||||
```powershell
|
||||
# OpenAI
|
||||
# Make sure to use the model which supports function calling capability.
|
||||
# Supported models: https://platform.openai.com/docs/guides/function-calling/supported-models
|
||||
dotnet user-secrets set "OpenAI:ChatModelId" "... your model ..."
|
||||
dotnet user-secrets set "OpenAI:ApiKey" "... your api key ... "
|
||||
```
|
||||
|
||||
## Testing
|
||||
|
||||
1. Start ASP.NET Web API application.
|
||||
2. Open `StepwisePlannerMigration.http` file and run listed requests.
|
||||
|
||||
It's possible to send [HTTP requests](https://learn.microsoft.com/en-us/aspnet/core/test/http-files?view=aspnetcore-8.0) directly from `StepwisePlannerMigration.http` with Visual Studio 2022 version 17.8 or later. For Visual Studio Code users, use `StepwisePlannerMigration.http` file as REST API specification and use tool of your choice to send described requests.
|
||||
|
||||
## Migration guide
|
||||
|
||||
### Plan generation
|
||||
|
||||
Old approach:
|
||||
|
||||
```csharp
|
||||
Kernel kernel = Kernel
|
||||
.CreateBuilder()
|
||||
.AddOpenAIChatCompletion("gpt-4", Environment.GetEnvironmentVariable("OpenAI__ApiKey"))
|
||||
.Build();
|
||||
|
||||
FunctionCallingStepwisePlanner planner = new();
|
||||
|
||||
FunctionCallingStepwisePlannerResult result = await planner.ExecuteAsync(kernel, "Check current UTC time and return current weather in Boston city.");
|
||||
|
||||
ChatHistory generatedPlan = result.ChatHistory;
|
||||
```
|
||||
|
||||
New approach:
|
||||
|
||||
```csharp
|
||||
Kernel kernel = Kernel
|
||||
.CreateBuilder()
|
||||
.AddOpenAIChatCompletion("gpt-4", Environment.GetEnvironmentVariable("OpenAI__ApiKey"))
|
||||
.Build();
|
||||
|
||||
IChatCompletionService chatCompletionService = kernel.GetRequiredService<IChatCompletionService>();
|
||||
|
||||
ChatHistory chatHistory = [];
|
||||
chatHistory.AddUserMessage("Check current UTC time and return current weather in Boston city.");
|
||||
|
||||
OpenAIPromptExecutionSettings executionSettings = new() { FunctionChoiceBehavior = FunctionChoiceBehavior.Auto() };
|
||||
|
||||
await chatCompletionService.GetChatMessageContentAsync(chatHistory, executionSettings, kernel);
|
||||
|
||||
ChatHistory generatedPlan = chatHistory;
|
||||
```
|
||||
|
||||
### New plan execution
|
||||
|
||||
Old approach:
|
||||
|
||||
```csharp
|
||||
Kernel kernel = Kernel
|
||||
.CreateBuilder()
|
||||
.AddOpenAIChatCompletion("gpt-4", Environment.GetEnvironmentVariable("OpenAI__ApiKey"))
|
||||
.Build();
|
||||
|
||||
FunctionCallingStepwisePlanner planner = new();
|
||||
|
||||
FunctionCallingStepwisePlannerResult result = await planner.ExecuteAsync(kernel, "Check current UTC time and return current weather in Boston city.");
|
||||
|
||||
string planResult = result.FinalAnswer;
|
||||
```
|
||||
|
||||
New approach:
|
||||
|
||||
```csharp
|
||||
Kernel kernel = Kernel
|
||||
.CreateBuilder()
|
||||
.AddOpenAIChatCompletion("gpt-4", Environment.GetEnvironmentVariable("OpenAI__ApiKey"))
|
||||
.Build();
|
||||
|
||||
OpenAIPromptExecutionSettings executionSettings = new() { FunctionChoiceBehavior = FunctionChoiceBehavior.Auto() };
|
||||
|
||||
FunctionResult result = await kernel.InvokePromptAsync("Check current UTC time and return current weather in Boston city.", new(executionSettings));
|
||||
|
||||
string planResult = result.ToString();
|
||||
```
|
||||
|
||||
### Existing plan execution
|
||||
|
||||
Old approach:
|
||||
|
||||
```csharp
|
||||
Kernel kernel = Kernel
|
||||
.CreateBuilder()
|
||||
.AddOpenAIChatCompletion("gpt-4", Environment.GetEnvironmentVariable("OpenAI__ApiKey"))
|
||||
.Build();
|
||||
|
||||
FunctionCallingStepwisePlanner planner = new();
|
||||
ChatHistory existingPlan = GetExistingPlan(); // plan can be stored in database for reusability.
|
||||
|
||||
FunctionCallingStepwisePlannerResult result = await planner.ExecuteAsync(kernel, "Check current UTC time and return current weather in Boston city.", existingPlan);
|
||||
|
||||
string planResult = result.FinalAnswer;
|
||||
```
|
||||
|
||||
New approach:
|
||||
|
||||
```csharp
|
||||
Kernel kernel = Kernel
|
||||
.CreateBuilder()
|
||||
.AddOpenAIChatCompletion("gpt-4", Environment.GetEnvironmentVariable("OpenAI__ApiKey"))
|
||||
.Build();
|
||||
|
||||
IChatCompletionService chatCompletionService = kernel.GetRequiredService<IChatCompletionService>();
|
||||
|
||||
ChatHistory existingPlan = GetExistingPlan(); // plan can be stored in database for reusability.
|
||||
|
||||
OpenAIPromptExecutionSettings executionSettings = new() { FunctionChoiceBehavior = FunctionChoiceBehavior.Auto() };
|
||||
|
||||
ChatMessageContent result = await chatCompletionService.GetChatMessageContentAsync(chatHistory, executionSettings, kernel);
|
||||
|
||||
string planResult = result.Content;
|
||||
```
|
||||
+121
@@ -0,0 +1,121 @@
|
||||
[
|
||||
{
|
||||
"Role": { "Label": "user" },
|
||||
"Items": [
|
||||
{
|
||||
"$type": "TextContent",
|
||||
"Text": "Check current UTC time and return current weather in Boston city."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"Role": { "Label": "assistant" },
|
||||
"Items": [
|
||||
{
|
||||
"$type": "FunctionCallContent",
|
||||
"Id": "call_NbFR26Ui7GaIlVgpGvsLWR8H",
|
||||
"PluginName": "TimePlugin",
|
||||
"FunctionName": "GetCurrentUtcTime",
|
||||
"Arguments": {}
|
||||
}
|
||||
],
|
||||
"ModelId": "gpt-4",
|
||||
"Metadata": {
|
||||
"Id": "chatcmpl-9h56QcFJ2DlDcX0GSwZHz0me8o0Xt",
|
||||
"Created": "2024-07-04T00:59:06+00:00",
|
||||
"PromptFilterResults": [],
|
||||
"SystemFingerprint": null,
|
||||
"Usage": {
|
||||
"CompletionTokens": 11,
|
||||
"PromptTokens": 86,
|
||||
"TotalTokens": 97
|
||||
},
|
||||
"ContentFilterResults": null,
|
||||
"FinishReason": "tool_calls",
|
||||
"FinishDetails": null,
|
||||
"LogProbabilityInfo": null,
|
||||
"Index": 0,
|
||||
"Enhancements": null,
|
||||
"ChatResponseMessage.FunctionToolCalls": [
|
||||
{
|
||||
"Name": "TimePlugin-GetCurrentUtcTime",
|
||||
"Arguments": "{}",
|
||||
"Id": "call_NbFR26Ui7GaIlVgpGvsLWR8H"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"Role": { "Label": "tool" },
|
||||
"Items": [
|
||||
{
|
||||
"$type": "TextContent",
|
||||
"Text": "Thu, 04 Jul 2024 00:59:07 GMT",
|
||||
"Metadata": { "ChatCompletionsToolCall.Id": "call_NbFR26Ui7GaIlVgpGvsLWR8H" }
|
||||
},
|
||||
{
|
||||
"$type": "FunctionResultContent",
|
||||
"CallId": "call_NbFR26Ui7GaIlVgpGvsLWR8H",
|
||||
"PluginName": "TimePlugin",
|
||||
"FunctionName": "GetCurrentUtcTime",
|
||||
"Result": "Thu, 04 Jul 2024 00:59:07 GMT"
|
||||
}
|
||||
],
|
||||
"Metadata": { "ChatCompletionsToolCall.Id": "call_NbFR26Ui7GaIlVgpGvsLWR8H" }
|
||||
},
|
||||
{
|
||||
"Role": { "Label": "assistant" },
|
||||
"Items": [
|
||||
{
|
||||
"$type": "FunctionCallContent",
|
||||
"Id": "call_HZrx5uHt89ogb2J5KG7quVsd",
|
||||
"PluginName": "WeatherPlugin",
|
||||
"FunctionName": "GetWeatherForCity",
|
||||
"Arguments": { "cityName": "Boston" }
|
||||
}
|
||||
],
|
||||
"ModelId": "gpt-4",
|
||||
"Metadata": {
|
||||
"Id": "chatcmpl-9h56R3fdeXBn7pPOSZUDtE0fSnrzU",
|
||||
"Created": "2024-07-04T00:59:07+00:00",
|
||||
"PromptFilterResults": [],
|
||||
"SystemFingerprint": null,
|
||||
"Usage": {
|
||||
"CompletionTokens": 22,
|
||||
"PromptTokens": 124,
|
||||
"TotalTokens": 146
|
||||
},
|
||||
"ContentFilterResults": null,
|
||||
"FinishReason": "tool_calls",
|
||||
"FinishDetails": null,
|
||||
"LogProbabilityInfo": null,
|
||||
"Index": 0,
|
||||
"Enhancements": null,
|
||||
"ChatResponseMessage.FunctionToolCalls": [
|
||||
{
|
||||
"Name": "WeatherPlugin-GetWeatherForCity",
|
||||
"Arguments": "{\n \u0022cityName\u0022: \u0022Boston\u0022\n}",
|
||||
"Id": "call_HZrx5uHt89ogb2J5KG7quVsd"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"Role": { "Label": "tool" },
|
||||
"Items": [
|
||||
{
|
||||
"$type": "TextContent",
|
||||
"Text": "61 and rainy",
|
||||
"Metadata": { "ChatCompletionsToolCall.Id": "call_HZrx5uHt89ogb2J5KG7quVsd" }
|
||||
},
|
||||
{
|
||||
"$type": "FunctionResultContent",
|
||||
"CallId": "call_HZrx5uHt89ogb2J5KG7quVsd",
|
||||
"PluginName": "WeatherPlugin",
|
||||
"FunctionName": "GetWeatherForCity",
|
||||
"Result": "61 and rainy"
|
||||
}
|
||||
],
|
||||
"Metadata": { "ChatCompletionsToolCall.Id": "call_HZrx5uHt89ogb2J5KG7quVsd" }
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,125 @@
|
||||
[
|
||||
{
|
||||
"Role": { "Label": "system" },
|
||||
"Items": [
|
||||
{
|
||||
"$type": "TextContent",
|
||||
"Text": "Original request: Check current UTC time and return current weather in Boston city.\n\nYou are in the process of helping the user fulfill this request using the following plan:\nPlan:\n\n1. Use the \u0026quot;TimePlugin-GetCurrentUtcTime\u0026quot; function to get the current UTC time.\n2. Use the \u0026quot;WeatherPlugin-GetWeatherForCity\u0026quot; function with the parameter \u0026quot;cityName\u0026quot; set to \u0026quot;Boston\u0026quot; to get the current weather in Boston.\n3. Combine the results from steps 1 and 2 into a single message.\n4. Use the \u0026quot;UserInteraction-SendFinalAnswer\u0026quot; function with the combined message from step 3 as the \u0026quot;answer\u0026quot; parameter to send the final answer to the user.\n\nThe user will ask you for help with each step."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"Role": { "Label": "user" },
|
||||
"Items": [
|
||||
{
|
||||
"$type": "TextContent",
|
||||
"Text": "Perform the next step of the plan if there is more work to do. When you have reached a final answer, use the UserInteraction-SendFinalAnswer function to communicate this back to the user."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"Role": { "Label": "assistant" },
|
||||
"Items": [
|
||||
{
|
||||
"$type": "FunctionCallContent",
|
||||
"Id": "call_zk4X05l4IjZrtvG7SXwdgpu2",
|
||||
"PluginName": "TimePlugin",
|
||||
"FunctionName": "GetCurrentUtcTime",
|
||||
"Arguments": {}
|
||||
}
|
||||
],
|
||||
"ModelId": "gpt-4",
|
||||
"Metadata": {
|
||||
"Id": "chatcmpl-9h4wSOujc7QxGOFQHdNiz24VQaVTn",
|
||||
"Created": "2024-07-04T00:48:48+00:00",
|
||||
"PromptFilterResults": [],
|
||||
"SystemFingerprint": null,
|
||||
"Usage": {
|
||||
"CompletionTokens": 11,
|
||||
"PromptTokens": 325,
|
||||
"TotalTokens": 336
|
||||
},
|
||||
"ContentFilterResults": null,
|
||||
"FinishReason": "tool_calls",
|
||||
"FinishDetails": null,
|
||||
"LogProbabilityInfo": null,
|
||||
"Index": 0,
|
||||
"Enhancements": null,
|
||||
"ChatResponseMessage.FunctionToolCalls": [
|
||||
{
|
||||
"Name": "TimePlugin-GetCurrentUtcTime",
|
||||
"Arguments": "{}",
|
||||
"Id": "call_zk4X05l4IjZrtvG7SXwdgpu2"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"Role": { "Label": "tool" },
|
||||
"Items": [
|
||||
{
|
||||
"$type": "TextContent",
|
||||
"Text": "Thu, 04 Jul 2024 00:48:49 GMT",
|
||||
"Metadata": { "ChatCompletionsToolCall.Id": "call_zk4X05l4IjZrtvG7SXwdgpu2" }
|
||||
}
|
||||
],
|
||||
"Metadata": { "ChatCompletionsToolCall.Id": "call_zk4X05l4IjZrtvG7SXwdgpu2" }
|
||||
},
|
||||
{
|
||||
"Role": { "Label": "user" },
|
||||
"Items": [
|
||||
{
|
||||
"$type": "TextContent",
|
||||
"Text": "Perform the next step of the plan if there is more work to do. When you have reached a final answer, use the UserInteraction-SendFinalAnswer function to communicate this back to the user."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"Role": { "Label": "assistant" },
|
||||
"Items": [
|
||||
{
|
||||
"$type": "FunctionCallContent",
|
||||
"Id": "call_wpIUUK7UloW00NCMQCfspRcg",
|
||||
"PluginName": "WeatherPlugin",
|
||||
"FunctionName": "GetWeatherForCity",
|
||||
"Arguments": { "cityName": "Boston" }
|
||||
}
|
||||
],
|
||||
"ModelId": "gpt-4",
|
||||
"Metadata": {
|
||||
"Id": "chatcmpl-9h4wTwSPTJ8CBmFuIB8X6kMjJXOvA",
|
||||
"Created": "2024-07-04T00:48:49+00:00",
|
||||
"PromptFilterResults": [],
|
||||
"SystemFingerprint": null,
|
||||
"Usage": {
|
||||
"CompletionTokens": 22,
|
||||
"PromptTokens": 407,
|
||||
"TotalTokens": 429
|
||||
},
|
||||
"ContentFilterResults": null,
|
||||
"FinishReason": "tool_calls",
|
||||
"FinishDetails": null,
|
||||
"LogProbabilityInfo": null,
|
||||
"Index": 0,
|
||||
"Enhancements": null,
|
||||
"ChatResponseMessage.FunctionToolCalls": [
|
||||
{
|
||||
"Name": "WeatherPlugin-GetWeatherForCity",
|
||||
"Arguments": "{\n \u0022cityName\u0022: \u0022Boston\u0022\n}",
|
||||
"Id": "call_wpIUUK7UloW00NCMQCfspRcg"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"Role": { "Label": "tool" },
|
||||
"Items": [
|
||||
{
|
||||
"$type": "TextContent",
|
||||
"Text": "61 and rainy",
|
||||
"Metadata": { "ChatCompletionsToolCall.Id": "call_wpIUUK7UloW00NCMQCfspRcg" }
|
||||
}
|
||||
],
|
||||
"Metadata": { "ChatCompletionsToolCall.Id": "call_wpIUUK7UloW00NCMQCfspRcg" }
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,17 @@
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
#pragma warning disable IDE0005 // Using directive is unnecessary
|
||||
|
||||
using Microsoft.SemanticKernel.ChatCompletion;
|
||||
|
||||
#pragma warning restore IDE0005 // Using directive is unnecessary
|
||||
|
||||
namespace StepwisePlannerMigration.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Interface to get a previously generated plan from file for demonstration purposes.
|
||||
/// </summary>
|
||||
public interface IPlanProvider
|
||||
{
|
||||
ChatHistory GetPlan(string fileName);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
|
||||
#pragma warning disable IDE0005 // Using directive is unnecessary
|
||||
|
||||
using Microsoft.SemanticKernel.ChatCompletion;
|
||||
|
||||
#pragma warning restore IDE0005 // Using directive is unnecessary
|
||||
|
||||
namespace StepwisePlannerMigration.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Class to get a previously generated plan from file for demonstration purposes.
|
||||
/// </summary>
|
||||
public class PlanProvider : IPlanProvider
|
||||
{
|
||||
public ChatHistory GetPlan(string fileName)
|
||||
{
|
||||
var plan = File.ReadAllText($"Resources/{fileName}");
|
||||
return JsonSerializer.Deserialize<ChatHistory>(plan)!;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<NoWarn>$(NoWarn);VSTHRD111,CA2007,CS8618,CS1591,SKEXP0001, SKEXP0060</NoWarn>
|
||||
<UserSecretsId>5ee045b0-aea3-4f08-8d31-32d1a6f8fed0</UserSecretsId>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.SemanticKernel.Abstractions" />
|
||||
<PackageReference Include="Microsoft.SemanticKernel.Connectors.OpenAI" />
|
||||
<PackageReference Include="Microsoft.SemanticKernel.Core" />
|
||||
<PackageReference Include="Microsoft.SemanticKernel.Planners.OpenAI" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Update="Resources\auto-function-calling-plan.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Update="Resources\stepwise-plan.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,61 @@
|
||||
@StepwisePlannerMigration_HostAddress = http://localhost:5257
|
||||
|
||||
POST {{StepwisePlannerMigration_HostAddress}}/stepwise-planner/generate-plan
|
||||
Accept: application/json
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"goal": "Check current UTC time and return current weather in Boston city."
|
||||
}
|
||||
|
||||
###
|
||||
|
||||
POST {{StepwisePlannerMigration_HostAddress}}/stepwise-planner/execute-new-plan
|
||||
Accept: application/json
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"goal": "Check current UTC time and return current weather in Boston city."
|
||||
}
|
||||
|
||||
###
|
||||
|
||||
POST {{StepwisePlannerMigration_HostAddress}}/stepwise-planner/execute-existing-plan
|
||||
Accept: application/json
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"goal": "Check current UTC time and return current weather in Boston city."
|
||||
}
|
||||
|
||||
###
|
||||
|
||||
POST {{StepwisePlannerMigration_HostAddress}}/auto-function-calling/generate-plan
|
||||
Accept: application/json
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"goal": "Check current UTC time and return current weather in Boston city."
|
||||
}
|
||||
|
||||
###
|
||||
|
||||
POST {{StepwisePlannerMigration_HostAddress}}/auto-function-calling/execute-new-plan
|
||||
Accept: application/json
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"goal": "Check current UTC time and return current weather in Boston city."
|
||||
}
|
||||
|
||||
###
|
||||
|
||||
POST {{StepwisePlannerMigration_HostAddress}}/auto-function-calling/execute-existing-plan
|
||||
Accept: application/json
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"goal": "Check current UTC time and return current weather in Boston city."
|
||||
}
|
||||
|
||||
###
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"OpenAI": {
|
||||
"ChatModelId": "",
|
||||
"ApiKey": ""
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user