support tts

This commit is contained in:
CaIon
2023-11-15 21:05:14 +08:00
parent 16ad764f9b
commit 63cd3f05f2
7 changed files with 81 additions and 13 deletions

View File

@@ -10,6 +10,7 @@ import (
"one-api/common"
"strconv"
"strings"
"unicode/utf8"
)
var stopFinishReason = "stop"
@@ -106,6 +107,14 @@ func countTokenInput(input any, model string) int {
return 0
}
func countAudioToken(text string, model string) int {
if strings.HasPrefix(model, "tts") {
return utf8.RuneCountInString(text)
} else {
return countTokenText(text, model)
}
}
func countTokenText(text string, model string) int {
tokenEncoder := getTokenEncoder(model)
return getTokenNum(tokenEncoder, text)