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.

merged master and resolved conflicts

cs0lar4c7deef9ae47
diff --cc .env.template
index 2089e5c4cf,22bf8d74d9..e6ef227fc8
--- a/.env.template
+++ b/.env.template
@@@ -1,26 -1,123 +1,145 @@@
- PINECONE_API_KEY=your-pinecone-api-key
- PINECONE_ENV=your-pinecone-region
+ ################################################################################
+ ### AUTO-GPT - GENERAL SETTINGS
+ ################################################################################
+ # EXECUTE_LOCAL_COMMANDS - Allow local command execution (Example: False)
+ EXECUTE_LOCAL_COMMANDS=False
+ # BROWSE_CHUNK_MAX_LENGTH - When browsing website, define the length of chunk stored in memory
+ BROWSE_CHUNK_MAX_LENGTH=8192
+ # BROWSE_SUMMARY_MAX_TOKEN - Define the maximum length of the summary generated by GPT agent when browsing website
+ BROWSE_SUMMARY_MAX_TOKEN=300
+ # USER_AGENT - Define the user-agent used by the requests library to browse website (string)
+ # USER_AGENT="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36"
+ # AI_SETTINGS_FILE - Specifies which AI Settings file to use (defaults to ai_settings.yaml)
+ AI_SETTINGS_FILE=ai_settings.yaml
+
+ ################################################################################
+ ### LLM PROVIDER
+ ################################################################################
+
+ ### OPENAI
+ # OPENAI_API_KEY - OpenAI API Key (Example: my-openai-api-key)
+ # TEMPERATURE - Sets temperature in OpenAI (Default: 1)
+ # USE_AZURE - Use Azure OpenAI or not (Default: False)
OPENAI_API_KEY=your-openai-api-key
TEMPERATURE=1
- ELEVENLABS_API_KEY=your-elevenlabs-api-key
- ELEVENLABS_VOICE_1_ID=your-voice-id
- ELEVENLABS_VOICE_2_ID=your-voice-id
+ USE_AZURE=False
+
+ ### AZURE
+ # OPENAI_AZURE_API_BASE - OpenAI API base URL for Azure (Example: https://my-azure-openai-url.com)
+ # OPENAI_AZURE_API_VERSION - OpenAI API version for Azure (Example: v1)
+ # OPENAI_AZURE_DEPLOYMENT_ID - OpenAI deployment ID for Azure (Example: my-deployment-id)
+ # OPENAI_AZURE_CHAT_DEPLOYMENT_ID - OpenAI deployment ID for Azure Chat (Example: my-deployment-id-for-azure-chat)
+ # OPENAI_AZURE_EMBEDDINGS_DEPLOYMENT_ID - OpenAI deployment ID for Embedding (Example: my-deployment-id-for-azure-embeddigs)
+ OPENAI_AZURE_API_BASE=your-base-url-for-azure
+ OPENAI_AZURE_API_VERSION=api-version-for-azure
+ OPENAI_AZURE_DEPLOYMENT_ID=deployment-id-for-azure
+ OPENAI_AZURE_CHAT_DEPLOYMENT_ID=deployment-id-for-azure-chat
+ OPENAI_AZURE_EMBEDDINGS_DEPLOYMENT_ID=deployment-id-for-azure-embeddigs
+
+ ################################################################################
+ ### LLM MODELS
+ ################################################################################
+
+ # SMART_LLM_MODEL - Smart language model (Default: gpt-4)
+ # FAST_LLM_MODEL - Fast language model (Default: gpt-3.5-turbo)
SMART_LLM_MODEL=gpt-4
FAST_LLM_MODEL=gpt-3.5-turbo
- GOOGLE_API_KEY=
- CUSTOM_SEARCH_ENGINE_ID=
- USE_AZURE=False
- EXECUTE_LOCAL_COMMANDS=False
- IMAGE_PROVIDER=dalle
- HUGGINGFACE_API_TOKEN=
- USE_MAC_OS_TTS=False
+
+ ### LLM MODEL SETTINGS
+ # FAST_TOKEN_LIMIT - Fast token limit for OpenAI (Default: 4000)
+ # SMART_TOKEN_LIMIT - Smart token limit for OpenAI (Default: 8000)
+ # When using --gpt3onlythis needs to be set to 4000.
+ FAST_TOKEN_LIMIT=4000
+ SMART_TOKEN_LIMIT=8000
+
+ ################################################################################
+ ### MEMORY
+ ################################################################################
+
+ # MEMORY_BACKEND - Memory backend type (Default: local)
++>>>>>>> master
+ MEMORY_BACKEND=local
+
+ ### PINECONE
+ # PINECONE_API_KEY - Pinecone API Key (Example: my-pinecone-api-key)
+ # PINECONE_ENV - Pinecone environment (region) (Example: us-west-2)
+ PINECONE_API_KEY=your-pinecone-api-key
+ PINECONE_ENV=your-pinecone-region
+
+ ### REDIS
+ # REDIS_HOST - Redis host (Default: localhost)
+ # REDIS_PORT - Redis port (Default: 6379)
+ # REDIS_PASSWORD - Redis password (Default: "")
+ # WIPE_REDIS_ON_START - Wipes data / index on start (Default: False)
+ # MEMORY_INDEX - Name of index created in Redis database (Default: auto-gpt)
+ REDIS_HOST=localhost
+ REDIS_PORT=6379
+ REDIS_PASSWORD=
+ WIPE_REDIS_ON_START=False
+ MEMORY_INDEX=auto-gpt
+
++### WEAVIATE
++# MEMORY_BACKEND - Use 'weaviate' to use Weaviate vector storage
++# WEAVIATE_HOST - Weaviate host IP
++# WEAVIATE_PORT - Weaviate host port
++# WEAVIATE_PROTOCOL - Weaviate host protocol (e.g. 'http')
++# USE_WEAVIATE_EMBEDDED - Whether to use Embedded Weaviate
++# WEAVIATE_EMBEDDED_PATH - File system path were to persist data when running Embedded Weaviate
++# WEAVIATE_USERNAME - Weaviate username
++# WEAVIATE_PASSWORD - Weaviate password
++# WEAVIATE_API_KEY - Weaviate API key if using API-key-based authentication
++# MEMORY_INDEX - Name of index to create in Weaviate
+WEAVIATE_HOST="127.0.0.1"
+WEAVIATE_PORT=8080
+WEAVIATE_PROTOCOL="http"
+USE_WEAVIATE_EMBEDDED=False
+WEAVIATE_EMBEDDED_PATH="/home/me/.local/share/weaviate"
+WEAVIATE_USERNAME=
+WEAVIATE_PASSWORD=
+WEAVIATE_API_KEY=
- MEMORY_INDEX="auto-gpt"
- MEMORY_BACKEND=local
++MEMORY_INDEX=AutoGpt
++
+ ################################################################################
+ ### IMAGE GENERATION PROVIDER
+ ################################################################################
+
+ ### OPEN AI
+ # IMAGE_PROVIDER - Image provider (Example: dalle)
+ IMAGE_PROVIDER=dalle
+
+ ### HUGGINGFACE
+ # STABLE DIFFUSION
+ # (Default URL: https://api-inference.huggingface.co/models/CompVis/stable-diffusion-v1-4)
+ # Set in image_gen.py)
+ # HUGGINGFACE_API_TOKEN - HuggingFace API token (Example: my-huggingface-api-token)
+ HUGGINGFACE_API_TOKEN=your-huggingface-api-token
+
+ ################################################################################
+ ### SEARCH PROVIDER
+ ################################################################################
+
+ ### GOOGLE
+ # GOOGLE_API_KEY - Google API key (Example: my-google-api-key)
+ # CUSTOM_SEARCH_ENGINE_ID - Custom search engine ID (Example: my-custom-search-engine-id)
+ GOOGLE_API_KEY=your-google-api-key
+ CUSTOM_SEARCH_ENGINE_ID=your-custom-search-engine-id
+
+ ################################################################################
+ ### TTS PROVIDER
+ ################################################################################
+
+ ### MAC OS
+ # USE_MAC_OS_TTS - Use Mac OS TTS or not (Default: False)
+ USE_MAC_OS_TTS=False
+
+ ### STREAMELEMENTS
+ # USE_BRIAN_TTS - Use Brian TTS or not (Default: False)
+ USE_BRIAN_TTS=False
+
+ ### ELEVENLABS
+ # ELEVENLABS_API_KEY - Eleven Labs API key (Example: my-elevenlabs-api-key)
+ # ELEVENLABS_VOICE_1_ID - Eleven Labs voice 1 ID (Example: my-voice-id-1)
+ # ELEVENLABS_VOICE_2_ID - Eleven Labs voice 2 ID (Example: my-voice-id-2)
+ ELEVENLABS_API_KEY=your-elevenlabs-api-key
+ ELEVENLABS_VOICE_1_ID=your-voice-id-1
+ ELEVENLABS_VOICE_2_ID=your-voice-id-2
diff --cc README.md
index b5a36b18ef,55c3d833b2..5f2bce23ff
--- a/README.md
+++ b/README.md
@@@ -242,31 -276,9 +276,31 @@@ For macOS and Linux users
```
export PINECONE_API_KEY="YOUR_PINECONE_API_KEY"
export PINECONE_ENV="Your pinecone region" # something like: us-east4-gcp
-
+ export MEMORY_BACKEND="pinecone"
```
+## Weaviate Setup
+
+[Weaviate](https://weaviate.io/) is an open-source vector database. It allows to store data objects and vector embeddings from ML-models and scales seamlessly to billion of data objects. [An instance of Weaviate can be created locally (using Docker), on Kubernetes or using Weaviate Cloud Services](https://weaviate.io/developers/weaviate/quickstart).
+Although still experimental, [Embedded Weaviate](https://weaviate.io/developers/weaviate/installation/embedded) is supported which allows the Auto-GPT process itself to start a Weaviate instance. To enable it, set `USE_WEAVIATE_EMBEDDED` to `True` and make sure you `pip install "weaviate-client>=3.15.4"`.
+
+#### Setting up environment variables
+
+In your `.env` file set the following:
+
+```
+MEMORY_BACKEND=weaviate
+WEAVIATE_HOST="127.0.0.1" # the IP or domain of the running Weaviate instance
+WEAVIATE_PORT="8080"
+WEAVIATE_PROTOCOL="http"
+WEAVIATE_USERNAME="your username"
+WEAVIATE_PASSWORD="your password"
+WEAVIATE_API_KEY="your weaviate API key if you have one"
+WEAVIATE_EMBEDDED_PATH="/home/me/.local/share/weaviate" # this is optional and indicates where the data should be persisted when running an embedded instance
+USE_WEAVIATE_EMBEDDED=False # set to True to run Embedded Weaviate
+MEMORY_INDEX="Autogpt" # name of the index to create for the application
+```
+
## Setting Your Cache Type
By default Auto-GPT is going to use LocalCache instead of redis or Pinecone.
diff --cc autogpt/memory/__init__.py
index 7535d09119,42ba5a65c9..d56b2de22f
--- a/autogpt/memory/__init__.py
+++ b/autogpt/memory/__init__.py
@@@ -37,17 -36,12 +41,19 @@@ def get_memory(cfg, init=False)
memory.clear()
elif cfg.memory_backend == "redis":
if not RedisMemory:
- print("Error: Redis is not installed. Please install redis-py to"
- " use Redis as a memory backend.")
+ print(
+ "Error: Redis is not installed. Please install redis-py to"
+ " use Redis as a memory backend."
+ )
else:
memory = RedisMemory(cfg)
+ elif cfg.memory_backend == "weaviate":
+ if not WeaviateMemory:
+ print("Error: Weaviate is not installed. Please install weaviate-client to"
+ " use Weaviate as a memory backend.")
+ else:
+ memory = WeaviateMemory(cfg)
+
elif cfg.memory_backend == "no_memory":
memory = NoMemory(cfg)
@@@ -62,11 -56,4 +68,4 @@@ def get_supported_memory_backends()
return supported_memory
- __all__ = [
- "get_memory",
- "LocalCache",
- "RedisMemory",
- "PineconeMemory",
- "WeaviateMemory"
- "NoMemory"
- ]
-__all__ = ["get_memory", "LocalCache", "RedisMemory", "PineconeMemory", "NoMemory"]
++__all__ = ["get_memory", "LocalCache", "RedisMemory", "PineconeMemory", "WeaviateMemory", "NoMemory"]
diff --cc autogpt/memory/base.py
index 1bb4e89f5b,691e2299c4..784483fa92
--- a/autogpt/memory/base.py
+++ b/autogpt/memory/base.py
@@@ -1,10 -1,13 +1,12 @@@
"""Base class for memory providers."""
import abc
- from config import AbstractSingleton, Config
+
import openai
+ from autogpt.config import AbstractSingleton, Config
+
cfg = Config()
-
def get_ada_embedding(text):
text = text.replace("\n", " ")
if cfg.use_azure:
diff --cc autogpt/memory/weaviate.py
index b5710cb5d6,0000000000..fdac8e852d
mode 100644,000000..100644
--- a/autogpt/memory/weaviate.py
+++ b/autogpt/memory/weaviate.py
@@@ -1,109 -1,0 +1,109 @@@
- from config import Config
- from memory.base import MemoryProviderSingleton, get_ada_embedding
++from autogpt.config import Config
++from autogpt.memory.base import MemoryProviderSingleton, get_ada_embedding
+import uuid
+import weaviate
+from weaviate import Client
+from weaviate.embedded import EmbeddedOptions
+from weaviate.util import generate_uuid5
+
+def default_schema(weaviate_index):
+ return {
+ "class": weaviate_index,
+ "properties": [
+ {
+ "name": "raw_text",
+ "dataType": ["text"],
+ "description": "original text for the embedding"
+ }
+ ],
+ }
+
+class WeaviateMemory(MemoryProviderSingleton):
+ def __init__(self, cfg):
+ auth_credentials = self._build_auth_credentials(cfg)
+
+ url = f'{cfg.weaviate_protocol}://{cfg.weaviate_host}:{cfg.weaviate_port}'
+
+ if cfg.use_weaviate_embedded:
+ self.client = Client(embedded_options=EmbeddedOptions(
+ hostname=cfg.weaviate_host,
+ port=int(cfg.weaviate_port),
+ persistence_data_path=cfg.weaviate_embedded_path
+ ))
+
+ print(f"Weaviate Embedded running on: {url} with persistence path: {cfg.weaviate_embedded_path}")
+ else:
+ self.client = Client(url, auth_client_secret=auth_credentials)
+
+ self.index = cfg.memory_index
+ self._create_schema()
+
+ def _create_schema(self):
+ schema = default_schema(self.index)
+ if not self.client.schema.contains(schema):
+ self.client.schema.create_class(schema)
+
+ def _build_auth_credentials(self, cfg):
+ if cfg.weaviate_username and cfg.weaviate_password:
+ return weaviate_auth.AuthClientPassword(cfg.weaviate_username, cfg.weaviate_password)
+ if cfg.weaviate_api_key:
+ return weaviate.auth.AuthApiKey(api_key=cfg.weaviate_api_key)
+ else:
+ return None
+
+ def add(self, data):
+ vector = get_ada_embedding(data)
+
+ doc_uuid = generate_uuid5(data, self.index)
+ data_object = {
+ 'raw_text': data
+ }
+
+ with self.client.batch as batch:
+ batch.add_data_object(
+ uuid=doc_uuid,
+ data_object=data_object,
+ class_name=self.index,
+ vector=vector
+ )
+
+ return f"Inserting data into memory at uuid: {doc_uuid}:\n data: {data}"
+
+ def get(self, data):
+ return self.get_relevant(data, 1)
+
+
+ def clear(self):
+ self.client.schema.delete_all()
+
+ # weaviate does not yet have a neat way to just remove the items in an index
+ # without removing the entire schema, therefore we need to re-create it
+ # after a call to delete_all
+ self._create_schema()
+
+ return 'Obliterated'
+
+ def get_relevant(self, data, num_relevant=5):
+ query_embedding = get_ada_embedding(data)
+ try:
+ results = self.client.query.get(self.index, ['raw_text']) \
+ .with_near_vector({'vector': query_embedding, 'certainty': 0.7}) \
+ .with_limit(num_relevant) \
+ .do()
+
+ if len(results['data']['Get'][self.index]) > 0:
+ return [str(item['raw_text']) for item in results['data']['Get'][self.index]]
+ else:
+ return []
+
+ except Exception as err:
+ print(f'Unexpected error {err=}, {type(err)=}')
+ return []
+
+ def get_stats(self):
+ result = self.client.query.aggregate(self.index) \
+ .with_meta_count() \
+ .do()
+ class_data = result['data']['Aggregate'][self.index]
+
+ return class_data[0]['meta'] if class_data else {}
diff --cc requirements.txt
index d6fb6426a1,44cd600fe2..b0d777d56a
--- a/requirements.txt
+++ b/requirements.txt
@@@ -15,7 -15,8 +15,9 @@@ pinecone-client==2.2.
redis
orjson
Pillow
+weaviate-client==3.15.5
+ selenium
+ webdriver-manager
coverage
flake8
numpy
diff --cc tests/integration/weaviate_memory_tests.py
index 7b2b331fa3,0000000000..fa456c8acc
mode 100644,000000..100644
--- a/tests/integration/weaviate_memory_tests.py
+++ b/tests/integration/weaviate_memory_tests.py
@@@ -1,119 -1,0 +1,118 @@@
+import unittest
+from unittest import mock
+import sys
+import os
+
+from weaviate import Client
+from weaviate.util import get_valid_uuid
+from uuid import uuid4
+
- sys.path.append(os.path.abspath('./scripts'))
- from config import Config
- from memory.weaviate import WeaviateMemory
- from memory.base import get_ada_embedding
++from autogpt.config import Config
++from autogpt.memory.weaviate import WeaviateMemory
++from autogpt.memory.base import get_ada_embedding
+
[email protected](os.environ, {
+ "WEAVIATE_HOST": "127.0.0.1",
+ "WEAVIATE_PROTOCOL": "http",
+ "WEAVIATE_PORT": "8080",
+ "WEAVIATE_USERNAME": "",
+ "WEAVIATE_PASSWORD": "",
+ "MEMORY_INDEX": "AutogptTests"
+})
+class TestWeaviateMemory(unittest.TestCase):
+ cfg = None
+ client = None
+
+ @classmethod
+ def setUpClass(cls):
+ # only create the connection to weaviate once
+ cls.cfg = Config()
+
+ if cls.cfg.use_weaviate_embedded:
+ from weaviate.embedded import EmbeddedOptions
+
+ cls.client = Client(embedded_options=EmbeddedOptions(
+ hostname=cls.cfg.weaviate_host,
+ port=int(cls.cfg.weaviate_port),
+ persistence_data_path=cls.cfg.weaviate_embedded_path
+ ))
+ else:
+ cls.client = Client(f"{cls.cfg.weaviate_protocol}://{cls.cfg.weaviate_host}:{self.cfg.weaviate_port}")
+
+ """
+ In order to run these tests you will need a local instance of
+ Weaviate running. Refer to https://weaviate.io/developers/weaviate/installation/docker-compose
+ for creating local instances using docker.
+ Alternatively in your .env file set the following environmental variables to run Weaviate embedded (see: https://weaviate.io/developers/weaviate/installation/embedded):
+
+ USE_WEAVIATE_EMBEDDED=True
+ WEAVIATE_EMBEDDED_PATH="/home/me/.local/share/weaviate"
+ """
+ def setUp(self):
+ try:
+ self.client.schema.delete_class(self.cfg.memory_index)
+ except:
+ pass
+
+ self.memory = WeaviateMemory(self.cfg)
+
+ def test_add(self):
+ doc = 'You are a Titan name Thanos and you are looking for the Infinity Stones'
+ self.memory.add(doc)
+ result = self.client.query.get(self.cfg.memory_index, ['raw_text']).do()
+ actual = result['data']['Get'][self.cfg.memory_index]
+
+ self.assertEqual(len(actual), 1)
+ self.assertEqual(actual[0]['raw_text'], doc)
+
+ def test_get(self):
+ doc = 'You are an Avenger and swore to defend the Galaxy from a menace called Thanos'
+
+ with self.client.batch as batch:
+ batch.add_data_object(
+ uuid=get_valid_uuid(uuid4()),
+ data_object={'raw_text': doc},
+ class_name=self.cfg.memory_index,
+ vector=get_ada_embedding(doc)
+ )
+
+ batch.flush()
+
+ actual = self.memory.get(doc)
+
+ self.assertEqual(len(actual), 1)
+ self.assertEqual(actual[0], doc)
+
+
+ def test_get_stats(self):
+ docs = [
+ 'You are now about to count the number of docs in this index',
+ 'And then you about to find out if you can count correctly'
+ ]
+
+ [self.memory.add(doc) for doc in docs]
+
+ stats = self.memory.get_stats()
+
+ self.assertTrue(stats)
+ self.assertTrue('count' in stats)
+ self.assertEqual(stats['count'], 2)
+
+
+ def test_clear(self):
+ docs = [
+ 'Shame this is the last test for this class',
+ 'Testing is fun when someone else is doing it'
+ ]
+
+ [self.memory.add(doc) for doc in docs]
+
+ self.assertEqual(self.memory.get_stats()['count'], 2)
+
+ self.memory.clear()
+
+ self.assertEqual(self.memory.get_stats()['count'], 0)
+
+
+if __name__ == '__main__':
+ unittest.main()