试试联网检索

This commit is contained in:
505030475 2023-04-20 23:58:26 +08:00
parent 325406a650
commit 90e1eef61f
3 changed files with 58 additions and 27 deletions

View File

@ -173,20 +173,23 @@ def get_crazy_functions():
###################### 第三组插件 ###########################
# [第三组插件]: 尚未充分测试的函数插件,放在这里
try:
from crazy_functions.下载arxiv论文翻译摘要 import 下载arxiv论文并翻译摘要
function_plugins.update({
"一键下载arxiv论文并翻译摘要先在input输入编号如1812.10695": {
"Color": "stop",
"AsButton": False, # 加入下拉菜单中
"Function": HotReload(下载arxiv论文并翻译摘要)
}
})
except Exception as err:
print(f'[下载arxiv论文并翻译摘要] 插件导入失败 {str(err)}')
from crazy_functions.下载arxiv论文翻译摘要 import 下载arxiv论文并翻译摘要
function_plugins.update({
"一键下载arxiv论文并翻译摘要先在input输入编号如1812.10695": {
"Color": "stop",
"AsButton": False, # 加入下拉菜单中
"Function": HotReload(下载arxiv论文并翻译摘要)
}
})
from crazy_functions.联网的ChatGPT import 连接网络回答问题
function_plugins.update({
"连接网络回答问题(先输入问题,再点击按钮,需要访问谷歌)": {
"Color": "stop",
"AsButton": False, # 加入下拉菜单中
"Function": HotReload(连接网络回答问题)
}
})
###################### 第n组插件 ###########################
return function_plugins

View File

@ -81,14 +81,31 @@ def test_下载arxiv论文并翻译摘要():
def test_联网回答问题():
from crazy_functions.联网的ChatGPT import 连接网络回答问题
# txt = "“我们称之为高效”是什么梗?" #
# txt = "为什么说枪毙P社玩家没有一个冤枉的" #
# txt = "谁是应急食品?" # '根据以上搜索结果可以得知,应急食品是“原神”游戏中的角色派蒙的外号。'
# txt = "道路千万条,安全第一条。后面两句是?" # '行车不规范,亲人两行泪。'
# txt = "特朗普为什么被捕了?" # 特朗普涉嫌向一名色情片女星付“封口费”,因此被刑事起诉,随后前往纽约市出庭受审。在不同的搜索结果中,可能会有不同的具体描述和表述方式。
# txt = "丁仪砸了水滴之后发生了什么?" # 丁仪用地质锤砸烂了水滴这个行为让三体智子和其他观众们感到震惊和不解。在第1份搜索结果中作者吐槽了一个脑洞——丁仪的破解方法是通过修炼、悟道和掌握一种新的“道”称为“丁仪化身宇宙之道可以轻易出现在宇宙的任何一个地方.............
txt = "What is in the canister?" # 根据搜索结果并没有找到与 Rainbow Six Siege 游戏中 Smoke 的 Canister 中装有何种物质相关的官方信息。
for cookies, cb, hist, msg in 连接网络回答问题(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, web_port): print(cb)
# txt = "“我们称之为高效”是什么梗?"
# >> 从第0份、第1份、第2份搜索结果可以看出“我们称之为高效”是指在游戏社区中用户们用来形容一些游戏策略或行为非常高效且能够带来好的效果的用语。这个用语最初可能是在群星Stellaris这个游戏里面流行起来的后来也传播到了其他游戏中比如巨像Titan等游戏。其中第1份搜索结果中的一篇文章也指出“我们称之为高效”这 一用语来源于群星Stellaris游戏中的一个情节。
# txt = "为什么说枪毙P社玩家没有一个冤枉的"
# >> 它们都是关于一个知乎用户所发的帖子引用了一群游戏玩家对于需要对P社玩家进行枪毙的讨论这个话题的本质是玩家们对于P 社游戏中的政治与历史元素的不同看法,以及其中不少玩家以极端立场宣扬的想法和言论,因此有人就以枪毙这些玩家来回应此类言论。但是这个话题本身并没有实质内容,只是一个玩笑或者恶搞,并不应该被当做真实的态度或者观点,因此这种说法没有实际意义。
# txt = "谁是应急食品?"
# >> '根据以上搜索结果可以得知,应急食品是“原神”游戏中的角色派蒙的外号。'
# txt = "道路千万条,安全第一条。后面两句是?"
# >> '行车不规范,亲人两行泪。'
# txt = "What is in the canister?"
# >> Rainbow Six Siege 游戏中 Smoke 的 Canister 中装有何种物质相关的官方信息。
# txt = "失败的man是什么?"
# >> 根据第1份搜索结果可以得知失败的man是指一位在B站购买了蜘蛛侠COS服后穿上后被网友嘲笑的UP主而“失败的man”是蜘蛛侠英文名“spiderman”的谐音梗并且网友们还 给这位UP主起了“苍蝇侠”的外号。因此失败的man是指这位UP主在穿上蜘蛛侠COS服后被网友嘲笑的情况。
# txt = "老六是什么,起源于哪里?"
# >> 老六是网络流行语最初起源于游戏《CSGO》指游戏中玩家中独来独往、游离于队伍之外的“自由人”或玩得比较菜或者玩得比较阴险的人 ,后来逐渐演变成指玩得比较阴险的玩家。
# txt = "罗小黑战记因为什么经常被吐槽?"
# >> 3. 更新速度。罗小黑战记的更新时间不定,时而快时而慢,给观众留下了等待的时间过长的印象。
# txt = "沙特、伊朗最近的关系如何?"
# >> 最近在中国的斡旋下沙特和伊朗于3月10日达成了恢复两国外交关系的协议这表明两国关系已经重新回到正常化状态。
# txt = "You should have gone for the head. What does that mean?"
# >> 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.
txt = "AutoGPT是什么"
# >> AutoGPT是一个基于GPT-4语言模型的开源应用程序。它可以根据用户需求自主执行任务包括事件分析、营销方案撰写、代码编程、数学运算等等并完全不需要用户插手。它可以自己思考给出实现的步骤和实现细节甚至可以自问自答执 行任务。最近它在GitHub上爆火成为了业内最热门的项目之一。
# txt = "钟离带什么圣遗物?"
for cookies, cb, hist, msg in 连接网络回答问题(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, web_port):
print("当前问答:", cb[-1][-1].replace("\n"," "))
for i, it in enumerate(cb): print亮蓝(it[0]); print亮黄(it[1])
# test_解析一个Python项目()

