from ctx import * from memory import * from memory_Context import * def ctx_test_Controller_executeFunctions_registerFunction_set( ) -> str: c = memory_createContext() ctrl = ctx_Controller(c) # Disable automatic invocation of executeFunctions. ctrl.isProcessingQueue = True ctrl.set("input", "123") @llm_by_value def processInput(c): if ( c.recentField == "input" ): c.outputHelp = "Checked" c.recentField = "outputHelp" return c #} c.recentField = "none" return c #} ctrl.registerFunction(processInput) # Apply 'input'. ctrl.executeFunctions() # Apply 'outputHelp'. ctrl.executeFunctions() if ( c.input == "123" and c.outputHelp == "Checked" ): return "OK: ctx_Controller_executeFunctions_set" #} return "ERR: ctx_Controller_executeFunctions_set" #} def ctx_test_Controller_processQueue( ) -> str: c = memory_createContext() ctrl = ctx_Controller(c) @llm_by_value def processInput(c): if ( c.recentField == "input" ): c.outputHelp = "Checked" c.recentField = "outputHelp" return c #} c.recentField = "none" return c #} ctrl.registerFunction(processInput) ctrl.set("input", "abc"); if ( c.input == "abc" and c.outputHelp == "Checked" ): return "OK: ctx_Controller_processQueue" #} return "ERR: ctx_Controller_processQueue" #} def ctx_test_Controller_registerFieldCallback_match( ) -> str: c = memory_createContext() ctrl = ctx_Controller(c) c.input = "123" c.recentField = "input" globals()["callbackInput"] = "" def setCallbackInput(c): if ( c.recentField == "input" ): globals()["callbackInput"] = c.input ctrl.registerFieldCallback("input", setCallbackInput) ctrl.reportContext() if ( c.input == globals()["callbackInput"] ): return "OK: ctx_Controller_registerFieldCallback_match" #} return "ERR: ctx_Controller_registerFieldCallback_match" #} def ctx_test_Controller_registerFieldCallback_mismatch( ) -> str: c = memory_createContext() ctrl = ctx_Controller(c) c.input = "123" c.outputHelp = "you" # A field other than 'input' is marked recent. c.recentField = "outputHelp" globals()["callbackInput"] = "" def setCallbackInput(c): if ( c.recentField == "input" ): globals()["callbackInput"] = c.input ctrl.registerFieldCallback("input", setCallbackInput) ctrl.reportContext() if ( globals()["callbackInput"] == "" ): return "OK: ctx_Controller_registerFieldCallback_mismatch" #} return "ERR: ctx_Controller_registerFieldCallback_mismatch" #} def ctx_test_memoryContext_field( ) -> str: c = memory_createContext() c.input = "abc" if ( c.field("input") == "abc" ): return "OK: ctx_memoryContext_field" #} return "ERR: ctx_memoryContext_field" #} def ctx_test_memoryContext_setField( ) -> str: c = memory_createContext() c.input = "abc" c.setField("input", "123") if ( c.input == "123" ): return "OK: ctx_memoryContext_setField" #} return "ERR: ctx_memoryContext_setField" #}