Continue local search from conversation context
This commit is contained in:
@@ -85,6 +85,16 @@ func TestLocalSearchClarification(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestContinueLocalSearch(t *testing.T) {
|
||||
history := []interaction.HumanUtterance{{Content: "Найди ближайший ресторан"}}
|
||||
if got := ContinueLocalSearch("в Сочи", history); got != "Найди ближайший ресторан в Сочи" {
|
||||
t.Fatalf("unexpected continuation: %q", got)
|
||||
}
|
||||
if got := ContinueLocalSearch("в Сочи", nil); got != "" {
|
||||
t.Fatalf("location must not create a goal without conversation context: %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTravelSearchClarification(t *testing.T) {
|
||||
if got := TravelSearchClarification("Найди билеты", nil); got == "" {
|
||||
t.Fatal("underspecified travel request must ask for missing route and date")
|
||||
|
||||
@@ -65,6 +65,24 @@ func LocalSearchClarification(message string) string {
|
||||
return "В каком городе или районе искать ресторан?"
|
||||
}
|
||||
|
||||
// ContinueLocalSearch turns a location-only follow-up into the previous local
|
||||
// search request, but only when that request is present in this conversation.
|
||||
func ContinueLocalSearch(message string, history []interaction.HumanUtterance) string {
|
||||
current := strings.TrimSpace(StripAssistantVocative(message))
|
||||
tokens := semanticTokens(current)
|
||||
if len(tokens) == 0 || len(tokens) > 3 || (tokens[0] != "в" && tokens[0] != "на" && tokens[0] != "около") {
|
||||
return ""
|
||||
}
|
||||
for index := len(history) - 1; index >= 0; index-- {
|
||||
previous := strings.TrimSpace(StripAssistantVocative(history[index].Content))
|
||||
previousTokens := semanticTokens(previous)
|
||||
if containsStemInTokens(previousTokens, "ресторан", "кафе") && containsStemInTokens(previousTokens, "ближ", "рядом") {
|
||||
return strings.TrimSpace(previous + " " + current)
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// TravelSearchClarification keeps an incomplete travel request in dialogue
|
||||
// instead of reducing it to an unrelated generic web search.
|
||||
func TravelSearchClarification(message string, history []interaction.HumanUtterance) string {
|
||||
|
||||
Reference in New Issue
Block a user