bstraehle commited on
Commit
53d588f
1 Parent(s): 503e34f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -9
app.py CHANGED
@@ -20,6 +20,11 @@ _ = load_dotenv(find_dotenv())
20
 
21
  #openai.api_key = os.environ["OPENAI_API_KEY"]
22
 
 
 
 
 
 
23
  template = """If you don't know the answer, just say that you don't know, don't try to make up an answer. Keep the answer as concise as possible. Always say
24
  "🧠 Thanks for using the app - Bernd" at the end of the answer. """
25
 
@@ -64,19 +69,19 @@ def document_loading_splitting():
64
  return splits
65
 
66
  def document_storage_chroma(splits):
67
- vector_db = Chroma.from_documents(documents = splits,
68
- embedding = OpenAIEmbeddings(disallowed_special = ()),
69
- persist_directory = CHROMA_DIR)
70
 
71
  def document_storage_mongodb(splits):
72
- #TODO
73
- vector_db = Chroma.from_documents(documents = splits,
74
- embedding = OpenAIEmbeddings(disallowed_special = ()),
75
- persist_directory = CHROMA_DIR)
76
 
77
  def document_retrieval_chroma(llm, prompt):
78
  db = Chroma(embedding_function = OpenAIEmbeddings(),
79
- persist_directory = CHROMA_DIR)
80
  return db
81
 
82
  def document_retrieval_mongodb(llm, prompt):
@@ -109,12 +114,13 @@ def invoke(openai_api_key, rag_option, prompt):
109
  llm = ChatOpenAI(model_name = MODEL_NAME,
110
  openai_api_key = openai_api_key,
111
  temperature = 0)
112
- #splits = document_loading_splitting()
113
  if (rag_option == "Chroma"):
 
114
  #document_storage_chroma(splits)
115
  db = document_retrieval_chroma(llm, prompt)
116
  result = rag_chain(llm, prompt, db)
117
  elif (rag_option == "MongoDB"):
 
118
  #document_storage_mongodb(splits)
119
  db = document_retrieval_mongodb(llm, prompt)
120
  result = rag_chain(llm, prompt, db)
 
20
 
21
  #openai.api_key = os.environ["OPENAI_API_KEY"]
22
 
23
+ mongodb_atlas_cluster_uri = os.environ["MONGODB_ATLAS_CLUSTER_URI"]
24
+ client = MongoClient(mongodb_atlas_cluster_uri)
25
+ MONGODB_COLLECTION = client["langchain_db"]["gpt-4"]
26
+ MONGODB_INDEX_NAME = "default"
27
+
28
  template = """If you don't know the answer, just say that you don't know, don't try to make up an answer. Keep the answer as concise as possible. Always say
29
  "🧠 Thanks for using the app - Bernd" at the end of the answer. """
30
 
 
69
  return splits
70
 
71
  def document_storage_chroma(splits):
72
+ Chroma.from_documents(documents = splits,
73
+ embedding = OpenAIEmbeddings(disallowed_special = ()),
74
+ persist_directory = CHROMA_DIR)
75
 
76
  def document_storage_mongodb(splits):
77
+ MongoDBAtlasVectorSearch.from_documents(documents = splits,
78
+ embedding = OpenAIEmbeddings(disallowed_special = ()),
79
+ collection = MONGODB_COLLECTION,
80
+ index_name = MONGODB_INDEX_NAME)
81
 
82
  def document_retrieval_chroma(llm, prompt):
83
  db = Chroma(embedding_function = OpenAIEmbeddings(),
84
+ persist_directory = CHROMA_DIR)
85
  return db
86
 
87
  def document_retrieval_mongodb(llm, prompt):
 
114
  llm = ChatOpenAI(model_name = MODEL_NAME,
115
  openai_api_key = openai_api_key,
116
  temperature = 0)
 
117
  if (rag_option == "Chroma"):
118
+ #splits = document_loading_splitting()
119
  #document_storage_chroma(splits)
120
  db = document_retrieval_chroma(llm, prompt)
121
  result = rag_chain(llm, prompt, db)
122
  elif (rag_option == "MongoDB"):
123
+ #splits = document_loading_splitting()
124
  #document_storage_mongodb(splits)
125
  db = document_retrieval_mongodb(llm, prompt)
126
  result = rag_chain(llm, prompt, db)