Skip to content

Commit

Permalink
.Net: Add custom PromptConfig to Stepwise Planner (#2000)
Browse files Browse the repository at this point in the history
### Motivation and Context

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required? : 
  3. What problem does it solve?
  4. What scenario does it contribute to?
  5. If it fixes an open issue, please link to the issue here.
-->

In case of custom prompt, allow sending custom prompt config. This is
useful for custom prompt to Stepwise Planner having additional
parameters.

### Description

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

This allow stepwise planner to be created with custom prompt and custom
prompt config

### Contribution Checklist

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

- [x] The code builds clean without any errors or warnings
- [x] 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#dev-scripts)
raises no violations
- [x] All unit tests pass, and I have added new tests where possible
- [x] I didn't break anyone 😄

---------

Co-authored-by: Shawn Callegari <36091529+shawncal@users.noreply.github.com>
  • Loading branch information
akshaykokane and shawncal authored Jul 17, 2023
1 parent db53c12 commit e026da7
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions dotnet/src/Extensions/Planning.StepwisePlanner/StepwisePlanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,29 @@ public class StepwisePlanner
/// <param name="kernel">The semantic kernel instance.</param>
/// <param name="config">Optional configuration object</param>
/// <param name="prompt">Optional prompt override</param>
/// <param name="promptUserConfig">Optional prompt config override</param>
public StepwisePlanner(
IKernel kernel,
StepwisePlannerConfig? config = null,
string? prompt = null)
string? prompt = null,
PromptTemplateConfig? promptUserConfig = null)
{
Verify.NotNull(kernel);
this._kernel = kernel;

this.Config = config ?? new();
this.Config.ExcludedSkills.Add(RestrictedSkillName);

var promptConfig = new PromptTemplateConfig();
var promptConfig = promptUserConfig ?? new PromptTemplateConfig();
var promptTemplate = prompt ?? EmbeddedResource.Read("Skills.StepwiseStep.skprompt.txt");
string promptConfigString = EmbeddedResource.Read("Skills.StepwiseStep.config.json");
if (!string.IsNullOrEmpty(promptConfigString))

if (promptUserConfig == null)
{
promptConfig = PromptTemplateConfig.FromJson(promptConfigString);
string promptConfigString = EmbeddedResource.Read("Skills.StepwiseStep.config.json");
if (!string.IsNullOrEmpty(promptConfigString))
{
promptConfig = PromptTemplateConfig.FromJson(promptConfigString);
}
}

promptConfig.Completion.MaxTokens = this.Config.MaxTokens;
Expand Down

0 comments on commit e026da7

Please sign in to comment.