Merge pull request #306 from jmorganca/default-keep-system

automatically set num_keep if num_keep < 0
This commit is contained in:
Michael Yang
2023-08-08 09:25:34 -07:00
committed by GitHub
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