fix: 修复流式对话日志丢失问题
This commit is contained in:
parent
3a7925fb55
commit
4452fb1568
|
|
@ -284,14 +284,42 @@ func (d *Do) startMessageHandler(
|
|||
|
||||
}()
|
||||
|
||||
streamText := ""
|
||||
streamIndex := ""
|
||||
for v := range requireData.Ch { // 自动检测通道关闭
|
||||
if err := sendWithTimeout(client, v, 10*time.Second); err != nil {
|
||||
log.Errorf("Send error: %v", err)
|
||||
return
|
||||
}
|
||||
if v.Type == entitys.ResponseText || v.Type == entitys.ResponseStream || v.Type == entitys.ResponseJson {
|
||||
// 文本+卡片
|
||||
if v.Type == entitys.ResponseText || v.Type == entitys.ResponseJson {
|
||||
chat = append(chat, v)
|
||||
}
|
||||
// 流式-追加
|
||||
if v.Type == entitys.ResponseStream {
|
||||
streamText += v.Content
|
||||
streamIndex = v.Index
|
||||
}
|
||||
// 流式-阶段结束|对话结束
|
||||
if streamText != "" && v.Type != entitys.ResponseStream {
|
||||
chat = append(chat, entitys.Response{
|
||||
Content: streamText,
|
||||
Type: entitys.ResponseText,
|
||||
Index: streamIndex,
|
||||
})
|
||||
streamText = ""
|
||||
streamIndex = ""
|
||||
}
|
||||
}
|
||||
// 流式结束
|
||||
if streamText != "" {
|
||||
chat = append(chat, entitys.Response{
|
||||
Content: streamText,
|
||||
Type: entitys.ResponseText,
|
||||
Index: streamIndex,
|
||||
})
|
||||
streamText = ""
|
||||
streamIndex = ""
|
||||
}
|
||||
}()
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue