You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
2.2 KiB
75 lines
2.2 KiB
#!/usr/bin/env python3
|
|
"""
|
|
测试网页搜索功能
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
from deepsearcher.web_search import WebSearch
|
|
from deepsearcher import configuration
|
|
|
|
def test_web_search():
|
|
"""测试网页搜索功能"""
|
|
print("=== 测试网页搜索功能 ===")
|
|
|
|
# 初始化网页搜索
|
|
web_search = WebSearch()
|
|
|
|
# 测试查询
|
|
test_query = "Milvus是什么"
|
|
print(f"测试查询: {test_query}")
|
|
|
|
# 执行搜索
|
|
results = web_search.search_with_retry(test_query, size=4)
|
|
|
|
if results:
|
|
print(f"找到 {len(results)} 个搜索结果:")
|
|
for i, result in enumerate(results, 1):
|
|
print(f"\n--- 结果 {i} ---")
|
|
print(f"标题: {result.metadata.get('title', 'N/A')}")
|
|
print(f"链接: {result.reference}")
|
|
print(f"分数: {result.score}")
|
|
print(f"内容长度: {len(result.text)} 字符")
|
|
print(f"内容预览: {result.text[:200]}...")
|
|
else:
|
|
print("未找到搜索结果")
|
|
|
|
def test_integration():
|
|
"""测试与DeepSearch的集成"""
|
|
print("\n=== 测试与DeepSearch的集成 ===")
|
|
|
|
# 初始化配置
|
|
configuration.init_config(configuration.config)
|
|
|
|
# 创建DeepSearch实例(启用网页搜索)
|
|
from deepsearcher.agent.deep_search import DeepSearch
|
|
|
|
searcher = DeepSearch(
|
|
llm=configuration.llm,
|
|
embedding_model=configuration.embedding_model,
|
|
vector_db=configuration.vector_db,
|
|
max_iter=2,
|
|
enable_web_search=True
|
|
)
|
|
|
|
# 测试查询
|
|
test_query = "Milvus是什么"
|
|
print(f"测试查询: {test_query}")
|
|
|
|
# 执行搜索
|
|
results, sub_queries = searcher.retrieve(test_query, max_iter=2)
|
|
|
|
print(f"生成的子问题: {sub_queries}")
|
|
print(f"找到 {len(results)} 个搜索结果")
|
|
# 显示结果统计
|
|
web_results = [r for r in results if r.metadata and r.metadata.get("source") == "webpage"]
|
|
vector_results = [r for r in results if not r.metadata or r.metadata.get("source") != "webpage"]
|
|
|
|
print(f"网页搜索结果: {len(web_results)} 个")
|
|
print(f"向量数据库结果: {len(vector_results)} 个")
|
|
|
|
if __name__ == "__main__":
|
|
test_web_search()
|
|
test_integration()
|
|
|