Spaces:
Sleeping
Sleeping
Update model_pipelineV2.py
Browse files- model_pipelineV2.py +20 -8
model_pipelineV2.py
CHANGED
|
@@ -55,13 +55,20 @@ class ModelPipeLine:
|
|
| 55 |
return document_separator.join(doc_strings)
|
| 56 |
|
| 57 |
def create_final_chain(self):
|
| 58 |
-
|
| 59 |
answer_prompt, condense_question_prompt = self.get_prompts()
|
| 60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
loaded_memory = RunnablePassthrough.assign(
|
| 62 |
chat_history=RunnableLambda(self.memory.load_memory_variables) | itemgetter("history"),
|
| 63 |
)
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
standalone_question = {
|
| 66 |
"standalone_question": {
|
| 67 |
"question": lambda x: x["question"],
|
|
@@ -70,25 +77,30 @@ class ModelPipeLine:
|
|
| 70 |
| condense_question_prompt
|
| 71 |
| self.llm,
|
| 72 |
}
|
| 73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
retrieved_documents = {
|
| 75 |
"docs": itemgetter("standalone_question") | self.retriever,
|
| 76 |
"question": lambda x: x["standalone_question"],
|
| 77 |
}
|
| 78 |
-
|
| 79 |
final_inputs = {
|
| 80 |
"context": lambda x: self._combine_documents(x["docs"]),
|
| 81 |
"question": itemgetter("question"),
|
| 82 |
}
|
| 83 |
-
|
| 84 |
answer = {
|
| 85 |
"answer": final_inputs | answer_prompt | self.llm,
|
| 86 |
"docs": itemgetter("docs"),
|
| 87 |
}
|
| 88 |
-
|
| 89 |
final_chain = loaded_memory | standalone_question | retrieved_documents | answer
|
| 90 |
-
|
| 91 |
return final_chain
|
|
|
|
| 92 |
|
| 93 |
|
| 94 |
def call_conversational_rag(self,question, chain):
|
|
|
|
| 55 |
return document_separator.join(doc_strings)
|
| 56 |
|
| 57 |
def create_final_chain(self):
|
|
|
|
| 58 |
answer_prompt, condense_question_prompt = self.get_prompts()
|
| 59 |
+
|
| 60 |
+
# Debugging outputs
|
| 61 |
+
print("Condense Question Prompt:", condense_question_prompt)
|
| 62 |
+
print("LLM:", self.llm)
|
| 63 |
+
|
| 64 |
loaded_memory = RunnablePassthrough.assign(
|
| 65 |
chat_history=RunnableLambda(self.memory.load_memory_variables) | itemgetter("history"),
|
| 66 |
)
|
| 67 |
+
|
| 68 |
+
# Check if loaded_memory is valid
|
| 69 |
+
if loaded_memory is None:
|
| 70 |
+
raise ValueError("Loaded memory is None")
|
| 71 |
+
|
| 72 |
standalone_question = {
|
| 73 |
"standalone_question": {
|
| 74 |
"question": lambda x: x["question"],
|
|
|
|
| 77 |
| condense_question_prompt
|
| 78 |
| self.llm,
|
| 79 |
}
|
| 80 |
+
|
| 81 |
+
# Ensure standalone_question is valid
|
| 82 |
+
if standalone_question is None:
|
| 83 |
+
raise ValueError("Standalone question is None")
|
| 84 |
+
|
| 85 |
retrieved_documents = {
|
| 86 |
"docs": itemgetter("standalone_question") | self.retriever,
|
| 87 |
"question": lambda x: x["standalone_question"],
|
| 88 |
}
|
| 89 |
+
|
| 90 |
final_inputs = {
|
| 91 |
"context": lambda x: self._combine_documents(x["docs"]),
|
| 92 |
"question": itemgetter("question"),
|
| 93 |
}
|
| 94 |
+
|
| 95 |
answer = {
|
| 96 |
"answer": final_inputs | answer_prompt | self.llm,
|
| 97 |
"docs": itemgetter("docs"),
|
| 98 |
}
|
| 99 |
+
|
| 100 |
final_chain = loaded_memory | standalone_question | retrieved_documents | answer
|
| 101 |
+
|
| 102 |
return final_chain
|
| 103 |
+
|
| 104 |
|
| 105 |
|
| 106 |
def call_conversational_rag(self,question, chain):
|