-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from tghamm/feature/token-counter
Claude token counter, version bump, readme update
- Loading branch information
Showing
6 changed files
with
64,826 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using Microsoft.ML.Tokenizers; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Dynamic; | ||
using System.IO; | ||
using System.Reflection; | ||
using System.Text; | ||
|
||
namespace Anthropic.SDK.Tokens | ||
{ | ||
/// <summary> | ||
/// Helper Class to Get Token Counts | ||
/// </summary> | ||
public static class TokenHelper | ||
{ | ||
private static readonly Tokenizer Tokenizer; | ||
static TokenHelper() | ||
{ | ||
var vocabFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Tokens", "anthropic_vocab.json"); | ||
var mergesFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Tokens", "anthropic_merges.txt"); | ||
Tokenizer = new Tokenizer(new Bpe(vocabFilePath, mergesFilePath, null, null), RobertaPreTokenizer.Instance); | ||
} | ||
|
||
|
||
/// <summary> | ||
/// Gets Token Count of Input String | ||
/// </summary> | ||
/// <param name="input"></param> | ||
/// <returns></returns> | ||
public static int GetClaudeTokenCount(this string input) | ||
{ | ||
return Tokenizer.Encode(input).Tokens.Count; | ||
} | ||
} | ||
} |
Oops, something went wrong.