Update app.py
Browse files
app.py
CHANGED
|
@@ -559,12 +559,16 @@ Information:
|
|
| 559 |
else:
|
| 560 |
# fallback: take first line
|
| 561 |
output = raw.split("\n")[0].strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 562 |
|
| 563 |
# Clean quotes / trailing punctuation
|
| 564 |
output = output.strip('"').strip()
|
| 565 |
if output.endswith("."):
|
| 566 |
output = output[:-1]
|
| 567 |
-
|
| 568 |
|
| 569 |
|
| 570 |
state["output"] = output
|
|
@@ -770,7 +774,24 @@ def tool_executor(state: AgentState):
|
|
| 770 |
|
| 771 |
elif action.tool == "visit_webpage":
|
| 772 |
try:
|
| 773 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 774 |
except:
|
| 775 |
pass
|
| 776 |
else:
|
|
|
|
| 559 |
else:
|
| 560 |
# fallback: take first line
|
| 561 |
output = raw.split("\n")[0].strip()
|
| 562 |
+
|
| 563 |
+
if "Response:" in output:
|
| 564 |
+
output = output.split("Response:")[-1]
|
| 565 |
+
elif "Response" in output:
|
| 566 |
+
output = output.split("Response")[-1]
|
| 567 |
|
| 568 |
# Clean quotes / trailing punctuation
|
| 569 |
output = output.strip('"').strip()
|
| 570 |
if output.endswith("."):
|
| 571 |
output = output[:-1]
|
|
|
|
| 572 |
|
| 573 |
|
| 574 |
state["output"] = output
|
|
|
|
| 774 |
|
| 775 |
elif action.tool == "visit_webpage":
|
| 776 |
try:
|
| 777 |
+
webpage_results = visit_webpage(**action.args)
|
| 778 |
+
webpage_result = " \n ".join(webpage_results)
|
| 779 |
+
|
| 780 |
+
# for webpage_result in webpage_results:
|
| 781 |
+
query_embeddings = sentence_transformer_model.encode_query(state["messages"][-1].content).reshape(1, -1)
|
| 782 |
+
webpage_information_embeddings = sentence_transformer_model.encode_query(webpage_result).reshape(1, -1)
|
| 783 |
+
query_webpage_information_similarity_score = float(cosine_similarity(query_embeddings, webpage_information_embeddings)[0][0])
|
| 784 |
+
|
| 785 |
+
# logger.info(f"Webpage Information and Similarity Score: {result} - {webpage_result} - {query_webpage_information_similarity_score}")
|
| 786 |
+
|
| 787 |
+
if query_webpage_information_similarity_score > 0.65:
|
| 788 |
+
webpage_information_complete += webpage_result
|
| 789 |
+
webpage_information_complete += " \n "
|
| 790 |
+
webpage_information_complete += " \n "
|
| 791 |
+
|
| 792 |
+
if query_webpage_information_similarity_score > best_query_webpage_information_similarity_score:
|
| 793 |
+
best_query_webpage_information_similarity_score = query_webpage_information_similarity_score
|
| 794 |
+
best_webpage_information = webpage_result
|
| 795 |
except:
|
| 796 |
pass
|
| 797 |
else:
|