From a20ac12dd6300a96f5e892be0d9823483aca599a Mon Sep 17 00:00:00 2001 From: Joseph Cheung Date: Tue, 21 Feb 2023 14:52:13 +0800 Subject: [PATCH] Update webapp.py --- searx/webapp.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/searx/webapp.py b/searx/webapp.py index 37fe6724e..8df1ef86f 100755 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -747,7 +747,7 @@ def search(): # OPENAI GPT try: - url_pair = {} + url_pair = [] prompt = "" for res in results: if 'url' not in res: continue @@ -755,7 +755,7 @@ def search(): if 'title' not in res: continue if res['content'] == '': continue new_url = 'https://url'+str(len(url_pair)+1) - url_pair[new_url] = res['url'] + url_pair.append(res['url']) res['title'] = res['title'].replace("التغريدات مع الردود بواسطة","") res['content'] = res['content'].replace("Translate Tweet. ","") res['content'] = res['content'].replace("Learn more ","") @@ -803,8 +803,8 @@ def search(): if 'choices' in gpt_json: gpt = gpt_json['choices'][0]['text'] gpt = gpt.replace("简报:","").replace("简报:","") - for urls in url_pair.keys(): - gpt = gpt.replace(urls,url_pair[urls]) + for i in range(len(url_pair)-1,-1,-1): + gpt = gpt.replace("https://url"+str(i),url_pair[i]) rgpt = gpt if gpt and gpt!="": @@ -815,9 +815,9 @@ def search(): rgpt = gpt # gpt = markdown.markdown( gpt , extensions=['footnotes']) - for urls in url_pair.keys(): - gpt = gpt.replace("#fn:"+urls.replace("https://url",""),url_pair[urls]) - gpt = gpt.replace("#fn:url"+urls.replace("https://url",""),url_pair[urls]) + for i in range(len(url_pair)-1,-1,-1): + gpt = gpt.replace("#fn:"+str(i),url_pair[i]) + gpt = gpt.replace("#fn:url"+str(i),url_pair[i]) gpt = re.sub(r'
(.*?)
', '', gpt, flags=re.DOTALL) gpt = gpt + '''