automatically set num_keep if num_keep < 0

num_keep defines how many tokens to keep in the context when truncating
inputs. if left to its default value of -1, the server will calculate
num_keep to be the left of the system instructions
This commit is contained in:
Michael Yang
2023-08-07 14:51:31 -07:00
parent 089d03bc8d
commit 4dc5b117dd
3 changed files with 28 additions and 14 deletions

View File

@@ -78,6 +78,25 @@ func GenerateHandler(c *gin.Context) {
return
}
if opts.NumKeep < 0 {
promptWithSystem, err := model.Prompt(api.GenerateRequest{})
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
promptNoSystem, err := model.Prompt(api.GenerateRequest{Context: []int{0}})
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
tokensWithSystem := llm.Encode(promptWithSystem)
tokensNoSystem := llm.Encode(promptNoSystem)
llm.NumKeep = len(tokensWithSystem) - len(tokensNoSystem) + 1
}
loaded.llm = llm
loaded.digest = model.Digest
loaded.options = opts