diff --git a/mem0/embeddings/ollama.py b/mem0/embeddings/ollama.py index 1298760b..2e7f3758 100644 --- a/mem0/embeddings/ollama.py +++ b/mem0/embeddings/ollama.py @@ -1,3 +1,5 @@ +import subprocess +import sys from typing import Optional from mem0.configs.embeddings.base import BaseEmbedderConfig @@ -6,9 +8,17 @@ from mem0.embeddings.base import EmbeddingBase try: from ollama import Client except ImportError: - raise ImportError( - "Ollama requires extra dependencies. Install with `pip install ollama`" - ) from None + user_input = input("The 'ollama' library is required. Install it now? [y/N]: ") + if user_input.lower() == 'y': + try: + subprocess.check_call([sys.executable, "-m", "pip", "install", "ollama"]) + from ollama import Client + except subprocess.CalledProcessError: + print("Failed to install 'ollama'. Please install it manually using 'pip install ollama'.") + sys.exit(1) + else: + print("The required 'ollama' library is not installed.") + sys.exit(1) class OllamaEmbedding(EmbeddingBase): diff --git a/mem0/proxy/main.py b/mem0/proxy/main.py index 76942b1f..58a6a730 100644 --- a/mem0/proxy/main.py +++ b/mem0/proxy/main.py @@ -1,3 +1,5 @@ +import subprocess +import sys import httpx from typing import Optional, List, Union import threading @@ -5,9 +7,17 @@ import threading try: import litellm except ImportError: - raise ImportError( - "litellm requires extra dependencies. Install with `pip install litellm`" - ) from None + user_input = input("The 'litellm' library is required. Install it now? [y/N]: ") + if user_input.lower() == 'y': + try: + subprocess.check_call([sys.executable, "-m", "pip", "install", "litellm"]) + import litellm + except subprocess.CalledProcessError: + print("Failed to install 'litellm'. Please install it manually using 'pip install litellm'.") + sys.exit(1) + else: + raise ImportError("The required 'litellm' library is not installed.") + sys.exit(1) from mem0.memory.telemetry import capture_client_event from mem0 import Memory, MemoryClient diff --git a/mem0/vector_stores/chroma.py b/mem0/vector_stores/chroma.py index b75b0c91..791ff8c9 100644 --- a/mem0/vector_stores/chroma.py +++ b/mem0/vector_stores/chroma.py @@ -1,3 +1,5 @@ +import subprocess +import sys import logging from typing import Optional, List, Dict @@ -7,9 +9,18 @@ try: import chromadb from chromadb.config import Settings except ImportError: - raise ImportError( - "Chromadb requires extra dependencies. Install with `pip install chromadb`" - ) from None + user_input = input("The 'chromadb' library is required. Install it now? [y/N]: ") + if user_input.lower() == 'y': + try: + subprocess.check_call([sys.executable, "-m", "pip", "install", "chromadb"]) + import chromadb + from chromadb.config import Settings + except subprocess.CalledProcessError: + print("Failed to install 'chromadb'. Please install it manually using 'pip install chromadb'.") + sys.exit(1) + else: + print("The required 'chromadb' library is not installed.") + sys.exit(1) from mem0.vector_stores.base import VectorStoreBase diff --git a/mem0/vector_stores/pgvector.py b/mem0/vector_stores/pgvector.py index 180792fd..9da5f4a1 100644 --- a/mem0/vector_stores/pgvector.py +++ b/mem0/vector_stores/pgvector.py @@ -1,3 +1,5 @@ +import subprocess +import sys import json from typing import Optional, List from pydantic import BaseModel @@ -6,9 +8,18 @@ try: import psycopg2 from psycopg2.extras import execute_values except ImportError: - raise ImportError( - "PGVector requires extra dependencies. Install with `pip install psycopg2`" - ) from None + user_input = input("The 'psycopg2' library is required. Install it now? [y/N]: ") + if user_input.lower() == 'y': + try: + subprocess.check_call([sys.executable, "-m", "pip", "install", "psycopg2"]) + import psycopg2 + from psycopg2.extras import execute_values + except subprocess.CalledProcessError: + print("Failed to install 'psycopg2'. Please install it manually using 'pip install psycopg2'.") + sys.exit(1) + else: + print("The required 'psycopg2' library is not installed.") + sys.exit(1) from mem0.vector_stores.base import VectorStoreBase