Skip to content

Commit 60cf261

Browse files
Merge branch 'main' into update-modelid
2 parents 2f726c2 + 3a7d3bd commit 60cf261

36 files changed

Lines changed: 844 additions & 604 deletions

File tree

‎dotnet/SK-dotnet.sln‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Planners.Handlebars", "src\
152152
EndProject
153153
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "planning", "planning", "{A7DAB812-81CF-4931-B38C-468A3261C4C8}"
154154
ProjectSection(SolutionItems) = preProject
155-
src\InternalUtilities\planning\PlannerConfigBase.cs = src\InternalUtilities\planning\PlannerConfigBase.cs
156155
src\InternalUtilities\planning\PlannerInstrumentation.cs = src\InternalUtilities\planning\PlannerInstrumentation.cs
157156
src\InternalUtilities\planning\PlanningUtilities.props = src\InternalUtilities\planning\PlanningUtilities.props
157+
src\InternalUtilities\planning\PlannerOptions.cs = src\InternalUtilities\planning\PlannerOptions.cs
158158
src\InternalUtilities\planning\SemanticMemoryConfig.cs = src\InternalUtilities\planning\SemanticMemoryConfig.cs
159159
EndProjectSection
160160
EndProject

‎dotnet/samples/KernelSyntaxExamples/Example48_GroundednessChecks.cs‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.IO;
44
using System.Threading.Tasks;
55
using Microsoft.SemanticKernel;
6+
using Microsoft.SemanticKernel.Connectors.OpenAI;
67
using Microsoft.SemanticKernel.Planning.Handlebars;
78
using Microsoft.SemanticKernel.Plugins.Core;
89
using RepoUtils;
@@ -101,7 +102,16 @@ which are not grounded in the original.
101102

102103
kernel.ImportPluginFromType<TextPlugin>();
103104

104-
var planner = new HandlebarsPlanner();
105+
var planner = new HandlebarsPlanner(
106+
new HandlebarsPlannerOptions()
107+
{
108+
// When using OpenAI models, we recommend using low values for temperature and top_p to minimize planner hallucinations.
109+
ExecutionSettings = new OpenAIPromptExecutionSettings()
110+
{
111+
Temperature = 0.0,
112+
TopP = 0.1,
113+
}
114+
});
105115
var plan = await planner.CreatePlanAsync(kernel, ask);
106116

107117
WriteLine($"======== Goal: ========\n{ask}");

