Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -282,7 +282,8 @@ if create_vectorstores:
|
|
282 |
documents = chunks,
|
283 |
vectorstore_name="Vit_All_HF_Embeddings"
|
284 |
)
|
285 |
-
print("vector_store_HF:",vector_store_HF._collection.count(),"chunks.")
|
|
|
286 |
print("")
|
287 |
|
288 |
"""
|
@@ -745,6 +746,76 @@ follow_up_question = "plaese give more details about it, including its use cases
|
|
745 |
chain.invoke({"question":follow_up_question})['answer'])
|
746 |
"""
|
747 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
748 |
def submit_message(prompt, prompt_template, temperature, max_tokens, context_length, state):
|
749 |
|
750 |
|
@@ -754,6 +825,8 @@ def submit_message(prompt, prompt_template, temperature, max_tokens, context_len
|
|
754 |
# return gr.update(value=''), [(history[i]['content'], history[i+1]['content']) for i in range(0, len(history)-1, 2)], state
|
755 |
|
756 |
#prompt_template = prompt_templates[prompt_template]
|
|
|
|
|
757 |
print(prompt_template)
|
758 |
print(prompt_templates[prompt_template])
|
759 |
|
|
|
282 |
documents = chunks,
|
283 |
vectorstore_name="Vit_All_HF_Embeddings"
|
284 |
)
|
285 |
+
print("vector_store_HF:",vector_store_HF._collection.count(),"chunks.", prompt_template)
|
286 |
+
|
287 |
print("")
|
288 |
|
289 |
"""
|
|
|
746 |
chain.invoke({"question":follow_up_question})['answer'])
|
747 |
"""
|
748 |
|
749 |
+
|
750 |
+
|
751 |
+
# It is not clear to me if this is running. If you take it out, it still provides answers but also using different promptTemplate
|
752 |
+
|
753 |
+
def create_ConversationalRetrievalChain(
|
754 |
+
llm,condense_question_llm,
|
755 |
+
retriever,
|
756 |
+
chain_type= 'stuff',
|
757 |
+
language="english",
|
758 |
+
model_name='gemini-pro'
|
759 |
+
#model_name='gpt-3.5-turbo'
|
760 |
+
):
|
761 |
+
"""Create a ConversationalRetrievalChain.
|
762 |
+
First, it passes the follow-up question along with the chat history to an LLM which rephrases
|
763 |
+
the question and generates a standalone query.
|
764 |
+
This query is then sent to the retriever, which fetches relevant documents (context)
|
765 |
+
and passes them along with the standalone question and chat history to an LLM to answer.
|
766 |
+
"""
|
767 |
+
|
768 |
+
# 1. Define the standalone_question prompt.
|
769 |
+
# Pass the follow-up question along with the chat history to the `condense_question_llm`
|
770 |
+
# which rephrases the question and generates a standalone question.
|
771 |
+
|
772 |
+
standalone_question_prompt = PromptTemplate(
|
773 |
+
input_variables=['chat_history', 'question'],
|
774 |
+
template="""Given the following conversation and a follow up question,
|
775 |
+
rephrase the follow up question to be a standalone question, in its original language.\n\n
|
776 |
+
Chat History:\n{chat_history}\n
|
777 |
+
Follow Up Input: {question}\n
|
778 |
+
Standalone question:""")
|
779 |
+
|
780 |
+
# 2. Define the answer_prompt
|
781 |
+
# Pass the standalone question + the chat history + the context (retrieved documents) to the `LLM` wihch will answer
|
782 |
+
|
783 |
+
answer_prompt = ChatPromptTemplate.from_template(answer_template(language=language))
|
784 |
+
|
785 |
+
# 3. Add ConversationSummaryBufferMemory for gpt-3.5, and ConversationBufferMemory for the other models
|
786 |
+
|
787 |
+
memory = create_memory(model_name)
|
788 |
+
|
789 |
+
# 4. Create the ConversationalRetrievalChain
|
790 |
+
|
791 |
+
chain = ConversationalRetrievalChain.from_llm(
|
792 |
+
condense_question_prompt=standalone_question_prompt,
|
793 |
+
combine_docs_chain_kwargs={'prompt': answer_prompt},
|
794 |
+
condense_question_llm=condense_question_llm,
|
795 |
+
|
796 |
+
memory=memory,
|
797 |
+
retriever = base_retriever_HF, #changed this
|
798 |
+
#retriever = retriever,
|
799 |
+
#llm=llm, #changed this
|
800 |
+
llm=instantiate_LLM(
|
801 |
+
LLM_provider="Google",api_key=google_api_key,temperature=0.5,
|
802 |
+
model_name="gemini-pro"),
|
803 |
+
chain_type= chain_type,
|
804 |
+
verbose= False,
|
805 |
+
return_source_documents=True
|
806 |
+
)
|
807 |
+
|
808 |
+
print("Conversational retriever chain created successfully!")
|
809 |
+
|
810 |
+
return chain,memory
|
811 |
+
|
812 |
+
|
813 |
+
|
814 |
+
|
815 |
+
|
816 |
+
|
817 |
+
|
818 |
+
|
819 |
def submit_message(prompt, prompt_template, temperature, max_tokens, context_length, state):
|
820 |
|
821 |
|
|
|
825 |
# return gr.update(value=''), [(history[i]['content'], history[i+1]['content']) for i in range(0, len(history)-1, 2)], state
|
826 |
|
827 |
#prompt_template = prompt_templates[prompt_template]
|
828 |
+
global prompt_template
|
829 |
+
prompt_template = prompt_template
|
830 |
print(prompt_template)
|
831 |
print(prompt_templates[prompt_template])
|
832 |
|