SourceCodeVerbalizer
relationalai.agent.cortex.verbalize
SourceCodeVerbalizer(model: relationalai.semantics.Model, *modules: Any)Verbalizer that uses relationship readings for model-level explanations and returns Python source code for concept-level explanations.
Extends ModelVerbalizer. The explain_model method is inherited
and returns sorted relationship readings. The explain_concept method
filters the provided modules to those that reference the requested concept
and returns their source code.
Leading indentation is normalized and excessive newlines are collapsed for cleaner presentation.
Parameters
Section titled “Parameters”
(modelModel) - RAI Model to verbalize.
(*modulesAny, default:()) - Variable number of Python callables (functions, classes) or modules containing model definitions. Each must have retrievable source code viainspect.getsource(). Built-ins without source are silently skipped.
Examples
Section titled “Examples”>>> from myproject.model import define_customer, define_order>>> verbalizer = SourceCodeVerbalizer(model, define_customer, define_order)>>> print(verbalizer.explain_concept("Customer"))def define_customer(model): ...Methods
Section titled “Methods”.explain_concept()
Section titled “.explain_concept()”SourceCodeVerbalizer.explain_concept(concept: str) -> strExtract source code from modules that reference the given concept.
Filters to only include modules where the concept name appears in source code.
Parameters:
(conceptstr) - Concept name to search for in the source code.
Returns:
str- Concatenated source code from matching modules with normalized formatting. Returns"Could not explain {concept}"if no modules contain the concept.