Ask for location before proximity search
CI / test (push) Successful in 1m3s
CI / test (pull_request) Successful in 1m2s

This commit is contained in:
m
2026-08-25 05:45:40 +03:00
parent 51e2b23082
commit 9534b041db
3 changed files with 31 additions and 0 deletions
@@ -76,6 +76,15 @@ func TestIndependentRequestParts(t *testing.T) {
}
}
func TestLocalSearchClarification(t *testing.T) {
if got := LocalSearchClarification("найди ближайший ресторан"); got == "" {
t.Fatal("proximity search without place must ask for location")
}
if got := LocalSearchClarification("найди ближайший ресторан в Сочи"); got != "" {
t.Fatalf("explicit place must proceed, got %q", got)
}
}
func TestTravelSearchClarification(t *testing.T) {
if got := TravelSearchClarification("Найди билеты", nil); got == "" {
t.Fatal("underspecified travel request must ask for missing route and date")
+18
View File
@@ -47,6 +47,24 @@ func IndependentRequestParts(message string) []string {
return result
}
// LocalSearchClarification prevents a proximity search from silently using a
// default city when the user did not provide a place.
func LocalSearchClarification(message string) string {
tokens := semanticTokens(StripAssistantVocative(message))
if !containsStemInTokens(tokens, "ресторан", "кафе") || !containsStemInTokens(tokens, "ближ", "рядом") {
return ""
}
for index, token := range tokens {
if token != "в" && token != "на" && token != "около" && !containsStem(token, "район", "город") {
continue
}
if index+1 < len(tokens) || containsStem(token, "район", "город") {
return ""
}
}
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 {