‎dotnet/samples/KernelSyntaxExamples/Example65_HandlebarsPlanner.cs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.IO;
55
using System.Threading.Tasks;
66
using Microsoft.SemanticKernel;
7+
using Microsoft.SemanticKernel.Connectors.OpenAI;
78
using Microsoft.SemanticKernel.Planning.Handlebars;
89
using Microsoft.SemanticKernel.Plugins.OpenApi;
910
using Plugins.DictionaryPlugin;
@@ -81,6 +82,13 @@ await kernel.ImportPluginFromOpenApiAsync(
8182
var planner = new HandlebarsPlanner(
8283
new HandlebarsPlannerOptions()
8384
{
85+
// When using OpenAI models, we recommend using low values for temperature and top_p to minimize planner hallucinations.
86+
ExecutionSettings = new OpenAIPromptExecutionSettings()
87+
{
88+
Temperature = 0.0,
89+
TopP = 0.1,
90+
},
91+
8492
// Change this if you want to test with loops regardless of model selection.
8593
AllowLoops = allowLoopsInPlan
8694
});

‎dotnet/samples/KernelSyntaxExamples/Example66_FunctionCallingStepwisePlanner.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ public async Task RunAsync()
2222

2323
var kernel = InitializeKernel();
2424

25-
var config = new FunctionCallingStepwisePlannerConfig
25+
var options = new FunctionCallingStepwisePlannerOptions
2626
{
2727
MaxIterations = 15,
2828
MaxTokens = 4000,
2929
};
30-
var planner = new FunctionCallingStepwisePlanner(config);
30+
var planner = new FunctionCallingStepwisePlanner(options);
3131

3232
foreach (var question in questions)
3333
{

‎dotnet/samples/KernelSyntaxExamples/Example75_AgentTools.cs‎

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,30 +26,19 @@ public sealed class Example75_AgentTools : BaseTest
2626
private readonly List<IAgent> _agents = new();
2727

2828
/// <summary>
29-
/// Show how to utilize code_interpreter and retrieval tools.
29+
/// Show how to utilize code_interpreter tool.
3030
/// </summary>
3131
[Fact]
32-
public async Task RunAsync()
32+
public async Task RunCodeInterpreterToolAsync()
3333
{
34-
this.WriteLine("======== Example75_AgentTools ========");
34+
this.WriteLine("======== Using CodeInterpreter tool ========");
3535

3636
if (TestConfiguration.OpenAI.ApiKey == null)
3737
{
3838
this.WriteLine("OpenAI apiKey not found. Skipping example.");
3939
return;
4040
}
4141

42-
// Run agent with 'code_interpreter' tool
43-
await RunCodeInterpreterToolAsync();
44-
45-
// Run agent with 'retrieval' tool
46-
await RunRetrievalToolAsync();
47-
}
48-
49-
private async Task RunCodeInterpreterToolAsync()
50-
{
51-
this.WriteLine("======== Run:CodeInterpreterTool ========");
52-
5342
var builder =
5443
new AgentBuilder()
5544
.WithOpenAIChatCompletion(OpenAIFunctionEnabledModel, TestConfiguration.OpenAI.ApiKey)
@@ -77,9 +66,19 @@ await ChatAsync(
7766
}
7867
}
7968

80-
private async Task RunRetrievalToolAsync()
69+
/// <summary>
70+
/// Show how to utilize retrieval tool.
71+
/// </summary>
72+
[Fact]
73+
public async Task RunRetrievalToolAsync()
8174
{
82-
this.WriteLine("======== Run:RunRetrievalTool ========");
75+
this.WriteLine("======== Using Retrieval tool ========");
76+
77+
if (TestConfiguration.OpenAI.ApiKey == null)
78+
{
79+
this.WriteLine("OpenAI apiKey not found. Skipping example.");
80+
return;
81+
}
8382

8483
// REQUIRED:
8584
//

‎dotnet/samples/TelemetryExample/Program.cs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@ private static Kernel GetKernel(ILoggerFactory loggerFactory)
105105
return builder.Build();
106106
}
107107

108-
private static HandlebarsPlanner CreatePlanner(int maxTokens = 1024)
108+
private static HandlebarsPlanner CreatePlanner()
109109
{
110-
var plannerConfig = new HandlebarsPlannerOptions { MaxTokens = maxTokens };
111-
return new HandlebarsPlanner(plannerConfig);
110+
var plannerOptions = new HandlebarsPlannerOptions();
111+
return new HandlebarsPlanner(plannerOptions);
112112
}
113113

114114
private static void LoadUserSecrets()

‎dotnet/src/Connectors/Connectors.OpenAI/AzureSdk/OpenAIFunction.cs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ internal OpenAIFunction(
101101
}
102102

103103
/// <summary>Gets the separator used between the plugin name and the function name, if a plugin name is present.</summary>
104-
public static string NameSeparator => "_";
104+
/// <remarks>This separator was previously <c>_</c>, but has been changed to <c>-</c> to better align to the behavior elsewhere in SK and in response
105+
/// to developers who want to use underscores in their function or plugin names. We plan to make this setting configurable in the future.</remarks>
106+
public static string NameSeparator { get; set; } = "-";
105107

106108
/// <summary>Gets the name of the plugin with which the function is associated, if any.</summary>
107109
public string? PluginName { get; }

‎dotnet/src/Connectors/Connectors.UnitTests/OpenAI/AzureSdk/OpenAIPluginCollectionExtensionsTests.cs‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public void TryGetFunctionAndArgumentsWithoutArgumentsReturnsTrue()
3838
var plugin = KernelPluginFactory.CreateFromFunctions("MyPlugin", [function]);
3939

4040
var plugins = new KernelPluginCollection([plugin]);
41-
var toolCall = new ChatCompletionsFunctionToolCall("id", "MyPlugin_MyFunction", string.Empty);
41+
var toolCall = new ChatCompletionsFunctionToolCall("id", "MyPlugin-MyFunction", string.Empty);
4242

4343
// Act
4444
var result = plugins.TryGetFunctionAndArguments(toolCall, out var actualFunction, out var actualArguments);
@@ -57,7 +57,7 @@ public void TryGetFunctionAndArgumentsWithArgumentsReturnsTrue()
5757
var plugin = KernelPluginFactory.CreateFromFunctions("MyPlugin", [function]);
5858

5959
var plugins = new KernelPluginCollection([plugin]);
60-
var toolCall = new ChatCompletionsFunctionToolCall("id", "MyPlugin_MyFunction", "{\n \"location\": \"San Diego\",\n \"max_price\": 300\n,\n \"null_argument\": null\n}");
60+
var toolCall = new ChatCompletionsFunctionToolCall("id", "MyPlugin-MyFunction", "{\n \"location\": \"San Diego\",\n \"max_price\": 300\n,\n \"null_argument\": null\n}");
6161

6262
// Act
6363
var result = plugins.TryGetFunctionAndArguments(toolCall, out var actualFunction, out var actualArguments);
@@ -67,8 +67,10 @@ public void TryGetFunctionAndArgumentsWithArgumentsReturnsTrue()
6767
Assert.Same(function, actualFunction);
6868

6969
Assert.NotNull(actualArguments);
70+
7071
Assert.Equal("San Diego", actualArguments["location"]);
7172
Assert.Equal("300", actualArguments["max_price"]);
73+
7274
Assert.Null(actualArguments["null_argument"]);
7375
}
7476
}

