Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -8,6 +8,9 @@ from langchain.embeddings import OpenAIEmbeddings # for creating embeddings
|
|
8 |
from langchain.vectorstores import Chroma # for the vectorization part
|
9 |
from langchain.chains import RetrievalQA # for conversing with chatGPT
|
10 |
from langchain.chat_models import ChatOpenAI # the LLM model we'll use (ChatGPT)
|
|
|
|
|
|
|
11 |
|
12 |
|
13 |
def load_doc(pdf_doc, open_ai_key):
|
@@ -25,7 +28,17 @@ def load_doc(pdf_doc, open_ai_key):
|
|
25 |
|
26 |
#Finally, we create the bot using the RetrievalQAChain class
|
27 |
global pdf_qa
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
return "Ready"
|
31 |
else:
|
|
|
8 |
from langchain.vectorstores import Chroma # for the vectorization part
|
9 |
from langchain.chains import RetrievalQA # for conversing with chatGPT
|
10 |
from langchain.chat_models import ChatOpenAI # the LLM model we'll use (ChatGPT)
|
11 |
+
from langchain import PromptTemplate
|
12 |
+
|
13 |
+
|
14 |
|
15 |
|
16 |
def load_doc(pdf_doc, open_ai_key):
|
|
|
28 |
|
29 |
#Finally, we create the bot using the RetrievalQAChain class
|
30 |
global pdf_qa
|
31 |
+
|
32 |
+
prompt_template = """Use the following pieces of context to answer the question at the end. If you do not know the answer, just return the question followed by N/A. If you encounter a date, return it in mm/dd/yyyy format.
|
33 |
+
|
34 |
+
{context}
|
35 |
+
|
36 |
+
Question: {question}
|
37 |
+
Return the key fields from the question followed by the answer :"""
|
38 |
+
PROMPT = PromptTemplate(template=prompt_template, input_variables=["context", "question"])
|
39 |
+
chain_type_kwargs = {"prompt": PROMPT}
|
40 |
+
pdf_qa = RetrievalQA.from_chain_type(llm=ChatOpenAI(temperature=0, model_name="gpt-4"),chain_type="stuff", retriever=vectordb.as_retriever(), chain_type_kwargs=chain_type_kwargs, return_source_documents=True)
|
41 |
+
|
42 |
|
43 |
return "Ready"
|
44 |
else:
|