@@ -35,6 +35,16 @@ const questions = [
3535 { name : "refund" , type : "predicate" , instructions : "Is the customer asking for a refund?" } ,
3636] as const
3737
38+ const defect = {
39+ name : "defect" ,
40+ type : "predicate" ,
41+ instructions : "Is the customer reporting a product defect?" ,
42+ criteria : {
43+ true : "The product itself is broken or faulty." ,
44+ false : "Preference, sizing, shipping, or pricing complaint." ,
45+ } ,
46+ } as const
47+
3848const systemOneAnswers = {
3949 department : { type : "choice" , choice : "billing" , probabilities : { technical : 0.1 , billing : 0.9 } , confidence : 0.8 } ,
4050 urgency : {
@@ -516,6 +526,76 @@ describe("Decision", () => {
516526 ) ,
517527 )
518528
529+ it . effect ( "sends predicate criteria as System One criteria" , ( ) =>
530+ ai . decision
531+ . generate ( {
532+ model : TypeSafeAI . configure ( { apiKey : "test" } ) . decision ( "jev-latest" ) ,
533+ input : [ { type : "text" , text : "I returned the sweater because I prefer green." } ] ,
534+ questions : [ defect ] ,
535+ } )
536+ . pipe (
537+ Effect . tap ( ( response ) =>
538+ Effect . sync ( ( ) =>
539+ expect ( response . answers ) . toEqual ( [ { name : "defect" , type : "predicate" , probability : 0.03 } ] ) ,
540+ ) ,
541+ ) ,
542+ Effect . provide (
543+ client ( ( input ) => {
544+ expect ( JSON . parse ( input . text ) . questions ) . toEqual ( {
545+ defect : {
546+ type : "noul" ,
547+ instructions : "Is the customer reporting a product defect?" ,
548+ criteria : {
549+ true : "The product itself is broken or faulty." ,
550+ false : "Preference, sizing, shipping, or pricing complaint." ,
551+ } ,
552+ } ,
553+ } )
554+ return Effect . succeed (
555+ json ( input , { model : "jev-latest" , answers : { defect : { type : "noul" , noul : 0.03 } } } ) ,
556+ )
557+ } ) ,
558+ ) ,
559+ ) ,
560+ )
561+
562+ it . effect ( "appends predicate criteria to OpenAI Decisions instructions" , ( ) =>
563+ ai . decision
564+ . generate ( {
565+ model : OpenAI . configure ( { apiKey : "openai-key" } ) . decision ( "gpt-6-luna" ) ,
566+ input : [ { type : "text" , text : "I returned the sweater because I prefer green." } ] ,
567+ questions : [ defect , { ...defect , name : "only_true" , criteria : { true : "The product is broken." } } ] ,
568+ } )
569+ . pipe (
570+ Effect . provide (
571+ client ( ( input ) => {
572+ expect ( JSON . parse ( input . text ) . questions ) . toEqual ( [
573+ {
574+ name : "defect" ,
575+ type : "predicate" ,
576+ instructions :
577+ "Is the customer reporting a product defect?\n\nTrue means: The product itself is broken or faulty.\nFalse means: Preference, sizing, shipping, or pricing complaint." ,
578+ } ,
579+ {
580+ name : "only_true" ,
581+ type : "predicate" ,
582+ instructions : "Is the customer reporting a product defect?\n\nTrue means: The product is broken." ,
583+ } ,
584+ ] )
585+ return Effect . succeed (
586+ json ( input , {
587+ model : "gpt-6-luna" ,
588+ answers : [
589+ { type : "predicate" , name : "defect" , probability : 0.03 } ,
590+ { type : "predicate" , name : "only_true" , probability : 0.04 } ,
591+ ] ,
592+ } ) ,
593+ )
594+ } ) ,
595+ ) ,
596+ ) ,
597+ )
598+
519599 it . effect ( "puts media in Clef's top-level lists on Cloudflare Run" , ( ) =>
520600 ai . decision
521601 . generate ( {
0 commit comments