Sandiago21 commited on
Commit
680ab2c
·
verified ·
1 Parent(s): 521f373

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -3
app.py CHANGED
@@ -530,7 +530,7 @@ DO NOT add anything additional and return ONLY what is asked and in the format a
530
 
531
  If you output anything else, it is incorrect.
532
 
533
- If there is no information provided ONLY then answer based on your own knowledge. Otherwise, leverage the information provided to answer the user's question exactly without adding anything else.
534
 
535
  Example of valid json response for user request: Who was the winner of 2025 World Snooker Championship:
536
  Response: Zhao Xintong.
@@ -850,7 +850,7 @@ def tool_executor(state: AgentState):
850
 
851
  except Exception as e:
852
  logger.info(f"Tool Executor - Exception: {e}")
853
-
854
  elif action.tool == "visit_webpage":
855
  try:
856
  if "www.youtube.com" in str(action.args["url"]):
@@ -866,7 +866,26 @@ def tool_executor(state: AgentState):
866
  "[Music]",
867
  "isn't that hot",
868
  "extremely",]
869
- webpage_information_complete = "? \n ".join(texts)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
870
  else:
871
  webpage_results = visit_webpage_wiki(action.args["url"])
872
  webpage_result = " \n ".join(webpage_results)
 
530
 
531
  If you output anything else, it is incorrect.
532
 
533
+ If there is no information provided or the information is not relevant then answer as best based on your own knowledge.
534
 
535
  Example of valid json response for user request: Who was the winner of 2025 World Snooker Championship:
536
  Response: Zhao Xintong.
 
850
 
851
  except Exception as e:
852
  logger.info(f"Tool Executor - Exception: {e}")
853
+
854
  elif action.tool == "visit_webpage":
855
  try:
856
  if "www.youtube.com" in str(action.args["url"]):
 
866
  "[Music]",
867
  "isn't that hot",
868
  "extremely",]
869
+ webpage_information_complete = " \n ".join(texts)
870
+
871
+
872
+ index = 0
873
+ counter = 0
874
+ best_query_webpage_information_similarity_score = 0.0
875
+ for text in texts:
876
+ query_embeddings = sentence_transformer_model.encode_query(state["messages"][-1].content).reshape(1, -1)
877
+ webpage_information_embeddings = sentence_transformer_model.encode_query(text).reshape(1, -1)
878
+ query_webpage_information_similarity_score = float(cosine_similarity(query_embeddings, webpage_information_embeddings)[0][0])
879
+
880
+ if query_webpage_information_similarity_score > best_query_webpage_information_similarity_score:
881
+ best_query_webpage_information_similarity_score = query_webpage_information_similarity_score
882
+ index = counter
883
+
884
+ counter += 1
885
+
886
+ webpage_information_complete = f"""answer: {texts[index]}"""
887
+ state["best_query_webpage_information_similarity_score"] = 1.0
888
+
889
  else:
890
  webpage_results = visit_webpage_wiki(action.args["url"])
891
  webpage_result = " \n ".join(webpage_results)