Merge pull request #1011 from cryptidv/redis-logging

Improved logging on connection fail to a Memory Backend
This commit is contained in:
Pi
2023-04-13 15:47:41 +01:00
committed by GitHub
3 changed files with 29 additions and 1 deletions

View File

@@ -124,6 +124,12 @@ class Logger(metaclass=Singleton):
self.logger.setLevel(level) self.logger.setLevel(level)
self.typing_logger.setLevel(level) self.typing_logger.setLevel(level)
def double_check(self, additionalText=None):
if not additionalText:
additionalText = "Please ensure you've setup and configured everything correctly. Read https://github.com/Torantulino/Auto-GPT#readme to double check. You can also create a github issue or join the discord and ask there!"
self.typewriter_log("DOUBLE CHECK CONFIGURATION", Fore.YELLOW, additionalText)
''' '''
Output stream to console using simulated typing Output stream to console using simulated typing

View File

@@ -2,7 +2,8 @@
import pinecone import pinecone
from memory.base import MemoryProviderSingleton, get_ada_embedding from memory.base import MemoryProviderSingleton, get_ada_embedding
from logger import logger
from colorama import Fore, Style
class PineconeMemory(MemoryProviderSingleton): class PineconeMemory(MemoryProviderSingleton):
def __init__(self, cfg): def __init__(self, cfg):
@@ -17,6 +18,15 @@ class PineconeMemory(MemoryProviderSingleton):
# for now this works. # for now this works.
# we'll need a more complicated and robust system if we want to start with memory. # we'll need a more complicated and robust system if we want to start with memory.
self.vec_num = 0 self.vec_num = 0
try:
pinecone.whoami()
except Exception as e:
logger.typewriter_log("FAILED TO CONNECT TO PINECONE", Fore.RED, Style.BRIGHT + str(e) + Style.RESET_ALL)
logger.double_check("Please ensure you have setup and configured Pinecone properly for use. " +
f"You can check out {Fore.CYAN + Style.BRIGHT}https://github.com/Torantulino/Auto-GPT#-pinecone-api-key-setup{Style.RESET_ALL} to ensure you've set up everything correctly.")
exit(1)
if table_name not in pinecone.list_indexes(): if table_name not in pinecone.list_indexes():
pinecone.create_index(table_name, dimension=dimension, metric=metric, pod_type=pod_type) pinecone.create_index(table_name, dimension=dimension, metric=metric, pod_type=pod_type)
self.index = pinecone.Index(table_name) self.index = pinecone.Index(table_name)

View File

@@ -7,6 +7,8 @@ from redis.commands.search.indexDefinition import IndexDefinition, IndexType
import numpy as np import numpy as np
from memory.base import MemoryProviderSingleton, get_ada_embedding from memory.base import MemoryProviderSingleton, get_ada_embedding
from logger import logger
from colorama import Fore, Style
SCHEMA = [ SCHEMA = [
@@ -44,6 +46,16 @@ class RedisMemory(MemoryProviderSingleton):
db=0 # Cannot be changed db=0 # Cannot be changed
) )
self.cfg = cfg self.cfg = cfg
# Check redis connection
try:
self.redis.ping()
except redis.ConnectionError as e:
logger.typewriter_log("FAILED TO CONNECT TO REDIS", Fore.RED, Style.BRIGHT + str(e) + Style.RESET_ALL)
logger.double_check("Please ensure you have setup and configured Redis properly for use. " +
f"You can check out {Fore.CYAN + Style.BRIGHT}https://github.com/Torantulino/Auto-GPT#redis-setup{Style.RESET_ALL} to ensure you've set up everything correctly.")
exit(1)
if cfg.wipe_redis_on_start: if cfg.wipe_redis_on_start:
self.redis.flushall() self.redis.flushall()
try: try: