-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
.Net: Create Plan Prompt Override (#5005)
### 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? 2. What problem does it solve? 3. What scenario does it contribute to? 4. If it fixes an open issue, please link to the issue here. --> This PR adds the option to override the CreatePlan prompt. ### Description <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> Users can pass in a callback to `HandlebarsPlannerOptions.GetCreatePlanPrompt` that returns a valid Handlebars Template string to be used in place of the default CreatePlan prompt. Users have the options to select any predefined partials in their own template. These helpers are pre-registered and available for reference at the time of import override. ### 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#development-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: Mark Wallace <127216156+markwallace-microsoft@users.noreply.github.com>
- Loading branch information
1 parent
0a60d9c
commit 27d5ffe
Showing
8 changed files
with
236 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
dotnet/samples/KernelSyntaxExamples/Resources/65-prompt-override.handlebars
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
{{!-- Example of a custom CreatePlan prompt for the Handlebars Planner. | ||
Be sure to use the ChatHistory syntax so the completion request is formatted correctly before it's sent to the model. --}} | ||
{{#message role="system"}} | ||
Explain how to achieve the user's goal using the available helpers with a Handlebars .Net template. | ||
{{~/message}} | ||
|
||
{{#message role="user"}} | ||
{{!-- Custom helpers section. Strictly for demonstration purposes. This will only render what's shown below. | ||
It will not render any of the kernel functions or built-in system helpers, | ||
thus overriding the helpers section is not recommended. --}} | ||
You have a plugin named `MovieDatabase`. | ||
These are the object types that are used in the plugin: | ||
|
||
### Movie: | ||
{ | ||
"type": "Object", | ||
"properties": { | ||
"name": { | ||
"type": "string", | ||
}, | ||
"genre": { | ||
"type": "string", | ||
}, | ||
"year": { | ||
"type": "integer", | ||
}, | ||
"rating": { | ||
"type": "number", | ||
}, | ||
} | ||
} | ||
|
||
### MovieDetails: | ||
{ | ||
"type": "Object", | ||
"properties": { | ||
"name": { | ||
"type": "string", | ||
}, | ||
"genre": { | ||
"type": "string", | ||
}, | ||
"year": { | ||
"type": "integer", | ||
}, | ||
"rating": { | ||
"type": "number", | ||
}, | ||
"description": { | ||
"type": "string", | ||
}, | ||
"reviews": { | ||
"type": "array", | ||
"items": { | ||
"type": "string", | ||
} | ||
}, | ||
"actors": { | ||
"type": "array", | ||
"items": { | ||
"type": "string", | ||
} | ||
}, | ||
"director": { | ||
"type": "string", | ||
}, | ||
} | ||
} | ||
|
||
These are the custom helpers that are available in the `MovieDatabase` plugin: | ||
|
||
### `MovieDatabase{{../nameDelimiter}}SearchMovies` | ||
Description: Search for movies in the database. | ||
Inputs: | ||
- Name: string - The name of the movie to search for, can be a partial name. (optional) | ||
- Genre: string - Genre of movie to search for. (optional) | ||
Output: List<Movie> - List of movies matching the search criteria. | ||
|
||
### `MovieDatabase{{../nameDelimiter}}GetMovieSummary` | ||
Description: Get of a movie. | ||
Inputs: | ||
- Name: string - The name of the movie to get. (required) | ||
Output: Movie - Summary details of the movie. | ||
|
||
### `MovieDatabase{{../nameDelimiter}}GetFullMovieDetails` | ||
Description: Get full details of a movie. | ||
Inputs: | ||
- Movie: Movie - The movie to pull details for. (required) | ||
Output: MovieDetails - Full details of the movie. | ||
|
||
### `MovieDatabase{{../nameDelimiter}}AddMovie` | ||
Description: Add a movie to the database. | ||
Inputs: | ||
- Movie: MovieDetails - The movie to add to the database. (required) | ||
Output: Void | ||
|
||
### `MovieDatabase{{../nameDelimiter}}AddReview` | ||
Description: Add a review to a movie. | ||
Inputs: | ||
- Movie: Movie - The movie to add the rating to. (required) | ||
- Rating: number - The rating to add to the movie. (required) | ||
- Review: string - The review to add to the movie. (optional) | ||
Output: Void | ||
|
||
{{!-- All partials defined in Planners.Handlebars.CreatePlanPromptPartials nanespace are registered | ||
with every Handlebars Planner instance and can be selected for use in custom prompts. --}} | ||
You also have the following built-in helpers available for use: | ||
{{> BlockHelpers }} | ||
|
||
{{> VariableHelpers }} | ||
{{/message}} | ||
|
||
{{!-- You can inject the user goal manually using {{goal}} or use the UserGoal partial to leverage SK's templating and prompt engineering. --}} | ||
{{> UserGoal }} | ||
|
||
{{> TipsAndInstructions }} |
Oops, something went wrong.