Skip to content

Commit

Permalink
We encountered some performance issues and implemented the following …
Browse files Browse the repository at this point in the history
…fix. We updated the TokenUtils class within the Skills Web API to address these issues. A newly-introduced tokenizer has been implemented for encoding text, which significantly improves the efficiency of the TokenCount method. As a result of this change, the performance of the token counting operations has been enhanced, ensuring more accurate and faster responses for users.
  • Loading branch information
JohanYman committed Nov 7, 2023
1 parent 68d6e0a commit d403a02
Showing 1 changed file with 2 additions and 1 deletion.
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

0 comments on commit d403a02

Please sign in to comment.