You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When attaching the PromptRendered event to the kernel (in order to avoid going over the token limits), the updated .RenderedPrompt is not taken into consideration (i.e. I still get a context_length_exceeded error).
Here is a sample event handler:
private void Kernel_PromptRendered(object? sender, Microsoft.SemanticKernel.Events.PromptRenderedEventArgs e)
{
var tokenEncoding = GptEncoding.GetEncodingForModel(options.CurrentValue.ChatCompletionModelId); // usually "cl100k_base"
var encoded = tokenEncoding.Encode(e.RenderedPrompt);
if (encoded.Count > options.CurrentValue.MaxTokenTotal)
{
e.RenderedPrompt = tokenEncoding.Decode(encoded.GetRange(0, options.CurrentValue.MaxTokenTotal));
}
}
This applies to the C# SemanticKernel 1.0.0-rc3.
The text was updated successfully, but these errors were encountered:
github-actionsbot
changed the title
PromptRendered event does not use changed RenderedPrompt
.Net: PromptRendered event does not use changed RenderedPrompt
Dec 12, 2023
…4194)
### Motivation and Context
Closes#4190
### Description
<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->
### Contribution Checklist
<!-- Before submitting this PR, please make sure: -->
- [ ] The code builds clean without any errors or warnings
- [ ] 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
- [ ] All unit tests pass, and I have added new tests where possible
- [ ] I didn't break anyone 😄
When attaching the PromptRendered event to the kernel (in order to avoid going over the token limits), the updated .RenderedPrompt is not taken into consideration (i.e. I still get a context_length_exceeded error).
Here is a sample event handler:
This applies to the C# SemanticKernel 1.0.0-rc3.
The text was updated successfully, but these errors were encountered: