Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

Plugins initial

BillSchumacher65b626c5e171
diff --git a/README.md b/README.md
index 749c879151..2f0ce155c1 100644
--- a/README.md
+++ b/README.md
@@ -204,6 +204,17 @@ export PINECONE_ENV="Your pinecone region" # something like: us-east4-gcp
```
+## Plugins
+
+See https://github.com/Torantulino/Auto-GPT-Plugin-Template for the template of the plugins.
+
+WARNING: Review the code of any plugin you use.
+
+Drop the repo's zipfile in the plugins folder.
+
+![Download Zip](https://raw.githubusercontent.com/BillSchumacher/Auto-GPT/master/plugin.png)
+
+If you add the plugins class name to the whitelist in the config.py you will not be prompted otherwise you'll be warned before loading the plugin.
## View Memory Usage
diff --git a/plugin.png b/plugin.png
new file mode 100644
index 0000000000..865ce3c922
Binary files /dev/null and b/plugin.png differ
diff --git a/plugins/__PUT_PLUGIN_ZIPS_HERE__ b/plugins/__PUT_PLUGIN_ZIPS_HERE__
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/scripts/config.py b/scripts/config.py
index 27cc946cf0..7c39d72b0b 100644
--- a/scripts/config.py
+++ b/scripts/config.py
@@ -81,6 +81,10 @@ class Config(metaclass=Singleton):
# Initialize the OpenAI API client
openai.api_key = self.openai_api_key
+ self.plugins = []
+ self.plugins_whitelist = []
+ self.plugins_blacklist = []
+
def set_continuous_mode(self, value: bool):
"""Set the continuous mode value."""
self.continuous_mode = value
@@ -135,3 +139,7 @@ class Config(metaclass=Singleton):
def set_debug_mode(self, value: bool):
"""Set the debug mode value."""
self.debug = value
+
+ def set_plugins(self, value: list):
+ """Set the plugins value."""
+ self.plugins = value
diff --git a/scripts/llm_utils.py b/scripts/llm_utils.py
index 94ba5f1316..28867494c2 100644
--- a/scripts/llm_utils.py
+++ b/scripts/llm_utils.py
@@ -22,5 +22,7 @@ def create_chat_completion(messages, model=None, temperature=None, max_tokens=No
temperature=temperature,
max_tokens=max_tokens
)
-
- return response.choices[0].message["content"]
+ resp = response.choices[0].message["content"]
+ for plugin in cfg.plugins:
+ resp = plugin.on_response(resp)
+ return resp
diff --git a/scripts/main.py b/scripts/main.py
index 4be0b2aa26..4411fb51c0 100644
--- a/scripts/main.py
+++ b/scripts/main.py
@@ -13,7 +13,10 @@ from enum import Enum, auto
import sys
from config import Config
from json_parser import fix_and_parse_json
+from plugins import load_plugins
from ai_config import AIConfig
+import os
+from pathlib import Path
import traceback
import yaml
import argparse
@@ -323,6 +326,30 @@ user_input = "Determine which next command to use, and respond using the format
memory = get_memory(cfg, init=True)
print('Using memory of type: ' + memory.__class__.__name__)
+
+plugins_found = load_plugins(Path(os.getcwd()) / "plugins")
+loaded_plugins = []
+for plugin in plugins_found:
+ if plugin.__name__ in cfg.plugins_blacklist:
+ continue
+ if plugin.__name__ in cfg.plugins_whitelist:
+ loaded_plugins.append(plugin())
+ else:
+ ack = input(
+ f"WARNNG Plugin {plugin.__name__} found. But not in the"
+ " whitelist... Load? (y/n): "
+ )
+ if ack.lower() == "y":
+ loaded_plugins.append(plugin())
+
+if loaded_plugins:
+ print(f"\nPlugins found: {len(loaded_plugins)}\n"
+ "--------------------")
+for plugin in loaded_plugins:
+ print(f"{plugin._name}: {plugin._version} - {plugin._description}")
+
+cfg.set_plugins(loaded_plugins)
+
# Interaction Loop
while True:
# Send message to AI, get response
diff --git a/scripts/plugins.py b/scripts/plugins.py
new file mode 100644
index 0000000000..44d7e618ae
--- /dev/null
+++ b/scripts/plugins.py
@@ -0,0 +1,74 @@
+"""Handles loading of plugins."""
+
+from ast import Module
+import zipfile
+from pathlib import Path
+from zipimport import zipimporter
+from typing import List, Optional, Tuple
+
+
+def inspect_zip_for_module(zip_path: str, debug: bool = False) -> Optional[str]:
+ """
+ Inspect a zipfile for a module.
+
+ Args:
+ zip_path (str): Path to the zipfile.
+ debug (bool, optional): Enable debug logging. Defaults to False.
+
+ Returns:
+ Optional[str]: The name of the module if found, else None.
+ """
+ with zipfile.ZipFile(zip_path, 'r') as zfile:
+ for name in zfile.namelist():
+ if name.endswith("__init__.py"):
+ if debug:
+ print(f"Found module '{name}' in the zipfile at: {name}")
+ return name
+ if debug:
+ print(f"Module '__init__.py' not found in the zipfile @ {zip_path}.")
+ return None
+
+
+def scan_plugins(plugins_path: Path, debug: bool = False) -> List[Tuple[str, Path]]:
+ """Scan the plugins directory for plugins.
+
+ Args:
+ plugins_path (Path): Path to the plugins directory.
+
+ Returns:
+ List[Path]: List of plugins.
+ """
+ plugins = []
+ for plugin in plugins_path.glob("*.zip"):
+ if module := inspect_zip_for_module(str(plugin), debug):
+ plugins.append((module, plugin))
+ return plugins
+
+
+def load_plugins(plugins_path: Path, debug: bool = False) -> List[Module]:
+ """Load plugins from the plugins directory.
+
+ Args:
+ plugins_path (Path): Path to the plugins directory.
+
+ Returns:
+ List[Path]: List of plugins.
+ """
+ plugins = scan_plugins(plugins_path)
+ plugin_modules = []
+ for module, plugin in plugins:
+ plugin = Path(plugin)
+ module = Path(module)
+ if debug:
+ print(f"Plugin: {plugin} Module: {module}")
+ zipped_package = zipimporter(plugin)
+ zipped_module = zipped_package.load_module(str(module.parent))
+ for key in dir(zipped_module):
+ if key.startswith("__"):
+ continue
+ a_module = getattr(zipped_module, key)
+ a_keys = dir(a_module)
+ if '_abc_impl' in a_keys and \
+ a_module.__name__ != 'AutoGPTPluginTemplate':
+ plugin_modules.append(a_module)
+ return plugin_modules