First implementation of questions management
This commit is contained in:
@@ -12,6 +12,9 @@ from core.sheerka.services.SheerkaFilter import Pipe
|
||||
from evaluators.BaseEvaluator import OneReturnValueEvaluator
|
||||
from parsers.PythonParser import PythonNode
|
||||
|
||||
TO_DISABLED = ["breakpoint", "callable", "compile", "delattr", "eval", "exec", "exit", "input", "locals", "open",
|
||||
"print", "quit", "setattr"]
|
||||
|
||||
|
||||
def inject_context(context):
|
||||
"""
|
||||
@@ -95,7 +98,7 @@ class PythonEvaluator(OneReturnValueEvaluator):
|
||||
concepts_entries = None
|
||||
evaluated = BuiltinConcepts.NOT_INITIALIZED
|
||||
errors = []
|
||||
expect_success = BuiltinConcepts.EVAL_UNTIL_SUCCESS_REQUESTED in context.local_hints
|
||||
expect_success = context.in_context(BuiltinConcepts.EVAL_UNTIL_SUCCESS_REQUESTED)
|
||||
for globals_ in all_possible_globals:
|
||||
try:
|
||||
# eval
|
||||
@@ -142,12 +145,13 @@ class PythonEvaluator(OneReturnValueEvaluator):
|
||||
my_globals = {
|
||||
"Concept": core.concept.Concept,
|
||||
"BuiltinConcepts": core.builtin_concepts.BuiltinConcepts,
|
||||
"in_context": context.in_context
|
||||
"in_context": context.in_context,
|
||||
}
|
||||
|
||||
if expression_only:
|
||||
# disable builtin
|
||||
my_globals["__builtins__"] = None
|
||||
# disable some builtin
|
||||
for statement in TO_DISABLED:
|
||||
my_globals[statement] = None
|
||||
|
||||
# has to be the first, to allow override
|
||||
method_from_sheerka = self.update_globals_with_sheerka_methods(my_globals, context, expression_only)
|
||||
@@ -164,17 +168,6 @@ class PythonEvaluator(OneReturnValueEvaluator):
|
||||
|
||||
@staticmethod
|
||||
def update_globals_with_sheerka_methods(my_locals, context, expression_only):
|
||||
# methods_from_sheerka = {}
|
||||
#
|
||||
# # Make sure that methods that need the concept are correctly wrapped
|
||||
# for method_name, method in context.sheerka.sheerka_methods.items():
|
||||
# if expression_only and method.has_side_effect:
|
||||
# continue
|
||||
#
|
||||
# if method_name in context.sheerka.methods_with_context:
|
||||
# methods_from_sheerka[method_name] = inject_context(context)(method.method)
|
||||
# else:
|
||||
# methods_from_sheerka[method_name] = method.method
|
||||
methods_from_sheerka = {}
|
||||
|
||||
# Add all the methods as a direct access
|
||||
@@ -238,6 +231,8 @@ class PythonEvaluator(OneReturnValueEvaluator):
|
||||
elif name in already_known:
|
||||
context.log(f"Already known. Skipping.", self.name)
|
||||
continue
|
||||
elif (concept := context.get_from_short_term_memory(name)) is not None:
|
||||
context.log(f"Using from STM known.", self.name)
|
||||
else:
|
||||
context.log(f"Instantiating new concept with {name}.", self.name)
|
||||
concept = self.resolve_concept(context, name)
|
||||
|
||||
Reference in New Issue
Block a user