‎dotnet/src/Connectors/Connectors.UnitTests/OpenAI/ChatCompletion/AzureOpenAIChatCompletionServiceTests.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ public async Task GetChatMessageContentsWithRequiredFunctionCallAsync()
388388
var secondContentJson = JsonSerializer.Deserialize<JsonElement>(secondContent);
389389

390390
Assert.Equal(1, firstContentJson.GetProperty("tools").GetArrayLength());
391-
Assert.Equal("MyPlugin_GetCurrentWeather", firstContentJson.GetProperty("tool_choice").GetProperty("function").GetProperty("name").GetString());
391+
Assert.Equal("MyPlugin-GetCurrentWeather", firstContentJson.GetProperty("tool_choice").GetProperty("function").GetProperty("name").GetString());
392392

393393
Assert.Equal("none", secondContentJson.GetProperty("tool_choice").GetString());
394394
}
@@ -555,7 +555,7 @@ public async Task GetStreamingChatMessageContentsWithRequiredFunctionCallAsync()
555555
var secondContentJson = JsonSerializer.Deserialize<JsonElement>(secondContent);
556556

557557
Assert.Equal(1, firstContentJson.GetProperty("tools").GetArrayLength());
558-
Assert.Equal("MyPlugin_GetCurrentWeather", firstContentJson.GetProperty("tool_choice").GetProperty("function").GetProperty("name").GetString());
558+
Assert.Equal("MyPlugin-GetCurrentWeather", firstContentJson.GetProperty("tool_choice").GetProperty("function").GetProperty("name").GetString());
559559

560560
Assert.Equal("none", secondContentJson.GetProperty("tool_choice").GetString());
561561
}

‎dotnet/src/Connectors/Connectors.UnitTests/OpenAI/ChatCompletion/OpenAIChatCompletionServiceTests.cs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ public async Task ItCreatesCorrectFunctionToolCallsWhenUsingAutoAsync()
9999
Assert.NotNull(actualRequestContent);
100100
var optionsJson = JsonSerializer.Deserialize<JsonElement>(actualRequestContent);
101101
Assert.Equal(2, optionsJson.GetProperty("tools").GetArrayLength());
102-
Assert.Equal("TimePlugin_Date", optionsJson.GetProperty("tools")[0].GetProperty("function").GetProperty("name").GetString());
103-
Assert.Equal("TimePlugin_Now", optionsJson.GetProperty("tools")[1].GetProperty("function").GetProperty("name").GetString());
102+
Assert.Equal("TimePlugin-Date", optionsJson.GetProperty("tools")[0].GetProperty("function").GetProperty("name").GetString());
103+
Assert.Equal("TimePlugin-Now", optionsJson.GetProperty("tools")[1].GetProperty("function").GetProperty("name").GetString());
104104
}
105105

106106
[Fact]
@@ -120,7 +120,7 @@ public async Task ItCreatesCorrectFunctionToolCallsWhenUsingNowAsync()
120120
Assert.NotNull(actualRequestContent);
121121
var optionsJson = JsonSerializer.Deserialize<JsonElement>(actualRequestContent);
122122
Assert.Equal(1, optionsJson.GetProperty("tools").GetArrayLength());
123-
Assert.Equal("TimePlugin_Now", optionsJson.GetProperty("tools")[0].GetProperty("function").GetProperty("name").GetString());
123+
Assert.Equal("TimePlugin-Now", optionsJson.GetProperty("tools")[0].GetProperty("function").GetProperty("name").GetString());
124124
}
125125

126126
[Fact]

0 commit comments

Comments
 (0)