Skip to content

Commit

Permalink
Fix panic on no autosuggest encoder found
Browse files Browse the repository at this point in the history
  • Loading branch information
bakks committed May 21, 2024
1 parent 1016527 commit 815d6de
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions butterfish/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -2000,7 +2000,8 @@ func (this *ShellState) RequestAutosuggest(delay time.Duration, command string)
this.Butterfish.Config.Verbose > 1,
this.History,
this.Butterfish.Config.ShellMaxHistoryBlockTokens,
this.AutosuggestChan)
this.AutosuggestChan,
this.getAutosuggestEncoder())

}

Expand All @@ -2016,7 +2017,9 @@ func RequestCancelableAutosuggest(
verbose bool,
history *ShellHistory,
maxHistoryBlockTokens int,
autosuggestChan chan<- *AutosuggestResult) {
autosuggestChan chan<- *AutosuggestResult,
encoder *tiktoken.Tiktoken,
) {

if delay > 0 {
time.Sleep(delay)
Expand All @@ -2027,11 +2030,7 @@ func RequestCancelableAutosuggest(

totalTokens := 1600 // limit autosuggest to 1600 tokens for cost reasons
reserveForAnswer := 64

encoder, err := tiktoken.EncodingForModel(model)
if err != nil {
panic(fmt.Sprintf("Error getting encoder for prompt model %s: %s", model, err))
}
var err error

historyBlocks, _ := getHistoryBlocksByTokens(history, encoder,
maxHistoryBlockTokens, totalTokens-reserveForAnswer, 4)
Expand Down

0 comments on commit 815d6de

Please sign in to comment.