Skip to content

Commit d2a9e54

Browse files
authored
Allow users to Disable Commands via the .env (Significant-Gravitas#3667)
1 parent d744280 commit d2a9e54

File tree

3 files changed

+51
-13
lines changed

3 files changed

+51
-13
lines changed

.env.template

+17
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,23 @@
1818
## EXIT_KEY - Key to exit AUTO-GPT
1919
# EXIT_KEY=n
2020

21+
## DISABLED_COMMAND_CATEGORIES - The list of categories of commands that are disabled. Each of the below are an option:
22+
## autogpt.commands.analyze_code
23+
## autogpt.commands.audio_text
24+
## autogpt.commands.execute_code
25+
## autogpt.commands.file_operations
26+
## autogpt.commands.git_operations
27+
## autogpt.commands.google_search
28+
## autogpt.commands.image_gen
29+
## autogpt.commands.improve_code
30+
## autogpt.commands.twitter
31+
## autogpt.commands.web_selenium
32+
## autogpt.commands.write_tests
33+
## autogpt.app
34+
## autogpt.commands.task_statuses
35+
## For example, to disable coding related features, uncomment the next line
36+
# DISABLED_COMMAND_CATEGORIES=autogpt.commands.analyze_code,autogpt.commands.execute_code,autogpt.commands.git_operations,autogpt.commands.improve_code,autogpt.commands.write_tests
37+
2138
################################################################################
2239
### LLM PROVIDER
2340
################################################################################

autogpt/config/config.py

+7
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ def __init__(self) -> None:
3030

3131
self.authorise_key = os.getenv("AUTHORISE_COMMAND_KEY", "y")
3232
self.exit_key = os.getenv("EXIT_KEY", "n")
33+
34+
disabled_command_categories = os.getenv("DISABLED_COMMAND_CATEGORIES")
35+
if disabled_command_categories:
36+
self.disabled_command_categories = disabled_command_categories.split(",")
37+
else:
38+
self.disabled_command_categories = []
39+
3340
self.ai_settings_file = os.getenv("AI_SETTINGS_FILE", "ai_settings.yaml")
3441
self.fast_llm_model = os.getenv("FAST_LLM_MODEL", "gpt-3.5-turbo")
3542
self.smart_llm_model = os.getenv("SMART_LLM_MODEL", "gpt-4")

autogpt/main.py

+27-13
Original file line numberDiff line numberDiff line change
@@ -118,19 +118,33 @@ def run_auto_gpt(
118118
cfg.set_plugins(scan_plugins(cfg, cfg.debug_mode))
119119
# Create a CommandRegistry instance and scan default folder
120120
command_registry = CommandRegistry()
121-
command_registry.import_commands("autogpt.commands.analyze_code")
122-
command_registry.import_commands("autogpt.commands.audio_text")
123-
command_registry.import_commands("autogpt.commands.execute_code")
124-
command_registry.import_commands("autogpt.commands.file_operations")
125-
command_registry.import_commands("autogpt.commands.git_operations")
126-
command_registry.import_commands("autogpt.commands.google_search")
127-
command_registry.import_commands("autogpt.commands.image_gen")
128-
command_registry.import_commands("autogpt.commands.improve_code")
129-
command_registry.import_commands("autogpt.commands.twitter")
130-
command_registry.import_commands("autogpt.commands.web_selenium")
131-
command_registry.import_commands("autogpt.commands.write_tests")
132-
command_registry.import_commands("autogpt.app")
133-
command_registry.import_commands("autogpt.commands.task_statuses")
121+
122+
command_categories = [
123+
"autogpt.commands.analyze_code",
124+
"autogpt.commands.audio_text",
125+
"autogpt.commands.execute_code",
126+
"autogpt.commands.file_operations",
127+
"autogpt.commands.git_operations",
128+
"autogpt.commands.google_search",
129+
"autogpt.commands.image_gen",
130+
"autogpt.commands.improve_code",
131+
"autogpt.commands.twitter",
132+
"autogpt.commands.web_selenium",
133+
"autogpt.commands.write_tests",
134+
"autogpt.app",
135+
"autogpt.commands.task_statuses",
136+
]
137+
logger.debug(
138+
f"The following command categories are disabled: {cfg.disabled_command_categories}"
139+
)
140+
command_categories = [
141+
x for x in command_categories if x not in cfg.disabled_command_categories
142+
]
143+
144+
logger.debug(f"The following command categories are enabled: {command_categories}")
145+
146+
for command_category in command_categories:
147+
command_registry.import_commands(command_category)
134148

135149
ai_name = ""
136150
ai_config = construct_main_ai_config()

0 commit comments

Comments
 (0)