镜像自地址
https://github.com/binary-husky/gpt_academic.git
已同步 2025-12-06 22:46:48 +00:00
add fail fallback option for media plugin
这个提交包含在:
@@ -26,6 +26,7 @@ class VideoResource(BaseModel):
|
|||||||
title: str = Field(description="title of the video")
|
title: str = Field(description="title of the video")
|
||||||
author: str = Field(description="author/uploader of the video")
|
author: str = Field(description="author/uploader of the video")
|
||||||
bvid: str = Field(description="unique ID of the video")
|
bvid: str = Field(description="unique ID of the video")
|
||||||
|
another_failsafe_bvid: str = Field(description="provide another bvid, the other one is not working")
|
||||||
|
|
||||||
|
|
||||||
def get_video_resource(search_keyword):
|
def get_video_resource(search_keyword):
|
||||||
@@ -53,6 +54,10 @@ def download_video(bvid, user_name, chatbot, history):
|
|||||||
chatbot.append((None, "下载音频, 请稍等...")); yield from update_ui(chatbot=chatbot, history=history)
|
chatbot.append((None, "下载音频, 请稍等...")); yield from update_ui(chatbot=chatbot, history=history)
|
||||||
downloaded_files = yield from download_video(bvid, only_audio=True, user_name=user_name, chatbot=chatbot, history=history)
|
downloaded_files = yield from download_video(bvid, only_audio=True, user_name=user_name, chatbot=chatbot, history=history)
|
||||||
|
|
||||||
|
if len(downloaded_files) == 0:
|
||||||
|
# failed to download audio
|
||||||
|
return []
|
||||||
|
|
||||||
# preview
|
# preview
|
||||||
preview_list = [promote_file_to_downloadzone(fp) for fp in downloaded_files]
|
preview_list = [promote_file_to_downloadzone(fp) for fp in downloaded_files]
|
||||||
file_links = generate_file_link(preview_list)
|
file_links = generate_file_link(preview_list)
|
||||||
@@ -101,39 +106,46 @@ def 多媒体任务(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_pro
|
|||||||
# 搜索
|
# 搜索
|
||||||
chatbot.append((txt, "检索中, 请稍等..."))
|
chatbot.append((txt, "检索中, 请稍等..."))
|
||||||
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
|
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
|
||||||
|
if "跳过联网搜索" not in user_wish:
|
||||||
|
# 结构化生成
|
||||||
|
rf_req = dedent(f"""
|
||||||
|
The user wish to get the following resource:
|
||||||
|
{user_wish}
|
||||||
|
You task is to help the user to search it on google.
|
||||||
|
Generate search keywords (less than 7 keywords).
|
||||||
|
""")
|
||||||
|
gpt_json_io = GptJsonIO(Query)
|
||||||
|
inputs = rf_req + gpt_json_io.format_instructions
|
||||||
|
run_gpt_fn = lambda inputs, sys_prompt: predict_no_ui_long_connection(inputs=inputs, llm_kwargs=llm_kwargs, history=[], sys_prompt=sys_prompt, observe_window=[])
|
||||||
|
analyze_res = run_gpt_fn(inputs, "")
|
||||||
|
logger.info(analyze_res)
|
||||||
|
query: Query = gpt_json_io.generate_output_auto_repair(analyze_res, run_gpt_fn)
|
||||||
|
internet_search_keyword = query.search_keyword
|
||||||
|
|
||||||
# 结构化生成
|
yield from update_ui_lastest_msg(lastmsg=f"发起互联网检索: {internet_search_keyword} ...", chatbot=chatbot, history=[], delay=1)
|
||||||
rf_req = dedent(f"""
|
from crazy_functions.Internet_GPT import internet_search_with_analysis_prompt
|
||||||
The user wish to get the following resource:
|
result = yield from internet_search_with_analysis_prompt(
|
||||||
{user_wish}
|
prompt=internet_search_keyword,
|
||||||
You task is to help the user to search it on google.
|
analysis_prompt="请根据搜索结果分析,获取用户需要找的资源的名称、作者、出处等信息。",
|
||||||
Generate search keywords (less than 7 keywords).
|
llm_kwargs=llm_kwargs,
|
||||||
""")
|
chatbot=chatbot
|
||||||
gpt_json_io = GptJsonIO(Query)
|
)
|
||||||
inputs = rf_req + gpt_json_io.format_instructions
|
|
||||||
run_gpt_fn = lambda inputs, sys_prompt: predict_no_ui_long_connection(inputs=inputs, llm_kwargs=llm_kwargs, history=[], sys_prompt=sys_prompt, observe_window=[])
|
|
||||||
analyze_res = run_gpt_fn(inputs, "")
|
|
||||||
logger.info(analyze_res)
|
|
||||||
query: Query = gpt_json_io.generate_output_auto_repair(analyze_res, run_gpt_fn)
|
|
||||||
internet_search_keyword = query.search_keyword
|
|
||||||
|
|
||||||
yield from update_ui_lastest_msg(lastmsg=f"发起互联网检索: {internet_search_keyword} ...", chatbot=chatbot, history=[], delay=1)
|
yield from update_ui_lastest_msg(lastmsg=f"互联网检索结论: {result} \n\n 正在生成进一步检索方案 ...", chatbot=chatbot, history=[], delay=1)
|
||||||
from crazy_functions.Internet_GPT import internet_search_with_analysis_prompt
|
rf_req = dedent(f"""
|
||||||
result = yield from internet_search_with_analysis_prompt(
|
The user wish to get the following resource:
|
||||||
prompt=internet_search_keyword,
|
{user_wish}
|
||||||
analysis_prompt="请根据搜索结果分析,获取用户需要找的资源的名称、作者、出处等信息。",
|
Meanwhile, you can access another expert's opinion on the user's wish:
|
||||||
llm_kwargs=llm_kwargs,
|
{result}
|
||||||
chatbot=chatbot
|
Generate search keywords (less than 5 keywords) for video download engine accordingly.
|
||||||
)
|
""")
|
||||||
|
else:
|
||||||
yield from update_ui_lastest_msg(lastmsg=f"互联网检索结论: {result} \n\n 正在生成进一步检索方案 ...", chatbot=chatbot, history=[], delay=1)
|
user_wish = user_wish.replace("跳过联网搜索", "").strip()
|
||||||
rf_req = dedent(f"""
|
rf_req = dedent(f"""
|
||||||
The user wish to get the following resource:
|
The user wish to get the following resource:
|
||||||
{user_wish}
|
{user_wish}
|
||||||
Meanwhile, you can access another expert's opinion on the user's wish:
|
Generate reseach keywords (less than 5 keywords) accordingly.
|
||||||
{result}
|
""")
|
||||||
Generate search keywords (less than 5 keywords) for video download engine accordingly.
|
|
||||||
""")
|
|
||||||
gpt_json_io = GptJsonIO(Query)
|
gpt_json_io = GptJsonIO(Query)
|
||||||
inputs = rf_req + gpt_json_io.format_instructions
|
inputs = rf_req + gpt_json_io.format_instructions
|
||||||
run_gpt_fn = lambda inputs, sys_prompt: predict_no_ui_long_connection(inputs=inputs, llm_kwargs=llm_kwargs, history=[], sys_prompt=sys_prompt, observe_window=[])
|
run_gpt_fn = lambda inputs, sys_prompt: predict_no_ui_long_connection(inputs=inputs, llm_kwargs=llm_kwargs, history=[], sys_prompt=sys_prompt, observe_window=[])
|
||||||
@@ -141,7 +153,6 @@ def 多媒体任务(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_pro
|
|||||||
logger.info(analyze_res)
|
logger.info(analyze_res)
|
||||||
query: Query = gpt_json_io.generate_output_auto_repair(analyze_res, run_gpt_fn)
|
query: Query = gpt_json_io.generate_output_auto_repair(analyze_res, run_gpt_fn)
|
||||||
video_engine_keywords = query.search_keyword
|
video_engine_keywords = query.search_keyword
|
||||||
|
|
||||||
# 关键词展示
|
# 关键词展示
|
||||||
chatbot.append((None, f"检索关键词已确认: {video_engine_keywords}。筛选中, 请稍等..."))
|
chatbot.append((None, f"检索关键词已确认: {video_engine_keywords}。筛选中, 请稍等..."))
|
||||||
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
|
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
|
||||||
@@ -168,6 +179,7 @@ def 多媒体任务(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_pro
|
|||||||
2. The time duration of the video should be less than 10 minutes.
|
2. The time duration of the video should be less than 10 minutes.
|
||||||
3. You should analyze the search results first, before giving your answer.
|
3. You should analyze the search results first, before giving your answer.
|
||||||
4. Use Chinese if possible.
|
4. Use Chinese if possible.
|
||||||
|
5. Beside the primary video selection, give a backup video resource `bvid`.
|
||||||
""")
|
""")
|
||||||
gpt_json_io = GptJsonIO(VideoResource)
|
gpt_json_io = GptJsonIO(VideoResource)
|
||||||
inputs = rf_req_2 + gpt_json_io.format_instructions
|
inputs = rf_req_2 + gpt_json_io.format_instructions
|
||||||
@@ -189,7 +201,11 @@ def 多媒体任务(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_pro
|
|||||||
|
|
||||||
if video_resource and video_resource.bvid:
|
if video_resource and video_resource.bvid:
|
||||||
logger.info(video_resource)
|
logger.info(video_resource)
|
||||||
yield from download_video(video_resource.bvid, chatbot.get_user(), chatbot, history)
|
downloaded = yield from download_video(video_resource.bvid, chatbot.get_user(), chatbot, history)
|
||||||
|
if not downloaded:
|
||||||
|
chatbot.append((None, f"下载失败, 尝试备选 ..."))
|
||||||
|
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
|
||||||
|
downloaded = yield from download_video(video_resource.another_failsafe_bvid, chatbot.get_user(), chatbot, history)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
在新工单中引用
屏蔽一个用户