Spaces:
Build error
Build error
Download executor.py from agora-protocol/agora-demo: direct link, hf CLI and curl.
- Browser
- Download file 863 Bytes
-
https://huggingface.co/spaces/agora-protocol/agora-demo/resolve/main/executor.py
- Command line
-
hf download hf://spaces/agora-protocol/agora-demo/executor.py
-
curl -L -o executor.py https://huggingface.co/spaces/agora-protocol/agora-demo/resolve/main/executor.py
863 Bytes
| from abc import abstractmethod | |
| import importlib | |
| from typing import List | |
| from toolformers.base import Tool | |
| class Executor: | |
| def run_routine(self, protocol_id, task_data, tools): | |
| pass | |
| class UnsafeExecutor(Executor): | |
| def run_routine(self, protocol_id, code, task_data, tools : List[Tool]): | |
| protocol_id = protocol_id.replace('-', '_').replace('.', '_').replace('/', '_') | |
| # TODO: This should be done in a safe, containerized environment | |
| spec = importlib.util.spec_from_loader(protocol_id, loader=None) | |
| loaded_module = importlib.util.module_from_spec(spec) | |
| #spec.loader.exec_module(loaded_module) | |
| exec(code, loaded_module.__dict__) | |
| for tool in tools: | |
| loaded_module.__dict__[tool.name] = tool.as_executable_function() | |
| return loaded_module.run(task_data) |