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.mdindex 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.++++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 Usagediff --git a/plugin.png b/plugin.pngnew file mode 100644index 0000000000..865ce3c922Binary files /dev/null and b/plugin.png differdiff --git a/plugins/__PUT_PLUGIN_ZIPS_HERE__ b/plugins/__PUT_PLUGIN_ZIPS_HERE__new file mode 100644index 0000000000..e69de29bb2diff --git a/scripts/config.py b/scripts/config.pyindex 27cc946cf0..7c39d72b0b 100644--- a/scripts/config.py+++ b/scripts/config.py@@ -81,6 +81,10 @@ class Config(metaclass=Singleton):# Initialize the OpenAI API clientopenai.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 = valuediff --git a/scripts/llm_utils.py b/scripts/llm_utils.pyindex 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=Notemperature=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 respdiff --git a/scripts/main.py b/scripts/main.pyindex 4be0b2aa26..4411fb51c0 100644--- a/scripts/main.py+++ b/scripts/main.py@@ -13,7 +13,10 @@ from enum import Enum, autoimport sysfrom config import Configfrom json_parser import fix_and_parse_json+from plugins import load_pluginsfrom ai_config import AIConfig+import os+from pathlib import Pathimport tracebackimport yamlimport argparse@@ -323,6 +326,30 @@ user_input = "Determine which next command to use, and respond using the formatmemory = 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 Loopwhile True:# Send message to AI, get responsediff --git a/scripts/plugins.py b/scripts/plugins.pynew file mode 100644index 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