Spaces:
				
			
			
	
			
			
					
		Running
		
	
	
	
			
			
	
	
	
	
		
		
					
		Running
		
	试试联网检索
Browse files- crazy_functional.py +16 -13
- crazy_functions/crazy_functions_test.py +25 -8
- crazy_functions/联网的ChatGPT.py +17 -6
    	
        crazy_functional.py
    CHANGED
    
    | @@ -173,20 +173,23 @@ def get_crazy_functions(): | |
| 173 |  | 
| 174 | 
             
                ###################### 第三组插件 ###########################
         | 
| 175 | 
             
                # [第三组插件]: 尚未充分测试的函数插件,放在这里
         | 
| 176 | 
            -
                 | 
| 177 | 
            -
             | 
| 178 | 
            -
                     | 
| 179 | 
            -
                        " | 
| 180 | 
            -
             | 
| 181 | 
            -
             | 
| 182 | 
            -
             | 
| 183 | 
            -
             | 
| 184 | 
            -
                    })
         | 
| 185 | 
            -
             | 
| 186 | 
            -
                except Exception as err:
         | 
| 187 | 
            -
                    print(f'[下载arxiv论文并翻译摘要] 插件导入失败 {str(err)}')
         | 
| 188 |  | 
| 189 | 
            -
             | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 190 |  | 
| 191 | 
             
                ###################### 第n组插件 ###########################
         | 
| 192 | 
             
                return function_plugins
         | 
|  | |
| 173 |  | 
| 174 | 
             
                ###################### 第三组插件 ###########################
         | 
| 175 | 
             
                # [第三组插件]: 尚未充分测试的函数插件,放在这里
         | 
| 176 | 
            +
                from crazy_functions.下载arxiv论文翻译摘要 import 下载arxiv论文并翻译摘要
         | 
| 177 | 
            +
                function_plugins.update({
         | 
| 178 | 
            +
                    "一键下载arxiv论文并翻译摘要(先在input输入编号,如1812.10695)": {
         | 
| 179 | 
            +
                        "Color": "stop",
         | 
| 180 | 
            +
                        "AsButton": False,  # 加入下拉菜单中
         | 
| 181 | 
            +
                        "Function": HotReload(下载arxiv论文并翻译摘要)
         | 
| 182 | 
            +
                    }
         | 
| 183 | 
            +
                })
         | 
|  | |
|  | |
|  | |
|  | |
| 184 |  | 
| 185 | 
            +
                from crazy_functions.联网的ChatGPT import 连接网络回答问题
         | 
| 186 | 
            +
                function_plugins.update({
         | 
| 187 | 
            +
                    "连接网络回答问题(先输入问题,再点击按钮,需要访问谷歌)": {
         | 
| 188 | 
            +
                        "Color": "stop",
         | 
| 189 | 
            +
                        "AsButton": False,  # 加入下拉菜单中
         | 
| 190 | 
            +
                        "Function": HotReload(连接网络回答问题)
         | 
| 191 | 
            +
                    }
         | 
| 192 | 
            +
                })
         | 
| 193 |  | 
| 194 | 
             
                ###################### 第n组插件 ###########################
         | 
| 195 | 
             
                return function_plugins
         | 
    	
        crazy_functions/crazy_functions_test.py
    CHANGED
    
    | @@ -81,14 +81,31 @@ def test_下载arxiv论文并翻译摘要(): | |
| 81 |  | 
| 82 | 
             
            def test_联网回答问题():
         | 
| 83 | 
             
                from crazy_functions.联网的ChatGPT import 连接网络回答问题
         | 
| 84 | 
            -
                # txt = "“我们称之为高效”是什么梗?" | 
| 85 | 
            -
                #  | 
| 86 | 
            -
                # txt = " | 
| 87 | 
            -
                #  | 
| 88 | 
            -
                # txt = " | 
| 89 | 
            -
                #  | 
| 90 | 
            -
                txt = " | 
| 91 | 
            -
                 | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 92 | 
             
                for i, it in enumerate(cb): print亮蓝(it[0]); print亮黄(it[1])
         | 
| 93 |  | 
| 94 | 
             
            # test_解析一个Python项目()
         | 
|  | |
| 81 |  | 
| 82 | 
             
            def test_联网回答问题():
         | 
| 83 | 
             
                from crazy_functions.联网的ChatGPT import 连接网络回答问题
         | 
| 84 | 
            +
                # txt = "“我们称之为高效”是什么梗?"
         | 
| 85 | 
            +
                # >>        从第0份、第1份、第2份搜索结果可以看出,“我们称之为高效”是指在游戏社区中,用户们用来形容一些游戏策略或行为非常高效且能够带来好的效果的用语。这个用语最初可能是在群星(Stellaris)这个游戏里面流行起来的,后来也传播到了其他游戏中,比如巨像(Titan)等游戏。其中第1份搜索结果中的一篇文章也指出,“我们称之为高效”这 一用语来源于群星(Stellaris)游戏中的一个情节。
         | 
