diff --git a/app/service/common.go b/app/service/common.go index 6d060fc..2543570 100644 --- a/app/service/common.go +++ b/app/service/common.go @@ -98,6 +98,12 @@ func GetAvailableClient(ctx context.Context, key string, modelName string, promp func CalculatePromptToken(inputs ...string) (promptToken int64) { for _, input := range inputs { + if len([]rune(input)) > 2500 { + // tokenizer has performance issue with large input length, use a simple method to calculate token + promptToken += int64(len([]rune(input)) / 4) + continue + } + promptToken += int64(tokenizer.MustCalToken(input)) }