Polish web research answers and travel context
This commit is contained in:
@@ -109,6 +109,10 @@ func TestTravelSearchClarification(t *testing.T) {
|
||||
if got := TravelSearchClarification("какая погода в Сочи?", history); got != "" {
|
||||
t.Fatalf("unrelated question must not inherit travel goal, got %q", got)
|
||||
}
|
||||
contextHistory := []interaction.HumanUtterance{{Content: "Как можно добраться до Сочи?"}}
|
||||
if got := TravelSearchClarification("Найди билеты, какой ближайший самолёт", contextHistory); got != "Из какого города вылетать в Сочи и на какую дату?" {
|
||||
t.Fatalf("travel destination should be inherited from context, got %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInterpretUtteranceDirectiveRecordsOutcomeWithoutExecution(t *testing.T) {
|
||||
|
||||
@@ -122,9 +122,52 @@ func TravelSearchClarification(message string, history []interaction.HumanUttera
|
||||
if origin && destination && date {
|
||||
return ""
|
||||
}
|
||||
if !destination {
|
||||
if contextDestination := travelContextDestination(history); contextDestination != "" {
|
||||
destination = true
|
||||
if !origin && !date {
|
||||
return "Из какого города вылетать в " + contextDestination + " и на какую дату?"
|
||||
}
|
||||
if !origin {
|
||||
return "Из какого города вылетать в " + contextDestination + "?"
|
||||
}
|
||||
}
|
||||
}
|
||||
if destination && !origin && !date {
|
||||
return "Из какого города вылетать и на какую дату?"
|
||||
}
|
||||
if destination && !origin {
|
||||
return "Из какого города вылетать?"
|
||||
}
|
||||
if destination && !date {
|
||||
return "На какую дату нужны билеты?"
|
||||
}
|
||||
return "Уточните маршрут и дату: откуда, куда и на какой день нужны билеты?"
|
||||
}
|
||||
|
||||
func travelContextDestination(history []interaction.HumanUtterance) string {
|
||||
for index := len(history) - 1; index >= 0; index-- {
|
||||
tokens := semanticTokens(history[index].Content)
|
||||
for tokenIndex, token := range tokens {
|
||||
if token != "в" && token != "до" {
|
||||
continue
|
||||
}
|
||||
if tokenIndex+1 < len(tokens) && len([]rune(tokens[tokenIndex+1])) >= 3 {
|
||||
return capitalizeWord(tokens[tokenIndex+1])
|
||||
}
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func capitalizeWord(value string) string {
|
||||
runes := []rune(value)
|
||||
if len(runes) == 0 {
|
||||
return value
|
||||
}
|
||||
return strings.ToUpper(string(runes[0])) + string(runes[1:])
|
||||
}
|
||||
|
||||
func travelCue(tokens []string) bool {
|
||||
return containsStemInTokens(tokens, "билет", "рейс", "поезд", "автобус", "перелет", "перелёт")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user