Spaces:
Sleeping
Sleeping
from pymongo import MongoClient | |
from langchain.embeddings.openai import OpenAIEmbeddings | |
from langchain.vectorstores import MongoDBAtlasVectorSearch | |
from langchain.document_loaders import DirectoryLoader | |
from langchain.llms import OpenAI | |
from langchain.chains import RetrievalQA | |
import gradio as gr | |
from gradio.themes.base import Base | |
#import key_param | |
import os | |
mongo_uri = os.getenv("MONGO_URI") | |
openai_api_key = os.getenv("OPENAI_API_KEY") | |
client = MongoClient(mongo_uri) | |
dbName = "langchain_demo" | |
collectionName = "collection_of_text_blobs" | |
collection = client[dbName][collectionName] | |
loader = DirectoryLoader( './sample_files', glob="./*.txt", show_progress=True) | |
data = loader.load() | |
embeddings = OpenAIEmbeddings(openai_api_key=openai_api_key) | |
vectorStore = MongoDBAtlasVectorSearch.from_documents( data, embeddings, collection=collection, index_name="default" ) | |