Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -259,43 +259,57 @@ def aisearch():
|
|
| 259 |
|
| 260 |
@app.route('/agent/chat/suggestion', methods=['POST'])
|
| 261 |
def process_json():
|
| 262 |
-
print("RQST")
|
| 263 |
print(f"\n{'*' * 100}\n")
|
| 264 |
print("Request Received >>>>>>>>>>>>>>>>>>", datetime.now().strftime("%H:%M:%S"))
|
| 265 |
content_type = request.headers.get('Content-Type')
|
| 266 |
-
if
|
| 267 |
requestQuery = request.get_json()
|
| 268 |
print(type(requestQuery))
|
| 269 |
-
custDetailsPresent=False
|
| 270 |
-
customerName=""
|
| 271 |
-
customerDistrict=""
|
| 272 |
-
if
|
| 273 |
custDetailsPresent = True
|
| 274 |
-
customerName=requestQuery['custDetails']['cName']
|
| 275 |
-
customerDistrict=requestQuery['custDetails']['cDistrict']
|
| 276 |
|
|
|
|
|
|
|
|
|
|
| 277 |
print("chain initiation")
|
| 278 |
-
chainRAG=getRAGChain(customerName, customerDistrict, custDetailsPresent,vectordb)
|
| 279 |
print("chain created")
|
| 280 |
suggestionArray = []
|
|
|
|
| 281 |
|
| 282 |
for index, query in enumerate(requestQuery['message']):
|
| 283 |
-
#message = answering(query)
|
| 284 |
-
|
| 285 |
-
|
|
|
|
|
|
|
|
|
|
| 286 |
print(f"\n{'-' * 100}\n")
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
print(
|
|
|
|
|
|
|
| 290 |
print(f"\n{'-' * 100}\n")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 291 |
message = chainRAG.run({"query": query})
|
| 292 |
-
print("
|
|
|
|
| 293 |
print("Response:", message)
|
| 294 |
if "I don't know" in message:
|
| 295 |
-
|
| 296 |
-
responseJSON={"message":message,"id":index}
|
| 297 |
suggestionArray.append(responseJSON)
|
| 298 |
-
|
|
|
|
| 299 |
else:
|
| 300 |
return 'Content-Type not supported!'
|
| 301 |
|
|
|
|
| 259 |
|
| 260 |
@app.route('/agent/chat/suggestion', methods=['POST'])
|
| 261 |
def process_json():
|
|
|
|
| 262 |
print(f"\n{'*' * 100}\n")
|
| 263 |
print("Request Received >>>>>>>>>>>>>>>>>>", datetime.now().strftime("%H:%M:%S"))
|
| 264 |
content_type = request.headers.get('Content-Type')
|
| 265 |
+
if content_type == 'application/json':
|
| 266 |
requestQuery = request.get_json()
|
| 267 |
print(type(requestQuery))
|
| 268 |
+
custDetailsPresent = False
|
| 269 |
+
customerName = ""
|
| 270 |
+
customerDistrict = ""
|
| 271 |
+
if "custDetails" in requestQuery:
|
| 272 |
custDetailsPresent = True
|
| 273 |
+
customerName = requestQuery['custDetails']['cName']
|
| 274 |
+
customerDistrict = requestQuery['custDetails']['cDistrict']
|
| 275 |
|
| 276 |
+
selectedLLMID=defaultLLMID
|
| 277 |
+
if "llmID" in requestQuery:
|
| 278 |
+
selectedLLMID=(int) (requestQuery['llmID'])
|
| 279 |
print("chain initiation")
|
| 280 |
+
chainRAG = getRAGChain(customerName, customerDistrict, custDetailsPresent, vectordb,selectedLLMID)
|
| 281 |
print("chain created")
|
| 282 |
suggestionArray = []
|
| 283 |
+
searchResultArray = []
|
| 284 |
|
| 285 |
for index, query in enumerate(requestQuery['message']):
|
| 286 |
+
# message = answering(query)
|
| 287 |
+
|
| 288 |
+
relevantDoc = vectordb.similarity_search_with_score(query, distance_metric="cos", k=3)
|
| 289 |
+
print("Printing Retriever Docs")
|
| 290 |
+
for doc in getRetriever(vectordb).get_relevant_documents(query):
|
| 291 |
+
searchResult = {}
|
| 292 |
print(f"\n{'-' * 100}\n")
|
| 293 |
+
searchResult['documentSource'] = doc.metadata['source']
|
| 294 |
+
searchResult['pageContent'] = doc.page_content
|
| 295 |
+
print(doc)
|
| 296 |
+
print("Document Source>>>>>> " + searchResult['documentSource'] + "\n\n")
|
| 297 |
+
print("Page Content>>>>>> " + searchResult['pageContent'] + "\n\n")
|
| 298 |
print(f"\n{'-' * 100}\n")
|
| 299 |
+
searchResultArray.append(searchResult)
|
| 300 |
+
print("Printing Retriever Docs Ended")
|
| 301 |
+
|
| 302 |
+
print("Chain Run Started >>>>>>>>>>>>>>>>>>", datetime.now().strftime("%H:%M:%S"))
|
| 303 |
message = chainRAG.run({"query": query})
|
| 304 |
+
print("Chain Run Completed >>>>>>>>>>>>>>>>>>", datetime.now().strftime("%H:%M:%S"))
|
| 305 |
+
print("query:", query)
|
| 306 |
print("Response:", message)
|
| 307 |
if "I don't know" in message:
|
| 308 |
+
message = "Dear Sir/ Ma'am, Could you please ask questions relevant to Jio?"
|
| 309 |
+
responseJSON = {"message": message, "id": index}
|
| 310 |
suggestionArray.append(responseJSON)
|
| 311 |
+
print("Response Sent >>>>>>>>>>>>>>>>>>", datetime.now().strftime("%H:%M:%S"))
|
| 312 |
+
return jsonify(suggestions=suggestionArray, searchResult=searchResultArray)
|
| 313 |
else:
|
| 314 |
return 'Content-Type not supported!'
|
| 315 |
|