Skip to content

SWE-agent takes a GitHub issue and tries to automatically fix it, using your LM of choice. It can also be employed for offensive cybersecurity or competitive coding challenges. [NeurIPS 2024]

Enh(tools): Fall back to env variables with registry.get

Kilian Lieret938cc4fb3bbe
diff --git a/tools/registry/lib/registry.py b/tools/registry/lib/registry.py
index 18764989..3e225ede 100644
--- a/tools/registry/lib/registry.py
+++ b/tools/registry/lib/registry.py
@@ -29,7 +29,17 @@ class EnvRegistry:
def __getitem__(self, key: str) -> str:
return json.loads(self.env_file.read_text())[key]
- def get(self, key: str, default_value: Any = None) -> Any:
+ def get(self, key: str, default_value: Any = None, fallback_to_env: bool = True) -> Any:
+ """Get a value from registry:
+
+ Args:
+ key: The key to get the value for.
+ default_value: The default value to return if the key is not found in the registry.
+ fallback_to_env: If True, fallback to environment variables if the key is not found in the registry.
+ If there's no environment variable, return the default value.
+ """
+ if fallback_to_env and key in os.environ:
+ default_value = os.environ[key]
return json.loads(self.env_file.read_text()).get(key, default_value)
def get_if_none(self, value: Any, key: str, default_value: Any = None) -> Any: