bstraehle commited on
Commit
84e076a
1 Parent(s): c7808d6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -6
app.py CHANGED
@@ -30,6 +30,9 @@ MONGODB_COLLECTION = client[MONGODB_DB_NAME][MONGODB_COLLECTION_NAME]
30
  MONGODB_INDEX_NAME = "default"
31
 
32
  config = {
 
 
 
33
  "model": "gpt-4",
34
  "temperature": 0,
35
  }
@@ -70,8 +73,8 @@ def document_loading_splitting():
70
  OpenAIWhisperParser())
71
  docs.extend(loader.load())
72
  # Document splitting
73
- text_splitter = RecursiveCharacterTextSplitter(chunk_overlap = 150,
74
- chunk_size = 1500)
75
  splits = text_splitter.split_documents(docs)
76
  return splits
77
 
@@ -106,10 +109,9 @@ def llm_chain(llm, prompt):
106
  def rag_chain(llm, prompt, db):
107
  rag_chain = RetrievalQA.from_chain_type(llm,
108
  chain_type_kwargs = {"prompt": RAG_CHAIN_PROMPT},
109
- retriever = db.as_retriever(search_kwargs = {"k": 3}),
110
  return_source_documents = True)
111
  completion = rag_chain({"query": prompt})
112
- print(completion)
113
  return completion["result"]
114
 
115
  def wandb_log(prompt, completion, rag_option):
@@ -134,17 +136,19 @@ def invoke(openai_api_key, rag_option, prompt):
134
  #document_storage_chroma(splits)
135
  db = document_retrieval_chroma(llm, prompt)
136
  completion = rag_chain(llm, prompt, db)
 
137
  elif (rag_option == "MongoDB"):
138
  #splits = document_loading_splitting()
139
  #document_storage_mongodb(splits)
140
  db = document_retrieval_mongodb(llm, prompt)
141
  completion = rag_chain(llm, prompt, db)
 
142
  else:
143
- completion = llm_chain(llm, prompt)
144
  except Exception as e:
145
  raise gr.Error(e)
146
  wandb_log(prompt, completion, rag_option)
147
- return completion
148
 
149
  description = """<strong>Overview:</strong> Context-aware multimodal reasoning application that demonstrates a <strong>large language model (LLM)</strong> with
150
  <strong>retrieval augmented generation (RAG)</strong>.
 
30
  MONGODB_INDEX_NAME = "default"
31
 
32
  config = {
33
+ "chunk_overlap": 150,
34
+ "chunk_size": 1500,
35
+ "k": 3,
36
  "model": "gpt-4",
37
  "temperature": 0,
38
  }
 
73
  OpenAIWhisperParser())
74
  docs.extend(loader.load())
75
  # Document splitting
76
+ text_splitter = RecursiveCharacterTextSplitter(chunk_overlap = config["chunk_overlap"],
77
+ chunk_size = config["chunk_size"])
78
  splits = text_splitter.split_documents(docs)
79
  return splits
80
 
 
109
  def rag_chain(llm, prompt, db):
110
  rag_chain = RetrievalQA.from_chain_type(llm,
111
  chain_type_kwargs = {"prompt": RAG_CHAIN_PROMPT},
112
+ retriever = db.as_retriever(search_kwargs = {"k": config["k"]}),
113
  return_source_documents = True)
114
  completion = rag_chain({"query": prompt})
 
115
  return completion["result"]
116
 
117
  def wandb_log(prompt, completion, rag_option):
 
136
  #document_storage_chroma(splits)
137
  db = document_retrieval_chroma(llm, prompt)
138
  completion = rag_chain(llm, prompt, db)
139
+ result = completion["result"]
140
  elif (rag_option == "MongoDB"):
141
  #splits = document_loading_splitting()
142
  #document_storage_mongodb(splits)
143
  db = document_retrieval_mongodb(llm, prompt)
144
  completion = rag_chain(llm, prompt, db)
145
+ result = completion["result"]
146
  else:
147
+ result = llm_chain(llm, prompt)
148
  except Exception as e:
149
  raise gr.Error(e)
150
  wandb_log(prompt, completion, rag_option)
151
+ return result
152
 
153
  description = """<strong>Overview:</strong> Context-aware multimodal reasoning application that demonstrates a <strong>large language model (LLM)</strong> with
154
  <strong>retrieval augmented generation (RAG)</strong>.