From b577a3ad1814ec67dc51b18244012003cddaccbb Mon Sep 17 00:00:00 2001 From: weiweiw <14335254+weiweiw22@user.noreply.gitee.com> Date: Thu, 24 Apr 2025 16:26:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=90=9C=E7=B4=A2api=20=E6=8D=A2=E6=88=90=20zh?= =?UTF-8?q?ipu-search=E5=B9=B6=E6=8F=90=E5=8D=87agent=20=E6=8F=90=E7=A4=BA?= =?UTF-8?q?=E8=AF=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/agent/tools_factory/search_internet.py | 5 +++-- libs/chatchat-server/chatchat/settings.py | 9 +++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/libs/chatchat-server/chatchat/server/agent/tools_factory/search_internet.py b/libs/chatchat-server/chatchat/server/agent/tools_factory/search_internet.py index e7c3838..54cb26a 100644 --- a/libs/chatchat-server/chatchat/server/agent/tools_factory/search_internet.py +++ b/libs/chatchat-server/chatchat/server/agent/tools_factory/search_internet.py @@ -116,7 +116,7 @@ def tavily_search(text, config, top_k): def zhipu_search(text, config, top_k): api_key = config["zhipu_api_key"] - endpoint = " https://open.bigmodel.cn/api/paas/v4/web_search" + endpoint = "https://open.bigmodel.cn/api/paas/v4/web_search" headers = { "Authorization": f"Bearer {api_key}", "Content-Type": "application/json" @@ -185,7 +185,8 @@ def search_engine(query: str, top_k: int = 0, engine_name: str = "", config: dic docs = [x for x in search_result2docs(results, engine_name, top_k) if x.page_content and x.page_content.strip()] print(f"len(docs): {len(docs)}") - print(f"docs: {docs[:150]}") + # print(f"docs:{docs}") + # # print(f"docs: {docs[:150]}") return {"docs": docs, "search_engine": engine_name} diff --git a/libs/chatchat-server/chatchat/settings.py b/libs/chatchat-server/chatchat/settings.py index 3d59e4b..d3b76d0 100644 --- a/libs/chatchat-server/chatchat/settings.py +++ b/libs/chatchat-server/chatchat/settings.py @@ -488,7 +488,7 @@ class ToolSettings(BaseFileSettings): search_internet: dict = { "use": False, - "search_engine_name": "tavily", + "search_engine_name": "zhipu_search", "search_engine_config": { "bing": { "bing_search_url": "https://api.bing.microsoft.com/v7.0/search", @@ -513,9 +513,12 @@ class ToolSettings(BaseFileSettings): "search_depth": "advanced", "include_raw_content": True, "max_results": 1 + }, + "zhipu_search":{ + "zhipu_api_key": "" } }, - "top_k": 5, + "top_k": 1, "verbose": "Origin", "conclude_prompt": "<指令>这是搜索到的互联网信息,请你根据这些信息进行提取并有调理,简洁的回答问题,不得包含有重复的词汇或句子。如果无法从中得到答案,请说 “无法搜索到能回答问题的内容”。 " "\n<已知信息>{{ context }}\n" @@ -748,6 +751,8 @@ class PromptSettings(BaseFileSettings): "Begin!\n\n" "Question: {input}\n\n" "{agent_scratchpad}\n\n" + "Important: After the last Observation, you must always add a Final Answer " + "summarizing the result. Do not skip this step." ), "structured-chat-agent": ( "Respond to the human as helpfully and accurately as possible. You have access to the following tools:\n\n"