mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2025-12-17 14:04:27 +01:00
Refactor memory into factory.
This commit is contained in:
@@ -1,8 +1,6 @@
|
|||||||
import browse
|
import browse
|
||||||
import json
|
import json
|
||||||
from memory.local import LocalCache
|
from memory import get_memory
|
||||||
from memory.pinecone import PineconeMemory
|
|
||||||
from memory.redismem import RedisMemory
|
|
||||||
import datetime
|
import datetime
|
||||||
import agent_manager as agents
|
import agent_manager as agents
|
||||||
import speak
|
import speak
|
||||||
@@ -54,12 +52,7 @@ def get_command(response):
|
|||||||
|
|
||||||
|
|
||||||
def execute_command(command_name, arguments):
|
def execute_command(command_name, arguments):
|
||||||
if cfg.memory_backend == "pinecone":
|
memory = get_memory(cfg)
|
||||||
memory = PineconeMemory(cfg=cfg)
|
|
||||||
elif cfg.memory_backend == "redis":
|
|
||||||
memory = RedisMemory(cfg=cfg)
|
|
||||||
else:
|
|
||||||
memory = LocalCache(cfg=cfg)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if command_name == "google":
|
if command_name == "google":
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
import json
|
import json
|
||||||
import random
|
import random
|
||||||
import commands as cmd
|
import commands as cmd
|
||||||
from memory.local import LocalCache
|
from memory import get_memory
|
||||||
from memory.pinecone import PineconeMemory
|
|
||||||
from memory.redismem import RedisMemory
|
|
||||||
import data
|
import data
|
||||||
import chat
|
import chat
|
||||||
from colorama import Fore, Style
|
from colorama import Fore, Style
|
||||||
@@ -285,13 +283,7 @@ user_input = "Determine which next command to use, and respond using the format
|
|||||||
|
|
||||||
# Initialize memory and make sure it is empty.
|
# Initialize memory and make sure it is empty.
|
||||||
# this is particularly important for indexing and referencing pinecone memory
|
# this is particularly important for indexing and referencing pinecone memory
|
||||||
if cfg.memory_backend == "pinecone":
|
memory = get_memory(cfg, init=True)
|
||||||
memory = PineconeMemory(cfg)
|
|
||||||
memory.clear()
|
|
||||||
elif cfg.memory_backend == "redis":
|
|
||||||
memory = RedisMemory(cfg)
|
|
||||||
else:
|
|
||||||
memory = LocalCache(cfg)
|
|
||||||
|
|
||||||
print('Using memory of type: ' + memory.__class__.__name__)
|
print('Using memory of type: ' + memory.__class__.__name__)
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
from memory.local import LocalCache
|
||||||
|
try:
|
||||||
|
from memory.redismem import RedisMemory
|
||||||
|
except ImportError:
|
||||||
|
print("Redis not installed. Skipping import.")
|
||||||
|
RedisMemory = None
|
||||||
|
|
||||||
|
try:
|
||||||
|
from memory.pinecone import PineconeMemory
|
||||||
|
except ImportError:
|
||||||
|
print("Pinecone not installed. Skipping import.")
|
||||||
|
PineconeMemory = None
|
||||||
|
|
||||||
|
|
||||||
|
def get_memory(cfg, init=False):
|
||||||
|
memory = None
|
||||||
|
if cfg.memory_backend == "pinecone":
|
||||||
|
if not PineconeMemory:
|
||||||
|
print("Error: Pinecone is not installed. Please install pinecone"
|
||||||
|
" to use Pinecone as a memory backend.")
|
||||||
|
else:
|
||||||
|
memory = PineconeMemory(cfg)
|
||||||
|
if init:
|
||||||
|
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.")
|
||||||
|
else:
|
||||||
|
memory = RedisMemory(cfg)
|
||||||
|
|
||||||
|
if memory is None:
|
||||||
|
memory = LocalCache(cfg)
|
||||||
|
return memory
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
"get_memory",
|
||||||
|
"LocalCache",
|
||||||
|
"RedisCache",
|
||||||
|
"PineconeCache",
|
||||||
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user