jonathanjordan21
commited on
Commit
•
151a30b
1
Parent(s):
657b01d
Update custom_llm.py
Browse files- custom_llm.py +19 -5
custom_llm.py
CHANGED
@@ -270,15 +270,29 @@ def custom_unique_df_chain(llm, df):
|
|
270 |
|
271 |
def custom_combined_chain(llm, df_chain, memory_chain):
|
272 |
|
273 |
-
prompt = PromptTemplate.from_template("""<s><INST> Given the following question, classify it as either being more relevant with a dataframe object of ticket submissions' history or several documents of user guide and general knowledge:
|
274 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
275 |
<question>
|
276 |
{question}
|
277 |
</question>
|
278 |
-
|
279 |
-
Respond with ONLY one word either "ticket" or "knowledge"
|
280 |
|
281 |
-
|
|
|
|
|
|
|
|
|
282 |
|
283 |
# def route(info):
|
284 |
# if 'ticket' in info['topic']:
|
@@ -289,7 +303,7 @@ def custom_combined_chain(llm, df_chain, memory_chain):
|
|
289 |
|
290 |
# full_chain = RunnablePassthrough.assign(topic= (prompt | llm)) | RunnableLambda(route)
|
291 |
# combined_chain = prompt | llm
|
292 |
-
return RunnablePassthrough.assign(topic=prompt | llm) | RunnableBranch( (lambda x: "
|
293 |
|
294 |
|
295 |
class CustomLLM(LLM):
|
|
|
270 |
|
271 |
def custom_combined_chain(llm, df_chain, memory_chain):
|
272 |
|
273 |
+
# prompt = PromptTemplate.from_template("""<s><INST> Given the following question, classify it as either being more relevant with a dataframe object of ticket submissions' history or several documents of user guide and general knowledge:
|
274 |
|
275 |
+
# <question>
|
276 |
+
# {question}
|
277 |
+
# </question>
|
278 |
+
|
279 |
+
# Respond with ONLY one word either "ticket" or "knowledge"
|
280 |
+
|
281 |
+
# </s></INST>""")
|
282 |
+
|
283 |
+
prompt = PromptTemplate.from_template("""<s><INST> You have access to the following data sources:
|
284 |
+
1. Dataframe : use this data source to retrieve anything about ticket submission history
|
285 |
+
2. Documents : use this data source to retrieve anything related to user guide and work instruction
|
286 |
+
|
287 |
<question>
|
288 |
{question}
|
289 |
</question>
|
|
|
|
|
290 |
|
291 |
+
|
292 |
+
Respond with ONLY one word either "dataframe" or "documents"
|
293 |
+
|
294 |
+
</s></INST>
|
295 |
+
""")
|
296 |
|
297 |
# def route(info):
|
298 |
# if 'ticket' in info['topic']:
|
|
|
303 |
|
304 |
# full_chain = RunnablePassthrough.assign(topic= (prompt | llm)) | RunnableLambda(route)
|
305 |
# combined_chain = prompt | llm
|
306 |
+
return RunnablePassthrough.assign(topic=prompt | llm) | RunnableBranch( (lambda x: "dataframe" in x['topic'].lower(), df_chain), memory_chain )
|
307 |
|
308 |
|
309 |
class CustomLLM(LLM):
|