Skip to content

Commit

Permalink
Fix text buffer length and debug logging in chat handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
swuecho committed Sep 15, 2024
1 parent 0ddf44e commit 47b48ca
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
9 changes: 7 additions & 2 deletions api/chat_main_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,12 @@ func (h *ChatHandler) chatStream(w http.ResponseWriter, chatSession sqlc_queries

var answer string
var answer_id string
textBuffer := newTextBuffer(int(chatSession.N), "", "")
bufferLen := int(chatSession.N)
if bufferLen == 0 {
log.Println("chatSession.N is 0")
bufferLen += 1
}
textBuffer := newTextBuffer(bufferLen, "", "")
if regenerate {
answer_id = chatUuid
}
Expand Down Expand Up @@ -574,12 +579,12 @@ func (h *ChatHandler) chatStream(w http.ResponseWriter, chatSession sqlc_queries
return "", "", true
}
}
log.Printf("%+v", response)
textIdx := response.Choices[0].Index
delta := response.Choices[0].Delta.Content
textBuffer.appendByIndex(textIdx, delta)

if chatSession.Debug {
log.Printf("%+v", response)
log.Printf("%s", delta)
}
answer = textBuffer.String("\n")
Expand Down
1 change: 1 addition & 0 deletions api/chat_session_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ func (h *ChatSessionHandler) createChatSessionFromSnapshot(w http.ResponseWriter
MaxTokens: originSession.MaxTokens,
TopP: originSession.TopP,
Debug: originSession.Debug,
N: 1,
})
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
Expand Down

0 comments on commit 47b48ca

Please sign in to comment.