| 86 | 
            +
                # txt = "为什么说枪毙P社玩家没有一个冤枉的?"
         | 
| 87 | 
            +
                # >>        它们都是关于一个知乎用户所发的帖子,引用了一群游戏玩家对于需要对P社玩家进行枪毙的讨论,这个话题的本质是玩家们对于P 社游戏中的政治与历史元素的不同看法,以及其中不少玩家以极端立场宣扬的想法和言论,因此有人就以枪毙这些玩家来回应此类言论。但是这个话题本身并没有实质内容,只是一个玩笑或者恶搞,并不应该被当做真实的态度或者观点,因此这种说法没有实际意义。
         | 
| 88 | 
            +
                # txt = "谁是应急食品?"
         | 
| 89 | 
            +
                # >>        '根据以上搜索结果可以得知,应急食品是“原神”游戏中的角色派蒙的外号。'
         | 
| 90 | 
            +
                # txt = "道路千万条,安全第一条。后面两句是?"
         | 
| 91 | 
            +
                # >>        '行车不规范,亲人两行泪。'
         | 
| 92 | 
            +
                # txt = "What is in the canister?"
         | 
| 93 | 
            +
                # >>        Rainbow Six Siege 游戏中 Smoke 的 Canister 中装有何种物质相关的官方信息。
         | 
| 94 | 
            +
                # txt = "失败的man是什么?"
         | 
| 95 | 
            +
                # >>        根据第1份搜索结果,可以得知失败的man是指一位在B站购买了蜘蛛侠COS服后穿上后被网友嘲笑的UP主,而“失败的man”是蜘蛛侠英文名“spiderman”的谐音梗,并且网友们还 给这位UP主起了“苍蝇侠”的外号。因此,失败的man是指这位UP主在穿上蜘蛛侠COS服后被网友嘲笑的情况。
         | 
| 96 | 
            +
                # txt = "老六是什么,起源于哪里?"
         | 
| 97 | 
            +
                # >>        老六是网络流行语,最初起源于游戏《CSGO》,指游戏中玩家中独来独往、游离于队伍之外的“自由人”或玩得比较菜或者玩得比较阴险的人 ,后来逐渐演变成指玩得比较阴险的玩家。
         | 
| 98 | 
            +
                # txt = "罗小黑战记因为什么经常被吐槽?"
         | 
| 99 | 
            +
                # >>        3. 更新速度。罗小黑战记的更新时间不定,时而快时而慢,给观众留下了等待的时间过长的印象。
         | 
| 100 | 
            +
                # txt = "沙特、伊朗最近的关系如何?"
         | 
| 101 | 
            +
                # >>        最近在中国的斡旋下,沙特和伊朗于3月10日达成了恢复两国外交关系的协议,这表明两国关系已经重新回到正常化状态。
         | 
| 102 | 
            +
                # txt = "You should have gone for the head. What does that mean?"
         | 
| 103 | 
            +
                # >>        The phrase "You should have gone for the head" is a quote from the Marvel movies, Avengers: Infinity War and Avengers: Endgame. It was spoken by the character Thanos in Infinity War and by Thor in Endgame.
         | 
| 104 | 
            +
                txt = "AutoGPT是什么?"
         | 
| 105 | 
            +
                # >>        AutoGPT是一个基于GPT-4语言模型的开源应用程序。它可以根据用户需求自主执行任务,包括事件分析、营销方案撰写、代码编程、数学运算等等,并完全不需要用户插手。它可以自己思考,给出实现的步骤和实现细节,甚至可以自问自答执 行任务。最���它在GitHub上爆火,成为了业内最热门的项目之一。
         | 
| 106 | 
            +
                # txt = "钟离带什么圣遗物?"
         | 
| 107 | 
            +
                for cookies, cb, hist, msg in 连接网络回答问题(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, web_port): 
         | 
| 108 | 
            +
                    print("当前问答:", cb[-1][-1].replace("\n"," "))
         | 
| 109 | 
             
                for i, it in enumerate(cb): print亮蓝(it[0]); print亮黄(it[1])
         | 
| 110 |  | 
| 111 | 
             
            # test_解析一个Python项目()
         | 
    	
        crazy_functions/联网的ChatGPT.py
    CHANGED
    
    | @@ -36,8 +36,15 @@ def scrape_text(url, proxies) -> str: | |
| 36 | 
             
                Returns:
         | 
| 37 | 
             
                    str: The scraped text
         | 
