Spaces:
Runtime error
Runtime error
Shaileshshantaram Kadam commited on
Commit ·
4a83326
1
Parent(s): 2b3ac20
Updated app
Browse files- _chat.txt +0 -0
- ingest_data.py +7 -4
- query_data.py +3 -3
_chat.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
ingest_data.py
CHANGED
|
@@ -5,7 +5,7 @@ from langchain.embeddings import OpenAIEmbeddings
|
|
| 5 |
import pickle
|
| 6 |
|
| 7 |
# Load Data
|
| 8 |
-
loader = UnstructuredFileLoader("
|
| 9 |
raw_documents = loader.load()
|
| 10 |
|
| 11 |
# Split text
|
|
@@ -15,9 +15,12 @@ documents = text_splitter.split_documents(raw_documents)
|
|
| 15 |
|
| 16 |
# Load Data to vectorstore
|
| 17 |
embeddings = OpenAIEmbeddings()
|
| 18 |
-
|
|
|
|
| 19 |
|
| 20 |
|
| 21 |
# Save vectorstore
|
| 22 |
-
with open("
|
| 23 |
-
pickle.dump(
|
|
|
|
|
|
|
|
|
| 5 |
import pickle
|
| 6 |
|
| 7 |
# Load Data
|
| 8 |
+
loader = UnstructuredFileLoader("_chat.txt")
|
| 9 |
raw_documents = loader.load()
|
| 10 |
|
| 11 |
# Split text
|
|
|
|
| 15 |
|
| 16 |
# Load Data to vectorstore
|
| 17 |
embeddings = OpenAIEmbeddings()
|
| 18 |
+
chatstore = FAISS.from_documents(documents, embeddings)
|
| 19 |
+
#vectorstore = FAISS.from_documents(documents, embeddings)
|
| 20 |
|
| 21 |
|
| 22 |
# Save vectorstore
|
| 23 |
+
with open("chatstore.pkl", "wb") as f:
|
| 24 |
+
pickle.dump(chatstore, f)
|
| 25 |
+
#with open("vectorstore.pkl", "wb") as f:
|
| 26 |
+
# pickle.dump(vectorstore, f)
|
query_data.py
CHANGED
|
@@ -3,7 +3,7 @@ from langchain.llms import OpenAI
|
|
| 3 |
from langchain.chains import ChatVectorDBChain
|
| 4 |
|
| 5 |
_template = """Given the following conversation and a follow up question, rephrase the follow up question to be a standalone question.
|
| 6 |
-
You can assume the question about the most recent
|
| 7 |
|
| 8 |
Chat History:
|
| 9 |
{chat_history}
|
|
@@ -11,10 +11,10 @@ Follow Up Input: {question}
|
|
| 11 |
Standalone question:"""
|
| 12 |
CONDENSE_QUESTION_PROMPT = PromptTemplate.from_template(_template)
|
| 13 |
|
| 14 |
-
template = """You are an AI assistant for answering questions about the most recent
|
| 15 |
You are given the following extracted parts of a long document and a question. Provide a conversational answer.
|
| 16 |
If you don't know the answer, just say "Hmm, I'm not sure." Don't try to make up an answer.
|
| 17 |
-
If the question is not about the most recent
|
| 18 |
Question: {question}
|
| 19 |
=========
|
| 20 |
{context}
|
|
|
|
| 3 |
from langchain.chains import ChatVectorDBChain
|
| 4 |
|
| 5 |
_template = """Given the following conversation and a follow up question, rephrase the follow up question to be a standalone question.
|
| 6 |
+
You can assume the question about the most recent response being sent.
|
| 7 |
|
| 8 |
Chat History:
|
| 9 |
{chat_history}
|
|
|
|
| 11 |
Standalone question:"""
|
| 12 |
CONDENSE_QUESTION_PROMPT = PromptTemplate.from_template(_template)
|
| 13 |
|
| 14 |
+
template = """You are an AI assistant for answering questions about the most recent chat conversation.
|
| 15 |
You are given the following extracted parts of a long document and a question. Provide a conversational answer.
|
| 16 |
If you don't know the answer, just say "Hmm, I'm not sure." Don't try to make up an answer.
|
| 17 |
+
If the question is not about the most recent files being sent, politely inform them that you are tuned to only answer questions about the files being outside of contents in this chat.
|
| 18 |
Question: {question}
|
| 19 |
=========
|
| 20 |
{context}
|