Route creative chat by meaning
This commit is contained in:
@@ -495,6 +495,9 @@ func capabilityHintsFor(primary, secondary interaction.SpeechAct, tokens []strin
|
||||
if sourceDependentQuestion(primary, secondary, tokens) {
|
||||
add("WEB_RESEARCH")
|
||||
}
|
||||
if isCreativeRequestTokens(tokens) {
|
||||
add("COGNITIVE_REASONING")
|
||||
}
|
||||
if containsToken(tokens, "напомни") || containsToken(tokens, "напомин") {
|
||||
add("SCHEDULE_REMINDER")
|
||||
}
|
||||
@@ -536,6 +539,14 @@ func capabilityHintsFor(primary, secondary interaction.SpeechAct, tokens []strin
|
||||
return values
|
||||
}
|
||||
|
||||
func isCreativeRequestTokens(tokens []string) bool {
|
||||
if containsStemInTokens(tokens, "нарис", "рису", "изобраз") {
|
||||
return true
|
||||
}
|
||||
return containsStemInTokens(tokens, "расска", "раска", "сочин", "придум") &&
|
||||
containsStemInTokens(tokens, "сказк", "истор", "стих", "шутк", "песн", "басн")
|
||||
}
|
||||
|
||||
// sourceDependentQuestion identifies semantic classes whose answer depends on
|
||||
// a current or externally observed source. It intentionally uses no named
|
||||
// place, person or one-off question branch; when the cue is absent the
|
||||
@@ -639,6 +650,24 @@ func LocationContextReply(message string) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// IsCreativeRequest recognizes generation requests rather than retrieval of
|
||||
// externally verifiable facts. The cognitive route remains responsible for
|
||||
// the requested style and content.
|
||||
func IsCreativeRequest(message string) bool {
|
||||
tokens := semanticTokens(message)
|
||||
return isCreativeRequestTokens(tokens)
|
||||
}
|
||||
|
||||
// CreativeDeterministicReply covers simple geometric sketches that do not
|
||||
// need a model or external source. Rich creative content remains cognitive.
|
||||
func CreativeDeterministicReply(message string) string {
|
||||
tokens := semanticTokens(message)
|
||||
if containsStemInTokens(tokens, "нарис", "рису", "изобраз") && containsStemInTokens(tokens, "круг", "окруж") {
|
||||
return "◯"
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func boundedConfidence(primaryScore, secondaryScore int, scores map[interaction.SpeechAct]int) int64 {
|
||||
total := 0
|
||||
for _, score := range scores {
|
||||
@@ -818,3 +847,9 @@ func removeCapabilityHint(values []string, denied string) []string {
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// RemoveCapabilityHint lets orchestration boundaries suppress a route that
|
||||
// contradicts an already understood semantic class.
|
||||
func RemoveCapabilityHint(values []string, denied string) []string {
|
||||
return removeCapabilityHint(values, denied)
|
||||
}
|
||||
|
||||
@@ -215,6 +215,45 @@ func TestMemoryInventoryRequestIsSemantic(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreativeRequestsDoNotRouteToWebResearch(t *testing.T) {
|
||||
for _, message := range []string{"нарисуй круг", "расскажи сказку о колобке"} {
|
||||
candidate := BuildDeterministicCandidate(message, "", time.Now().UnixMilli())
|
||||
t.Logf("%q candidate=%+v", message, candidate)
|
||||
for _, hint := range candidate.CapabilityHints {
|
||||
if hint == "WEB_RESEARCH" {
|
||||
t.Fatalf("creative request %q unexpectedly selected web research: %+v", message, candidate)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestInterpretCreativeRequestDoesNotRequireExternalEvidence(t *testing.T) {
|
||||
utterance := interaction.HumanUtterance{Content: "нарисуй круг"}
|
||||
result, err := InterpretUtterance(utterance, nil, nil, time.Now())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Logf("semantic result=%+v", result)
|
||||
if result.Interpretation.SpeechAct == interaction.SpeechActQuestion || containsString(result.CapabilityHints, "WEB_RESEARCH") {
|
||||
t.Fatalf("creative request was routed as external research: %+v", result)
|
||||
}
|
||||
if got := CreativeDeterministicReply("нарисуй круг"); got != "◯" {
|
||||
t.Fatalf("circle reply = %q", got)
|
||||
}
|
||||
if !IsCreativeRequest("расскажи сказку о колобке") {
|
||||
t.Fatal("story request was not recognized as creative")
|
||||
}
|
||||
}
|
||||
|
||||
func containsString(values []string, expected string) bool {
|
||||
for _, value := range values {
|
||||
if value == expected {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func TestLocationContextReply(t *testing.T) {
|
||||
if got := LocationContextReply("я сейчас в Москве"); got != "Запомнил: сейчас вы в Москве." {
|
||||
t.Fatalf("unexpected location reply %q", got)
|
||||
|
||||
Reference in New Issue
Block a user