Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.Net: Update StepwisePlannerConfig to Improve MaxPromptTokens Calculation and Add Tests for Edge Cases #2850

Merged

Conversation

lemillermicrosoft
Copy link
Member

@lemillermicrosoft lemillermicrosoft commented Sep 15, 2023

This pull request updates the StepwisePlannerConfig class in the Planning.StepwisePlanner project to improve the calculation of the MaxPromptTokens property, ensuring that the maximum number of iterations allowed in a plan is properly taken into account. Additionally, it introduces a new configuration property for the maximum number of tokens allowed in a completion request and adds two new tests to cover edge cases where the number of functions is too large or almost too large.

Changes:

  • Modified the MaxPromptTokens property in the StepwisePlannerConfig class to use the MaxTokensRatio for calculating the maximum number of prompt tokens.
  • Updated the summary comment for the MaxPromptTokens property to reflect the new calculation method.
  • Add a new test ExecutePlanFailsWithTooManyFunctions to check if the execution fails when there are too many functions.
  • Add a new test ExecutePlanSucceedsWithAlmostTooManyFunctions to check if the execution succeeds when there are almost too many functions.
  • Update StepwisePlannerConfig to include a new property MaxTokensRatio for controlling the ratio of tokens allocated to the completion request.
  • Update StepwisePlanner to use the new MaxCompletionTokens property for setting the maximum number of tokens allowed in a completion request.
  • Modify the trimming logic in StepwisePlanner to account for the new token handling configuration and throw an exception if the chat history is too long.
  • Update the TrimMessageFormat constant in StepwisePlanner to include the number of steps removed in the message.
  • No other files or classes were affected by these changes.

Contribution Checklist

Sorry, something went wrong.

@shawncal shawncal added .NET Issue or Pull requests regarding .NET code kernel Issues or pull requests impacting the core kernel labels Sep 15, 2023
@github-actions github-actions bot changed the title Update StepwisePlannerConfig to Improve MaxPromptTokens Calculation and Add Tests for Edge Cases .Net: Update StepwisePlannerConfig to Improve MaxPromptTokens Calculation and Add Tests for Edge Cases Sep 15, 2023
@lemillermicrosoft lemillermicrosoft marked this pull request as ready for review September 19, 2023 04:49
@lemillermicrosoft lemillermicrosoft requested a review from a team as a code owner September 19, 2023 04:49
@lemillermicrosoft lemillermicrosoft self-assigned this Sep 19, 2023
@lemillermicrosoft lemillermicrosoft added this to the v1 milestone Sep 19, 2023
@lemillermicrosoft lemillermicrosoft added the PR: breaking change Pull requests that introduce breaking changes label Sep 19, 2023

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
This commit adjusts the token management in the StepwisePlanner by
introducing separate limits for prompt and completion tokens. It also
improves the trimming process by specifying the number of steps removed
and handling cases where the chat history is too long for completion.

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
Add two new tests to StepwisePlannerTests.cs: one for checking if the
plan execution fails when there are too many functions, and another for
verifying that the plan execution succeeds when there are almost too
many functions. This helps ensure the planner can handle different
scenarios with a large number of functions.
- Replace hardcoded "Result not found" message with a constant
  `NoFinalAnswerFoundMessage`
- Update comment for `MaxTokens` in `StepwisePlannerConfig` to clarify
  that it includes both prompt and completion tokens
- Changed test methods to use async Task instead of async void
- Renamed OpenApiSkillExecutionParameters to OpenApiPluginExecutionParameters
- Updated test method names to include "Async" suffix
@lemillermicrosoft lemillermicrosoft added this pull request to the merge queue Sep 21, 2023
Merged via the queue into microsoft:main with commit a348ca3 Sep 21, 2023
@lemillermicrosoft lemillermicrosoft deleted the 915_stepwise_tokens branch September 21, 2023 03:48
SOE-YoungS pushed a commit to SOE-YoungS/semantic-kernel that referenced this pull request Nov 1, 2023
…tion and Add Tests for Edge Cases (microsoft#2850)

This pull request updates the StepwisePlannerConfig class in the
Planning.StepwisePlanner project to improve the calculation of the
MaxPromptTokens property, ensuring that the maximum number of iterations
allowed in a plan is properly taken into account. Additionally, it
introduces a new configuration property for the maximum number of tokens
allowed in a completion request and adds two new tests to cover edge
cases where the number of functions is too large or almost too large.

Changes:
- Modified the MaxPromptTokens property in the StepwisePlannerConfig
class to use the MaxTokensRatio for calculating the maximum number of
prompt tokens.
- Updated the summary comment for the MaxPromptTokens property to
reflect the new calculation method.
- Add a new test `ExecutePlanFailsWithTooManyFunctions` to check if the
execution fails when there are too many functions.
- Add a new test `ExecutePlanSucceedsWithAlmostTooManyFunctions` to
check if the execution succeeds when there are almost too many
functions.
- Update `StepwisePlannerConfig` to include a new property
`MaxTokensRatio` for controlling the ratio of tokens allocated to the
completion request.
- Update `StepwisePlanner` to use the new `MaxCompletionTokens` property
for setting the maximum number of tokens allowed in a completion
request.
- Modify the trimming logic in `StepwisePlanner` to account for the new
token handling configuration and throw an exception if the chat history
is too long.
- Update the `TrimMessageFormat` constant in `StepwisePlanner` to
include the number of steps removed in the message.
- No other files or classes were affected by these changes.

### 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 😄
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kernel Issues or pull requests impacting the core kernel .NET Issue or Pull requests regarding .NET code PR: breaking change Pull requests that introduce breaking changes
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

3 participants