Route creative requests through cognition #357
@@ -73,14 +73,10 @@ func TestHouseholdBearDrawingUsesCreativeLocalRoute(t *testing.T) {
|
||||
t.Fatalf("bear drawing selected web research: %+v", candidate)
|
||||
}
|
||||
}
|
||||
if got := interactiondomain.CreativeDeterministicReply("нарисуй бурого медведя"); got != "🐻" {
|
||||
t.Fatalf("bear drawing fallback=%q", got)
|
||||
}
|
||||
if got := interactiondomain.CreativeDeterministicReply("нарисуй птицу"); got != "🐦" {
|
||||
t.Fatalf("bird drawing fallback=%q", got)
|
||||
}
|
||||
if got := interactiondomain.CreativeDeterministicReply("нарисуй коня"); got != "🐴" {
|
||||
t.Fatalf("horse drawing fallback=%q", got)
|
||||
for _, message := range []string{"нарисуй бурого медведя", "нарисуй птицу", "нарисуй зеленую птицу", "нарисуй птицу в HD", "нарисуй коня"} {
|
||||
if got := interactiondomain.CreativeDeterministicReply(message); got != "" {
|
||||
t.Fatalf("creative request %q received a canned reply=%q", message, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -658,33 +658,18 @@ func IsCreativeRequest(message string) bool {
|
||||
return isCreativeRequestTokens(tokens)
|
||||
}
|
||||
|
||||
// CreativeDeterministicReply covers simple geometric sketches that do not
|
||||
// need a model or external source. Rich creative content remains cognitive.
|
||||
// CreativeDeterministicReply intentionally has no example-specific answer
|
||||
// branches. Creative requests must retain their full meaning and go through
|
||||
// cognition; canned object or color answers hide lost attributes.
|
||||
func CreativeDeterministicReply(message string) string {
|
||||
tokens := semanticTokens(message)
|
||||
if containsStemInTokens(tokens, "нарис", "рису", "изобраз") && containsStemInTokens(tokens, "круг", "окруж") {
|
||||
return "◯"
|
||||
}
|
||||
if containsStemInTokens(tokens, "нарис", "рису", "изобраз") && containsStemInTokens(tokens, "медвед", "мишк") {
|
||||
return "🐻"
|
||||
}
|
||||
if containsStemInTokens(tokens, "нарис", "рису", "изобраз") && containsStemInTokens(tokens, "птиц", "птичк", "ворон", "голуб") {
|
||||
return "🐦"
|
||||
}
|
||||
if containsStemInTokens(tokens, "нарис", "рису", "изобраз") && containsStemInTokens(tokens, "кон", "лошад", "жереб") {
|
||||
return "🐴"
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// CreativeFallbackReply keeps a small creative conversation useful when the
|
||||
// cognitive channel is unavailable. It is not used when cognition returns a
|
||||
// completed richer answer.
|
||||
// CreativeFallbackReply intentionally has no canned creative content. The
|
||||
// cognitive route must construct the requested result while preserving all
|
||||
// user attributes; a degraded path must not pretend that a prepared answer
|
||||
// was generated.
|
||||
func CreativeFallbackReply(message string) string {
|
||||
tokens := semanticTokens(message)
|
||||
if IsCreativeRequest(message) && containsStemInTokens(tokens, "сказк", "басн") && containsStemInTokens(tokens, "колоб") {
|
||||
return "Жили-были дед и баба. Испекли они Колобка, а он убежал в лес. Встретил зайца, волка и медведя — от всех укатился, но лису перехитрить не смог. Так Колобок понял: хвастовство и беспечность до добра не доводят."
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package domain
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -277,23 +276,19 @@ func TestInterpretCreativeRequestDoesNotRequireExternalEvidence(t *testing.T) {
|
||||
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 got := CreativeDeterministicReply("нарисуй круг"); got != "" {
|
||||
t.Fatalf("creative request received a canned reply = %q", got)
|
||||
}
|
||||
if !IsCreativeRequest("расскажи сказку о колобке") {
|
||||
t.Fatal("story request was not recognized as creative")
|
||||
}
|
||||
if got := CreativeFallbackReply("расскажи сказку о колобке"); !strings.Contains(got, "Колоб") {
|
||||
t.Fatalf("story fallback = %q", got)
|
||||
if got := CreativeFallbackReply("расскажи сказку о колобке"); got != "" {
|
||||
t.Fatalf("creative request received canned content = %q", got)
|
||||
}
|
||||
if got := CreativeDeterministicReply("нарисуй бурого медведя"); got != "🐻" {
|
||||
t.Fatalf("bear reply = %q", got)
|
||||
}
|
||||
if got := CreativeDeterministicReply("нарисуй птицу"); got != "🐦" {
|
||||
t.Fatalf("bird reply = %q", got)
|
||||
}
|
||||
if got := CreativeDeterministicReply("нарисуй коня"); got != "🐴" {
|
||||
t.Fatalf("horse reply = %q", got)
|
||||
for _, message := range []string{"нарисуй птицу", "нарисуй зеленую птицу", "нарисуй птицу в HD", "нарисуй коня"} {
|
||||
if got := CreativeDeterministicReply(message); got != "" {
|
||||
t.Fatalf("creative request %q received a canned reply = %q", message, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user