Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

怎么实现模型遇到超出训练数据本身的问题时能自动调用搜索引擎回答,而不需要人为去选择搜索引擎回答呢? #5198

Open
Alan-zhong opened this issue Jan 20, 2025 · 1 comment

Comments

@Alan-zhong
Copy link

怎么实现模型遇到超出训练数据本身的问题时能自动调用搜索引擎回答,而不需要人为去选择搜索引擎回答呢?

Copy link

dosubot bot commented Jan 20, 2025

要实现模型在遇到超出训练数据的问题时自动调用搜索引擎回答,可以使用Langchain-Chatchat中的“搜索引擎问答”模式。以下是相关实现步骤:

  1. 设置对话模式为“搜索引擎问答”。
  2. 系统会自动调用指定的搜索引擎(如Bing、DuckDuckGo、Metaphor、Searx)进行搜索。
  3. 搜索结果会自动返回给用户,无需人工干预。

相关代码片段如下:

elif dialogue_mode == "搜索引擎问答":
    chat_box.ai_say([
        f"正在执行 `{search_engine}` 搜索...",
        Markdown("...", in_expander=True, title="网络搜索结果", state="complete"),
    ])
    text = ""
    for d in api.search_engine_chat(prompt,
                                    search_engine_name=search_engine,
                                    top_k=se_top_k,
                                    history=history,
                                    model=llm_model,
                                    prompt_name=prompt_template_name,
                                    temperature=temperature,
                                    split_result=se_top_k > 1):
        if error_msg := check_error_msg(d):  # check whether error occured
            st.error(error_msg)
        elif chunk := d.get("answer"):
            text += chunk
            chat_box.update_msg(text, element_index=0)
    chat_box.update_msg(text, element_index=0, streaming=False)
    chat_box.update_msg("\n\n".join(d.get("docs", [])), element_index=1, streaming=False)

通过这种方式,模型可以在无法回答的问题上自动利用搜索引擎获取答案 [1].

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant