From 6ca9e2a7536b003a5311d29a4c95fa24295eeaa4 Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Sun, 2 Feb 2025 14:42:13 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20websearch=20=E5=8F=AF=E9=80=89=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E5=BC=95=E7=94=A8=E9=93=BE=E6=8E=A5=20#287?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- astrbot/core/config/default.py | 12 +++++++++++- packages/web_searcher/engines/google.py | 3 ++- packages/web_searcher/main.py | 13 ++++++++++++- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/astrbot/core/config/default.py b/astrbot/core/config/default.py index fa99f167a..6f6f2450e 100644 --- a/astrbot/core/config/default.py +++ b/astrbot/core/config/default.py @@ -37,6 +37,7 @@ DEFAULT_CONFIG = { "enable": True, "wake_prefix": "", "web_search": False, + "web_search_link": False, "identifier": False, "datetime_system_prompt": True, "default_personality": "default", @@ -539,16 +540,25 @@ CONFIG_METADATA_2 = { "web_search": { "description": "启用网页搜索", "type": "bool", - "hint": "能访问 Google 时效果最佳。如果 Google 访问失败,程序会依次访问 Bing, Sogo 搜索引擎。", + "obvious_hint": True, + "hint": "能访问 Google 时效果最佳(国内需要在 `其他配置` 开启 HTTP 代理)。如果 Google 访问失败,程序会依次访问 Bing, Sogo 搜索引擎。", + }, + "web_search_link": { + "description": "网页搜索引用链接", + "type": "bool", + "obvious_hint": True, + "hint": "开启后,将会传入网页搜索结果的链接给模型,并引导模型输出引用链接。", }, "identifier": { "description": "启动识别群员", "type": "bool", + "obvious_hint": True, "hint": "在 Prompt 前加上群成员的名字以让模型更好地了解群聊状态。启用将略微增加 token 开销。", }, "datetime_system_prompt": { "description": "启用日期时间系统提示", "type": "bool", + "obvious_hint": True, "hint": "启用后,会在系统提示词中加上当前机器的日期时间。", }, "default_personality": { diff --git a/packages/web_searcher/engines/google.py b/packages/web_searcher/engines/google.py index 3e26f581e..cd0e559ff 100644 --- a/packages/web_searcher/engines/google.py +++ b/packages/web_searcher/engines/google.py @@ -8,7 +8,8 @@ from typing import List class Google(SearchEngine): def __init__(self) -> None: super().__init__() - self.proxy = os.environ.get("HTTPS_PROXY") + self.proxy = os.environ.get("https_proxy") + print(f"Google Search using proxy: {self.proxy}") async def search(self, query: str, num_results: int) -> List[SearchResult]: results = [] diff --git a/packages/web_searcher/main.py b/packages/web_searcher/main.py index 2186d67b4..67a08ab2f 100644 --- a/packages/web_searcher/main.py +++ b/packages/web_searcher/main.py @@ -22,6 +22,8 @@ class Main(star.Star): self.sogo_search = Sogo() self.google = Google() + self.websearch_link = self.context.get_config()['provider_settings'].get('web_search_link', False) + async def initialize(self): websearch = self.context.get_config()['provider_settings']['web_search'] if websearch: @@ -109,8 +111,17 @@ class Main(star.Star): except BaseException: site_result = "" site_result = site_result[:700] + "..." if len(site_result) > 700 else site_result - ret += f"{idx}. {i.title} \n{i.snippet}\n{site_result}\n\n" + + header = f"{idx}. {i.title} " + + if self.websearch_link and i.url: + header += i.url + + ret += f"{header}\n{i.snippet}\n{site_result}\n\n" idx += 1 + + if self.websearch_link: + ret += "针对问题,请根据上面的结果分点总结,并且在结尾处附上对应内容的参考链接(如有)。" return ret