Ask departure city for general travel requests #330

Merged
m merged 1 commits from codex/chat-semantic-inventory into main 2026-08-25 04:13:56 +00:00
2 changed files with 21 additions and 0 deletions
@@ -109,6 +109,9 @@ func TestTravelSearchClarification(t *testing.T) {
if got := TravelSearchClarification("какая погода в Сочи?", history); got != "" {
t.Fatalf("unrelated question must not inherit travel goal, got %q", got)
}
if got := TravelSearchClarification("Как можно добраться до Сочи?", nil); got != "Из какого города выезжать в Сочи? Подберу самолёт, поезд, автобус или машину." {
t.Fatalf("general travel question should ask departure city, got %q", got)
}
contextHistory := []interaction.HumanUtterance{{Content: "Как можно добраться до Сочи?"}}
if got := TravelSearchClarification("Найди билеты, какой ближайший самолёт", contextHistory); got != "Из какого города вылетать в Сочи и на какую дату?" {
t.Fatalf("travel destination should be inherited from context, got %q", got)
+18
View File
@@ -97,6 +97,9 @@ func ContinueLocalSearch(message string, history []interaction.HumanUtterance) s
func TravelSearchClarification(message string, history []interaction.HumanUtterance) string {
current := semanticTokens(StripAssistantVocative(message))
travel := travelCue(current)
if !travel {
travel = containsStemInTokens(current, "добрат", "передвиг", "поех", "дорог")
}
if !travel && travelFollowUpCue(current) {
for index := len(history) - 1; index >= 0; index-- {
if travelCue(semanticTokens(history[index].Content)) {
@@ -134,6 +137,9 @@ func TravelSearchClarification(message string, history []interaction.HumanUttera
}
}
if destination && !origin && !date {
if !containsStemInTokens(current, "билет", "рейс", "самолет", "самолёт", "вылет") {
return "Из какого города выезжать в " + destinationLabel(current, history) + "? Подберу самолёт, поезд, автобус или машину."
}
return "Из какого города вылетать и на какую дату?"
}
if destination && !origin {
@@ -145,6 +151,18 @@ func TravelSearchClarification(message string, history []interaction.HumanUttera
return "Уточните маршрут и дату: откуда, куда и на какой день нужны билеты?"
}
func destinationLabel(current []string, history []interaction.HumanUtterance) string {
for index, token := range current {
if (token == "в" || token == "до") && index+1 < len(current) {
return capitalizeWord(current[index+1])
}
}
if destination := travelContextDestination(history); destination != "" {
return destination
}
return "пункт назначения"
}
func travelContextDestination(history []interaction.HumanUtterance) string {
for index := len(history) - 1; index >= 0; index-- {
tokens := semanticTokens(history[index].Content)