mirror of
https://github.com/yangjian102621/geekai.git
synced 2025-11-11 03:33:48 +08:00
refactor: V3 版本重构已基本完成
This commit is contained in:
17
api/go/utils/openai.go
Normal file
17
api/go/utils/openai.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/pkoukk/tiktoken-go"
|
||||
)
|
||||
|
||||
func CalcTokens(text string, model string) (int, error) {
|
||||
encoding := tiktoken.MODEL_TO_ENCODING[model]
|
||||
tke, err := tiktoken.GetEncoding(encoding)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("getEncoding: %v", err)
|
||||
}
|
||||
|
||||
token := tke.Encode(text, nil, nil)
|
||||
return len(token), nil
|
||||
}
|
||||
Reference in New Issue
Block a user