8383multiplayer_turn_minor = 1
8484multiplayer_dataformat = "" # used to tell what is the data payload in saved story. set by client
8585multiplayer_lastactive = {} # timestamp of last activity for each unique player
86+ websearch_lastquery = ""
87+ websearch_lastresponse = []
8688preloaded_story = None
8789chatcompl_adapter = None
8890embedded_kailite = None
@@ -1272,8 +1274,14 @@ def detokenize_ids(tokids):
12721274
12731275# Performs a web search using DuckDuckGo and extracts text content from the top results.
12741276def websearch (query ):
1277+ global websearch_lastquery
1278+ global websearch_lastresponse
12751279 if not query or query == "" :
12761280 return []
1281+ query = query [:300 ] # only search first 300 chars, due to search engine limits
1282+ if query == websearch_lastquery :
1283+ print ("Returning cached websearch..." )
1284+ return websearch_lastresponse
12771285 import urllib .parse
12781286 import urllib .request
12791287 import difflib
@@ -1282,7 +1290,7 @@ def websearch(query):
12821290 num_results = 3
12831291 searchresults = []
12841292 if args .debugmode != - 1 and not args .quiet :
1285- print ("Performing websearch..." )
1293+ print ("Performing new websearch..." )
12861294
12871295 def fetch_searched_webpage (url ):
12881296 if args .debugmode :
@@ -1420,6 +1428,9 @@ def handle_data(self, data):
14201428 if args .debugmode != - 1 and not args .quiet :
14211429 print (f"Error fetching URL { search_url } : { e } " )
14221430 return ""
1431+ if len (searchresults ) > 0 :
1432+ websearch_lastquery = query
1433+ websearch_lastresponse = searchresults
14231434 return searchresults
14241435
14251436#################################################################
0 commit comments