Merge the clarify and voice sweep (#228)
chatHistory's doc comment pointed at a line range that had moved. It now names runTurn's step 6, which survives the next edit. chatHistory and rememberTurn each built the same dialogue.Turn projection inline; one sessionAsTurn helper now serves both. The history cap was a bare 3 with no tie to the four turns both doc comments quote. The clarify decision points are left untouched. V-577 and V-579 own them. (V-581)
This commit is contained in:
@@ -527,20 +527,22 @@ func (h *reactiveHandler) finishClarified(ctx context.Context, dec router.Decisi
|
|||||||
return reply
|
return reply
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// maxCarriedHistory — how many turns of PRIOR history (beyond the immediate
|
||||||
|
// last turn) rememberTurn carries forward. The session ends up holding this
|
||||||
|
// many plus the one just-finished turn, so callers describing the total
|
||||||
|
// depth (chatHistory's doc comment, this one) say "up to 4".
|
||||||
|
const maxCarriedHistory = 3
|
||||||
|
|
||||||
// rememberTurn stores this turn as the dialogue session the next follow-up
|
// rememberTurn stores this turn as the dialogue session the next follow-up
|
||||||
// inherits from, carrying up to 4 prior turns of history for anaphora. Capped so
|
// inherits from, carrying up to 4 prior turns of history for anaphora. Capped so
|
||||||
// one long conversation can't grow the session unboundedly.
|
// one long conversation can't grow the session unboundedly.
|
||||||
func (h *reactiveHandler) rememberTurn(ctx context.Context, prev *dialogue.Session, dec router.Decision, now time.Time) {
|
func (h *reactiveHandler) rememberTurn(ctx context.Context, prev *dialogue.Session, dec router.Decision, now time.Time) {
|
||||||
var history []dialogue.Turn
|
var history []dialogue.Turn
|
||||||
if prev != nil {
|
if prev != nil {
|
||||||
history = append(history, dialogue.Turn{
|
history = append(history, sessionAsTurn(prev))
|
||||||
Intent: prev.Intent,
|
|
||||||
Slots: prev.Slots,
|
|
||||||
Text: prev.Slots.Text,
|
|
||||||
})
|
|
||||||
maxHist := len(prev.History)
|
maxHist := len(prev.History)
|
||||||
if maxHist > 3 {
|
if maxHist > maxCarriedHistory {
|
||||||
maxHist = 3
|
maxHist = maxCarriedHistory
|
||||||
}
|
}
|
||||||
history = append(history, prev.History[:maxHist]...)
|
history = append(history, prev.History[:maxHist]...)
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-6
@@ -528,6 +528,17 @@ func (h *reactiveHandler) replySystem(ctx context.Context, dec router.Decision)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// sessionAsTurn projects a stored session onto the dialogue.Turn shape used in
|
||||||
|
// history lists. Shared by chatHistory and rememberTurn (clarify.go) so the
|
||||||
|
// same session is described the same way in both places.
|
||||||
|
func sessionAsTurn(s *dialogue.Session) dialogue.Turn {
|
||||||
|
return dialogue.Turn{
|
||||||
|
Intent: s.Intent,
|
||||||
|
Slots: s.Slots,
|
||||||
|
Text: s.Slots.Text,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// chatHistory collects dialogue turns from the session store for the current
|
// chatHistory collects dialogue turns from the session store for the current
|
||||||
// conversation. Returns prior user utterances (newest last) up to a depth of
|
// conversation. Returns prior user utterances (newest last) up to a depth of
|
||||||
// 4 turns. Returns nil when there's no session or no history.
|
// 4 turns. Returns nil when there's no session or no history.
|
||||||
@@ -541,13 +552,9 @@ func (h *reactiveHandler) chatHistory(ctx context.Context) []dialogue.Turn {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
// History already includes the immediate prior turn (set by the dialogue
|
// History already includes the immediate prior turn (set by the dialogue
|
||||||
// merge at lines 373-395), plus up to 3 more from deeper history.
|
// merge in runTurn's step 6, above), plus up to 3 more from deeper history.
|
||||||
out := make([]dialogue.Turn, 0, 1+len(prev.History))
|
out := make([]dialogue.Turn, 0, 1+len(prev.History))
|
||||||
out = append(out, dialogue.Turn{
|
out = append(out, sessionAsTurn(prev))
|
||||||
Intent: prev.Intent,
|
|
||||||
Slots: prev.Slots,
|
|
||||||
Text: prev.Slots.Text,
|
|
||||||
})
|
|
||||||
out = append(out, prev.History...)
|
out = append(out, prev.History...)
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user