Private
Public Access
1
0

Wrap chunk content in a Chunk type

Preparing to include additional information with each chunk (e.g. token
count)
This commit is contained in:
2024-06-08 23:37:58 +00:00
parent c963747066
commit d2d946b776
8 changed files with 35 additions and 20 deletions

View File

@@ -90,20 +90,19 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
case msgResponseChunk:
cmds = append(cmds, m.waitForResponseChunk()) // wait for the next chunk
chunk := string(msg)
if chunk == "" {
if msg.Content == "" {
break
}
last := len(m.messages) - 1
if last >= 0 && m.messages[last].Role.IsAssistant() {
// append chunk to existing message
m.setMessageContents(last, m.messages[last].Content+chunk)
m.setMessageContents(last, m.messages[last].Content+msg.Content)
} else {
// use chunk in new message
m.addMessage(models.Message{
Role: models.MessageRoleAssistant,
Content: chunk,
Content: msg.Content,
})
}
m.updateContent()