semantic-kernel icon indicating copy to clipboard operation
semantic-kernel copied to clipboard

OpenAPI skills dotnet sample removes the system prompt from chat history when token limit is exceeded.

Open vman opened this issue 3 years ago • 2 comments

Description

In this line of code https://github.com/microsoft/semantic-kernel/blob/6a270273ee6a2bc27baaa9c8157416b7c10716a7/samples/dotnet/openapi-skills/Program.cs#L116

The first element from the chatHistory.Messages array is removed when tokenCount goes about the Token limit.

In the first iteration, this removes the system prompt from the history. The logic works well in the subsequent removals. Removal of the system prompt could cause the language model to give unexpected results.

To Reproduce Steps to reproduce the behavior:

  1. Run the OpenAI Skills sample
  2. Have a conversation until the token limit is exceeded
  3. Observe that the system prompt is removed from chatHistory.Messages
  4. See error

Expected behavior The line should be changed to chatHistory.Messages.RemoveAt(1) so that the system prompt always remains at the 0 index and the history is removed starting from index 1.

Desktop (please complete the following information):

  • OS: Windows
  • IDE: Visual Studio
  • NuGet Package Version: N/A

vman avatar Jun 04 '23 22:06 vman

Testing fix

gitri-ms avatar Jun 27 '23 22:06 gitri-ms

Thanks @vman for the clear repro steps and details about this issue! I've opened a PR (#1738) with the fix.

gitri-ms avatar Jun 27 '23 23:06 gitri-ms