| 38 | 
             
                """
         | 
| 39 | 
            -
                headers = { | 
| 40 | 
            -
             | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 41 | 
             
                soup = BeautifulSoup(response.text, "html.parser")
         | 
| 42 | 
             
                for script in soup(["script", "style"]):
         | 
| 43 | 
             
                    script.extract()
         | 
| @@ -70,20 +77,24 @@ def 连接网络回答问题(txt, llm_kwargs, plugin_kwargs, chatbot, history, s | |
| 70 | 
             
                history = []
         | 
| 71 |  | 
| 72 | 
             
                # ------------- < 第2步:依次访问网页 > -------------
         | 
| 73 | 
            -
                max_search_result =  | 
| 74 | 
             
                for index, url in enumerate(urls[:max_search_result]):
         | 
| 75 | 
             
                    res = scrape_text(url['link'], proxies)
         | 
| 76 | 
             
                    history.extend([f"第{index}份搜索结果:", res])
         | 
| 77 | 
            -
                    chatbot.append([f"第{index}份搜索结果:", res[:500]])
         | 
| 78 | 
             
                    yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 # 由于请求gpt需要一段时间,我们先及时地做一次界面更新
         | 
| 79 |  | 
| 80 | 
             
                # ------------- < 第3步:ChatGPT综合 > -------------
         | 
| 81 | 
             
                i_say = f"从以上搜索结果中抽取信息,然后回答问题:{txt}"
         | 
| 82 | 
            -
                i_say, history = input_clipping( | 
|  | |
|  | |
|  | |
|  | |
| 83 | 
             
                gpt_say = yield from request_gpt_model_in_new_thread_with_ui_alive(
         | 
| 84 | 
             
                    inputs=i_say, inputs_show_user=i_say, 
         | 
| 85 | 
             
                    llm_kwargs=llm_kwargs, chatbot=chatbot, history=history, 
         | 
| 86 | 
            -
                    sys_prompt=" | 
| 87 | 
             
                )
         | 
| 88 | 
             
                chatbot[-1] = (i_say, gpt_say)
         | 
| 89 | 
             
                history.append(i_say);history.append(gpt_say)
         | 
|  | |
| 36 | 
             
                Returns:
         | 
| 37 | 
             
                    str: The scraped text
         | 
| 38 | 
             
                """
         | 
| 39 | 
            +
                headers = {
         | 
| 40 | 
            +
                    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.61 Safari/537.36',
         | 
| 41 | 
            +
                    'Content-Type': 'text/plain',
         | 
| 42 | 
            +
                }
         | 
| 43 | 
            +
                try: 
         | 
| 44 | 
            +
                    response = requests.get(url, headers=headers, proxies=proxies, timeout=8)
         | 
| 45 | 
            +
                    if response.encoding == "ISO-8859-1": response.encoding = response.apparent_encoding
         | 
| 46 | 
            +
                except: 
         | 
| 47 | 
            +
                    return "无法连接到该网页"
         | 
| 48 | 
             
                soup = BeautifulSoup(response.text, "html.parser")
         | 
| 49 | 
             
                for script in soup(["script", "style"]):
         | 
| 50 | 
             
                    script.extract()
         | 
|  | |
| 77 | 
             
                history = []
         | 
| 78 |  | 
| 79 | 
             
                # ------------- < 第2步:依次访问网页 > -------------
         | 
| 80 | 
            +
                max_search_result = 5   # 最多收纳多少个网页的结果
         | 
| 81 | 
             
                for index, url in enumerate(urls[:max_search_result]):
         | 
| 82 | 
             
                    res = scrape_text(url['link'], proxies)
         | 
| 83 | 
             
                    history.extend([f"第{index}份搜索结果:", res])
         | 
| 84 | 
            +
                    chatbot.append([f"第{index}份搜索结果:", res[:500]+"......"])
         | 
| 85 | 
             
                    yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 # 由于请求gpt需要一段时间,我们先及时地做一次界面更新
         | 
| 86 |  | 
| 87 | 
             
                # ------------- < 第3步:ChatGPT综合 > -------------
         | 
| 88 | 
             
                i_say = f"从以上搜索结果中抽取信息,然后回答问题:{txt}"
         | 
| 89 | 
            +
                i_say, history = input_clipping(    # 裁剪输入,从最长的条目开始裁剪,防止爆token
         | 
| 90 | 
            +
                    inputs=i_say, 
         | 
| 91 | 
            +
                    history=history, 
         | 
| 92 | 
            +
                    max_token_limit=model_info[llm_kwargs['llm_model']]['max_token']*3//4
         | 
| 93 | 
            +
                )
         | 
| 94 | 
             
                gpt_say = yield from request_gpt_model_in_new_thread_with_ui_alive(
         | 
| 95 | 
             
                    inputs=i_say, inputs_show_user=i_say, 
         | 
| 96 | 
             
                    llm_kwargs=llm_kwargs, chatbot=chatbot, history=history, 
         | 
| 97 | 
            +
                    sys_prompt="请从给定的若干条搜索结果中抽取信息,对最相关的两个搜索结果进行总结,然后回答问题。"
         | 
| 98 | 
             
                )
         | 
| 99 | 
             
                chatbot[-1] = (i_say, gpt_say)
         | 
| 100 | 
             
                history.append(i_say);history.append(gpt_say)
         |