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

TokenCount performance issues #580

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion webapi/Skills/Utils/TokenUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ namespace CopilotChat.WebApi.Skills.Utils;
/// </summary>
public static class TokenUtils
{
private static SharpToken.GptEncoding tokenizer = SharpToken.GptEncoding.GetEncoding("cl100k_base");

/// <summary>
/// Semantic dependencies of ChatSkill.
/// If you add a new semantic dependency, please add it here.
Expand Down Expand Up @@ -98,7 +100,6 @@ internal static void GetFunctionTokenUsage(SKContext result, SKContext chatConte
/// <param name="text">The string to calculate the number of tokens in.</param>
internal static int TokenCount(string text)
{
var tokenizer = SharpToken.GptEncoding.GetEncoding("cl100k_base");
var tokens = tokenizer.Encode(text);
return tokens.Count;
}
Expand Down
Loading