互联网查询

This commit is contained in:
weiweiw 2025-03-03 17:53:32 +08:00
parent 7a64bd5cb9
commit 00f56aa23c
1 changed files with 8 additions and 3 deletions

View File

@ -11,9 +11,10 @@ from strsimpy.normalized_levenshtein import NormalizedLevenshtein
from chatchat.settings import Settings
from chatchat.server.pydantic_v1 import Field
from chatchat.server.utils import get_tool_config
from chatchat.utils import build_logger
from .tools_registry import BaseToolOutput, regist_tool, format_context
logger = build_logger()
def searx_search(text ,config, top_k: int):
print(f"searx_search: text: {text},config:{config},top_k:{top_k}")
@ -124,5 +125,9 @@ def search_engine(query: str, top_k:int=0, engine_name: str="", config: dict={})
@regist_tool(title="互联网搜索")
def search_internet(query: str = Field(description="query for Internet search")):
"""用这个工具实现获取世界、历史、实时新闻、或除电力系统之外的信息查询"""
print(f"search_internet: query: {query}")
return BaseToolOutput(search_engine(query=query), format=format_context)
try:
print(f"search_internet: query: {query}")
return BaseToolOutput(search_engine(query=query), format=format_context)
except Exception as e:
logger.error(f"未知错误: {str(e)}")
return BaseToolOutput(f"搜索过程中发生未知错误,{str(e)}", format=format_context)