Skip to content

Commit c81ee68

Browse files
committed
feat: improve error logging for token encoder initialization with offline usage guidance
1 parent ececfe5 commit c81ee68

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

relay/adaptor/openai/token.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@ package openai
33
import (
44
"errors"
55
"fmt"
6+
"math"
7+
"strings"
8+
69
"github.com/pkoukk/tiktoken-go"
10+
711
"github.com/songquanpeng/one-api/common/config"
812
"github.com/songquanpeng/one-api/common/image"
913
"github.com/songquanpeng/one-api/common/logger"
1014
billingratio "github.com/songquanpeng/one-api/relay/billing/ratio"
1115
"github.com/songquanpeng/one-api/relay/model"
12-
"math"
13-
"strings"
1416
)
1517

1618
// tokenEncoderMap won't grow after initialization
@@ -21,7 +23,8 @@ func InitTokenEncoders() {
2123
logger.SysLog("initializing token encoders")
2224
gpt35TokenEncoder, err := tiktoken.EncodingForModel("gpt-3.5-turbo")
2325
if err != nil {
24-
logger.FatalLog(fmt.Sprintf("failed to get gpt-3.5-turbo token encoder: %s", err.Error()))
26+
logger.FatalLog(fmt.Sprintf("failed to get gpt-3.5-turbo token encoder: %s, "+
27+
"if you are using in offline environment, please set TIKTOKEN_CACHE_DIR to use exsited files, check this link for more information: https://stackoverflow.com/questions/76106366/how-to-use-tiktoken-in-offline-mode-computer ", err.Error()))
2528
}
2629
defaultTokenEncoder = gpt35TokenEncoder
2730
gpt4oTokenEncoder, err := tiktoken.EncodingForModel("gpt-4o")

0 commit comments

Comments
 (0)