Skip to content

Commit

Permalink
⚙️ fix: dependency crash, conditional imports for heavier packages (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
danny-avila authored Sep 27, 2024
1 parent f21b6e7 commit fc7b36c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
26 changes: 17 additions & 9 deletions config.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
# config.py
import os
import json
import logging
import boto3
import logging
from enum import Enum
from datetime import datetime
from dotenv import find_dotenv, load_dotenv
from langchain_ollama import OllamaEmbeddings
from langchain_huggingface import HuggingFaceEmbeddings, HuggingFaceEndpointEmbeddings
from langchain_aws import BedrockEmbeddings
from langchain_openai import AzureOpenAIEmbeddings, OpenAIEmbeddings
from starlette.middleware.base import BaseHTTPMiddleware
from store_factory import get_vector_store

Expand Down Expand Up @@ -179,28 +175,40 @@ async def dispatch(self, request, call_next):

def init_embeddings(provider, model):
if provider == EmbeddingsProvider.OPENAI:
from langchain_openai import OpenAIEmbeddings

return OpenAIEmbeddings(
model=model,
api_key=RAG_OPENAI_API_KEY,
openai_api_base=RAG_OPENAI_BASEURL,
openai_proxy=RAG_OPENAI_PROXY,
)
elif provider == EmbeddingsProvider.AZURE:
from langchain_openai import AzureOpenAIEmbeddings

return AzureOpenAIEmbeddings(
azure_deployment=model,
api_key=RAG_AZURE_OPENAI_API_KEY,
azure_endpoint=RAG_AZURE_OPENAI_ENDPOINT,
api_version=RAG_AZURE_OPENAI_API_VERSION,
)
elif provider == EmbeddingsProvider.HUGGINGFACE:
from langchain_huggingface import HuggingFaceEmbeddings

return HuggingFaceEmbeddings(
model_name=model, encode_kwargs={"normalize_embeddings": True}
)
elif provider == EmbeddingsProvider.HUGGINGFACETEI:
from langchain_huggingface import HuggingFaceEndpointEmbeddings

return HuggingFaceEndpointEmbeddings(model=model)
elif provider == EmbeddingsProvider.OLLAMA:
from langchain_ollama import OllamaEmbeddings

return OllamaEmbeddings(model=model, base_url=OLLAMA_BASE_URL)
elif provider == EmbeddingsProvider.BEDROCK:
from langchain_aws import BedrockEmbeddings

session = boto3.Session(
aws_access_key_id=AWS_ACCESS_KEY_ID,
aws_secret_access_key=AWS_SECRET_ACCESS_KEY,
Expand Down Expand Up @@ -237,9 +245,7 @@ def init_embeddings(provider, model):
EMBEDDINGS_MODEL = get_env_variable(
"EMBEDDINGS_MODEL", "amazon.titan-embed-text-v1"
)
AWS_DEFAULT_REGION = get_env_variable(
"AWS_DEFAULT_REGION", "us-east-1"
)
AWS_DEFAULT_REGION = get_env_variable("AWS_DEFAULT_REGION", "us-east-1")
else:
raise ValueError(f"Unsupported embeddings provider: {EMBEDDINGS_PROVIDER}")

Expand All @@ -258,7 +264,9 @@ def init_embeddings(provider, model):
elif VECTOR_DB_TYPE == VectorDBType.ATLAS_MONGO:
# Backward compatability check
if MONGO_VECTOR_COLLECTION:
logger.info(f"DEPRECATED: Please remove env var MONGO_VECTOR_COLLECTION and instead use COLLECTION_NAME and ATLAS_SEARCH_INDEX. You can set both as same, but not neccessary. See README for more information.")
logger.info(
f"DEPRECATED: Please remove env var MONGO_VECTOR_COLLECTION and instead use COLLECTION_NAME and ATLAS_SEARCH_INDEX. You can set both as same, but not neccessary. See README for more information."
)
ATLAS_SEARCH_INDEX = MONGO_VECTOR_COLLECTION
COLLECTION_NAME = MONGO_VECTOR_COLLECTION
vector_store = get_vector_store(
Expand Down
18 changes: 10 additions & 8 deletions requirements.lite.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
langchain==0.1.12
langchain_community==0.0.34
langchain_openai==0.0.8
langchain_core==0.1.45
langchain==0.3
langchain_community==0.3
langchain_openai==0.2.0
langchain_core==0.3.5
sqlalchemy==2.0.28
python-dotenv==1.0.1
fastapi==0.110.0
psycopg2-binary==2.9.9
pgvector==0.2.5
uvicorn==0.28.0
pypdf==4.1.0
unstructured==0.12.6
unstructured==0.15.13
markdown==3.6
networkx==3.2.1
pandas==2.2.1
Expand All @@ -20,11 +20,13 @@ PyJWT==2.8.0
asyncpg==0.29.0
python-multipart==0.0.9
aiofiles==23.2.1
rapidocr-onnxruntime==1.3.17
rapidocr-onnxruntime==1.3.24
opencv-python-headless==4.9.0.80
pymongo==4.6.3
langchain-mongodb==0.1.3
langchain-mongodb==0.2.0
cryptography==42.0.7
python-magic==0.4.27
python-pptx==0.6.23
xlrd==2.0.1
xlrd==2.0.1
langchain-aws==0.2.1
boto3==1.34.144

0 comments on commit fc7b36c

Please sign in to comment.