OpenAPI skills dotnet sample removes the system prompt from chat history when token limit is exceeded.
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:
- Run the OpenAI Skills sample
- Have a conversation until the token limit is exceeded
- Observe that the system prompt is removed from
chatHistory.Messages - 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
Testing fix
Thanks @vman for the clear repro steps and details about this issue! I've opened a PR (#1738) with the fix.