Skip to content

Commit

Permalink
[SequentialPlanner] Add default values to function manual (microsoft#647
Browse files Browse the repository at this point in the history
)

### Motivation and Context
SequentialPlanner was not respecting default values for inputs.

### Description
This commit modifies the ToManualString extension method for
FunctionView to include the default value of each parameter in the
generated string. This makes the manual more informative and helpful for
LLM to know the default behavior of a function. The default value is
shown in parentheses after the parameter description.
  • Loading branch information
lemillermicrosoft committed Apr 25, 2023
1 parent c5d46a7 commit 69bd011
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 23 additions & 0 deletions dotnet/src/IntegrationTests/Planning/SequentialPlannerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public async Task CreatePlanFunctionFlowAsync(string prompt, string expectedFunc

// Act
var plan = await planner.CreatePlanAsync(prompt);

// Assert
Assert.Contains(
plan.Steps,
Expand All @@ -51,6 +52,28 @@ public async Task CreatePlanFunctionFlowAsync(string prompt, string expectedFunc
step.SkillName.Equals(expectedSkill, StringComparison.OrdinalIgnoreCase));
}

[Theory]
[InlineData("Write a novel about software development that is 3 chapters long.", "NovelOutline", "WriterSkill", "<!--===ENDPART===-->")]
public async Task CreatePlanWithDefaultsAsync(string prompt, string expectedFunction, string expectedSkill, string expectedDefault)
{
// Arrange
IKernel kernel = this.InitializeKernel();
TestHelpers.GetSkill("WriterSkill", kernel);

var planner = new SequentialPlanner(kernel);

// Act
var plan = await planner.CreatePlanAsync(prompt);

// Assert
Assert.Contains(
plan.Steps,
step =>
step.Name.Equals(expectedFunction, StringComparison.OrdinalIgnoreCase) &&
step.SkillName.Equals(expectedSkill, StringComparison.OrdinalIgnoreCase) &&
step.NamedParameters["endMarker"].Equals(expectedDefault, StringComparison.OrdinalIgnoreCase));
}

[Theory]
[InlineData("Write a poem or joke and send it in an e-mail to Kai.", "SendEmailAsync", "_GLOBAL_FUNCTIONS_")]
public async Task CreatePlanGoalRelevantAsync(string prompt, string expectedFunction, string expectedSkill)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal static class FunctionViewExtensions
/// <returns>A manual-friendly string for a function.</returns>
internal static string ToManualString(this FunctionView function)
{
var inputs = string.Join("\n", function.Parameters.Select(p => $" - {p.Name}: {p.Description}"));
var inputs = string.Join("\n", function.Parameters.Select(p => $" - {p.Name}: {p.Description} (default value: {p.DefaultValue}))"));
return $" {function.ToFullyQualifiedName()}:\n description: {function.Description}\n inputs:\n{inputs}";
}

Expand Down

0 comments on commit 69bd011

Please sign in to comment.