-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit adds a CountTokens function that counts the number of tokens in a given slice of messages. The function uses the go-gpt-3-encoder package to encode the messages and count the tokens. A test for the CountTokens function is also added to the aichat_test.go file.
- Loading branch information
Showing
4 changed files
with
72 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestCountTokens(t *testing.T) { | ||
messages := []string{ | ||
"Hello, world!", | ||
"How are you?", | ||
} | ||
count, err := CountTokens(messages) | ||
if err != nil { | ||
t.Errorf("CountTokens() returned an error: %v", err) | ||
} | ||
if count != 8 { | ||
t.Errorf("CountTokens() returned %d, expected 8", count) | ||
} | ||
} |
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