Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -27,6 +27,18 @@ ANSWER:
|
|
27 |
"""
|
28 |
CUSTOM_QUESTION_PROMPT = PromptTemplate.from_template(custom_template)
|
29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
# Function to extract text from documents
|
31 |
def get_document_text(uploaded_files):
|
32 |
documents = []
|
@@ -62,15 +74,17 @@ def get_vectorstore(chunks):
|
|
62 |
|
63 |
# Create a conversational chain
|
64 |
def get_conversationchain(vectorstore):
|
65 |
-
llm = ChatOpenAI(temperature=0.
|
66 |
memory = ConversationBufferMemory(memory_key='chat_history', return_messages=True)
|
67 |
-
|
68 |
llm=llm,
|
69 |
-
retriever=vectorstore.as_retriever(),
|
70 |
condense_question_prompt=CUSTOM_QUESTION_PROMPT,
|
71 |
-
memory=memory
|
|
|
72 |
)
|
73 |
-
|
|
|
74 |
# Handle user questions and update chat history
|
75 |
def handle_question(question):
|
76 |
if not st.session_state.conversation:
|
|
|
27 |
"""
|
28 |
CUSTOM_QUESTION_PROMPT = PromptTemplate.from_template(custom_template)
|
29 |
|
30 |
+
prompt_template = """<s>[INST]
|
31 |
+
You will answer from the provided files stored in knowledge base
|
32 |
+
CONTEXT: {context}
|
33 |
+
CHAT HISTORY: {chat_history}
|
34 |
+
QUESTION: {question}
|
35 |
+
ANSWER:
|
36 |
+
</s>[INST]
|
37 |
+
|
38 |
+
"""
|
39 |
+
|
40 |
+
prompt = PromptTemplate(template=prompt_template,
|
41 |
+
input_variables=['context', 'question', 'chat_history'])
|
42 |
# Function to extract text from documents
|
43 |
def get_document_text(uploaded_files):
|
44 |
documents = []
|
|
|
74 |
|
75 |
# Create a conversational chain
|
76 |
def get_conversationchain(vectorstore):
|
77 |
+
llm = ChatOpenAI(temperature=0.5, model_name='gpt-4o-mini')
|
78 |
memory = ConversationBufferMemory(memory_key='chat_history', return_messages=True)
|
79 |
+
conversation_chain = ConversationalRetrievalChain.from_llm(
|
80 |
llm=llm,
|
81 |
+
retriever=vectorstore.as_retriever(search_type="similarity",search_kwargs={"k": 20}),
|
82 |
condense_question_prompt=CUSTOM_QUESTION_PROMPT,
|
83 |
+
memory=memory,
|
84 |
+
combine_docs_chain_kwargs={'prompt': prompt}
|
85 |
)
|
86 |
+
return conversation_chain
|
87 |
+
|
88 |
# Handle user questions and update chat history
|
89 |
def handle_question(question):
|
90 |
if not st.session_state.conversation:
|