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):
    create_structure: 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 = self.create_structure().run(*[arg.value for arg in args])
        finally:
            os.environ.clear()
            os.environ.update(old_env)

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

create_structure: 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 = self.create_structure().run(*[arg.value for arg in args])
    finally:
        os.environ.clear()
        os.environ.update(old_env)

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