|
|
|
|
@ -153,7 +153,7 @@ func numTokensFromMessages(messages []Message, model string) int {
|
|
|
|
|
tkm, err := tiktoken.EncodingForModel(model)
|
|
|
|
|
if err != nil {
|
|
|
|
|
err = fmt.Errorf("getEncoding: %v", err)
|
|
|
|
|
panic(err)
|
|
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
numTokens := 0
|
|
|
|
|
for _, message := range messages {
|
|
|
|
|
@ -169,7 +169,7 @@ func numTokensFromString(msg string, model string) int {
|
|
|
|
|
tkm, err := tiktoken.EncodingForModel(model)
|
|
|
|
|
if err != nil {
|
|
|
|
|
err = fmt.Errorf("getEncoding: %v", err)
|
|
|
|
|
panic(err)
|
|
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
if model == "text-davinci-003" {
|
|
|
|
|
return len(tkm.Encode(msg, nil, nil)) + 1
|
|
|
|
|
@ -201,7 +201,8 @@ func embeddings(c *gin.Context) {
|
|
|
|
|
|
|
|
|
|
remote, err := url.Parse(serverInfo.ServerAddress)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
c.AbortWithStatusJSON(400, gin.H{"error": err.Error()})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
proxy := httputil.NewSingleHostReverseProxy(remote)
|
|
|
|
|
@ -283,7 +284,8 @@ func completions(c *gin.Context) {
|
|
|
|
|
|
|
|
|
|
remote, err := url.Parse(serverInfo.ServerAddress)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
c.AbortWithStatusJSON(400, gin.H{"error": err.Error()})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
proxy := httputil.NewSingleHostReverseProxy(remote)
|
|
|
|
|
|