View File

@ -36,8 +36,15 @@ def scrape_text(url, proxies) -> str:
Returns:
str: The scraped text
"""
headers = {'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'}
response = requests.get(url, headers=headers, proxies=proxies)
headers = {
'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',
'Content-Type': 'text/plain',
}
try:
response = requests.get(url, headers=headers, proxies=proxies, timeout=8)
if response.encoding == "ISO-8859-1": response.encoding = response.apparent_encoding
except:
return "无法连接到该网页"
soup = BeautifulSoup(response.text, "html.parser")
for script in soup(["script", "style"]):
script.extract()
@ -70,20 +77,24 @@ def 连接网络回答问题(txt, llm_kwargs, plugin_kwargs, chatbot, history, s
history = []
# ------------- < 第2步依次访问网页 > -------------
max_search_result = 4 # 最多收纳多少个网页的结果
max_search_result = 5 # 最多收纳多少个网页的结果
for index, url in enumerate(urls[:max_search_result]):
res = scrape_text(url['link'], proxies)
history.extend([f"{index}份搜索结果:", res])
chatbot.append([f"{index}份搜索结果:", res[:500]])
chatbot.append([f"{index}份搜索结果:", res[:500]+"......"])
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 # 由于请求gpt需要一段时间我们先及时地做一次界面更新
# ------------- < 第3步ChatGPT综合 > -------------
i_say = f"从以上搜索结果中抽取信息,然后回答问题:{txt}"
i_say, history = input_clipping(inputs=i_say, history=history, max_token_limit=model_info[llm_kwargs['llm_model']]['max_token']//2)
i_say, history = input_clipping( # 裁剪输入从最长的条目开始裁剪防止爆token
inputs=i_say,
history=history,
max_token_limit=model_info[llm_kwargs['llm_model']]['max_token']*3//4
)
gpt_say = yield from request_gpt_model_in_new_thread_with_ui_alive(
inputs=i_say, inputs_show_user=i_say,
llm_kwargs=llm_kwargs, chatbot=chatbot, history=history,
sys_prompt="请从给定文本中抽取信息"
sys_prompt="请从给定的若干条搜索结果中抽取信息,对最相关的两个搜索结果进行总结,然后回答问题。"
)
chatbot[-1] = (i_say, gpt_say)
history.append(i_say);history.append(gpt_say)