Spaces:
Sleeping
Sleeping
John Graham Reynolds
commited on
Commit
·
0191305
1
Parent(s):
a62b777
reference methods in chain directly
Browse files
chain.py
CHANGED
|
@@ -149,11 +149,11 @@ class ChainBuilder:
|
|
| 149 |
return get_and_cache_model(endpoint, extra_params)
|
| 150 |
|
| 151 |
def build_chain(self):
|
| 152 |
-
model = self.get_model()
|
| 153 |
-
prompt = self.get_prompt()
|
| 154 |
-
format_context = self.format_context()
|
| 155 |
-
vector_search_as_retriever = self.get_retriever()
|
| 156 |
-
query_rewrite_prompt = self.get_query_rewrite_prompt()
|
| 157 |
|
| 158 |
# RAG Chain
|
| 159 |
chain = (
|
|
@@ -169,17 +169,17 @@ class ChainBuilder:
|
|
| 169 |
"context": RunnableBranch( # Only re-write the question if there is a chat history - RunnableBranch() is essentially a LCEL if statement
|
| 170 |
(
|
| 171 |
lambda x: len(x["chat_history"]) > 0, #https://python.langchain.com/api_reference/core/runnables/langchain_core.runnables.branch.RunnableBranch.html
|
| 172 |
-
|
| 173 |
),
|
| 174 |
itemgetter("question"), # else, just ask the question
|
| 175 |
)
|
| 176 |
-
|
|
| 177 |
-
| RunnableLambda(format_context),
|
| 178 |
"formatted_chat_history": itemgetter("formatted_chat_history"),
|
| 179 |
"question": itemgetter("question"),
|
| 180 |
}
|
| 181 |
-
|
|
| 182 |
-
|
|
| 183 |
| StrOutputParser()
|
| 184 |
)
|
| 185 |
return chain
|
|
|
|
| 149 |
return get_and_cache_model(endpoint, extra_params)
|
| 150 |
|
| 151 |
def build_chain(self):
|
| 152 |
+
# model = self.get_model()
|
| 153 |
+
# prompt = self.get_prompt()
|
| 154 |
+
# format_context = self.format_context()
|
| 155 |
+
# vector_search_as_retriever = self.get_retriever()
|
| 156 |
+
# query_rewrite_prompt = self.get_query_rewrite_prompt()
|
| 157 |
|
| 158 |
# RAG Chain
|
| 159 |
chain = (
|
|
|
|
| 169 |
"context": RunnableBranch( # Only re-write the question if there is a chat history - RunnableBranch() is essentially a LCEL if statement
|
| 170 |
(
|
| 171 |
lambda x: len(x["chat_history"]) > 0, #https://python.langchain.com/api_reference/core/runnables/langchain_core.runnables.branch.RunnableBranch.html
|
| 172 |
+
self.get_query_rewrite_prompt() | self.get_model() | StrOutputParser(), # rewrite question with context
|
| 173 |
),
|
| 174 |
itemgetter("question"), # else, just ask the question
|
| 175 |
)
|
| 176 |
+
| self.get_retriever() # set 'context' to the result of passing either the base question, or the reformatted question to the retriever for semantic search
|
| 177 |
+
| RunnableLambda(self.format_context),
|
| 178 |
"formatted_chat_history": itemgetter("formatted_chat_history"),
|
| 179 |
"question": itemgetter("question"),
|
| 180 |
}
|
| 181 |
+
| self.get_prompt() # 'context', 'formatted_chat_history', and 'question' passed to prompt
|
| 182 |
+
| self.get_model() # prompt passed to model
|
| 183 |
| StrOutputParser()
|
| 184 |
)
|
| 185 |
return chain
|