Skip to content

Local structure run driver

LocalStructureRunDriver

Bases: BaseStructureRunDriver

Source code in griptape/drivers/structure_run/local_structure_run_driver.py
@define
class LocalStructureRunDriver(BaseStructureRunDriver):
    structure_factory_fn: Callable[[], Structure] = field(kw_only=True)

    def try_run(self, *args: BaseArtifact) -> BaseArtifact:
        old_env = os.environ.copy()
        try:
            os.environ.update(self.env)
            structure_factory_fn = self.structure_factory_fn().run(*[arg.value for arg in args])
        finally:
            os.environ.clear()
            os.environ.update(old_env)

        if structure_factory_fn.output_task.output is not None:
            return structure_factory_fn.output_task.output
        else:
            return InfoArtifact("No output found in response")

structure_factory_fn: Callable[[], Structure] = field(kw_only=True) class-attribute instance-attribute

try_run(*args)

Source code in griptape/drivers/structure_run/local_structure_run_driver.py
def try_run(self, *args: BaseArtifact) -> BaseArtifact:
    old_env = os.environ.copy()
    try:
        os.environ.update(self.env)
        structure_factory_fn = self.structure_factory_fn().run(*[arg.value for arg in args])
    finally:
        os.environ.clear()
        os.environ.update(old_env)

    if structure_factory_fn.output_task.output is not None:
        return structure_factory_fn.output_task.output
    else:
        return InfoArtifact("No output found in response")