Skip to content

Commit d5d4e2f

Browse files
[search online] 修改检视意见
1 parent 405909a commit d5d4e2f

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

app-builder/plugins/fit_py_internet_search/conf/application.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
internet-search:
22
max_results_per_provider: 5
3+
summary-length: 150
34
api-key:
45
exa: "https://dashboard.exa.ai/home -- 登录获取api key"
56
tavily: "https://app.tavily.com/home -- 登录获取api key"

app-builder/plugins/fit_py_internet_search/src/internet_search.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# Licensed under the MIT License. See License.txt in the project root for license information.
55
# ======================================================================================================================
66
import json
7+
import re
78
from concurrent.futures import ThreadPoolExecutor, as_completed
89
from dataclasses import dataclass
910
from typing import Dict, List, Optional, Sequence
@@ -70,6 +71,11 @@ def _get_max_results_per_provider() -> int:
7071
pass
7172

7273

74+
@value('internet-search.summary-length')
75+
def _get_max_summary_length() -> int:
76+
pass
77+
78+
7379
def _truncate(text: str, max_chars: int) -> str:
7480
if len(text) <= max_chars:
7581
return text
@@ -90,8 +96,6 @@ def _extract_summary(text: str, max_sentences: int = 4) -> str:
9096
if not text:
9197
return ""
9298

93-
# 定义句子分隔符(支持中英文)
94-
import re
9599
# 使用正则表达式匹配句子结束符号
96100
sentences = re.split(r'([。!?\.!?]+["\'»\)]?\s*)', text)
97101

@@ -115,11 +119,12 @@ def _extract_summary(text: str, max_sentences: int = 4) -> str:
115119
summary = " ".join(combined_sentences[:max_sentences])
116120

117121
# 确保摘要不会过长(最多150字符)
118-
if len(summary) > 150:
119-
summary = summary[:147].rstrip() + "..."
122+
if len(summary) > _get_max_summary_length():
123+
summary = summary[:(_get_max_summary_length() - 3)].rstrip() + "..."
120124

121125
return summary
122126

127+
123128
def _search_exa(query: str, api_key: str, max_results: int, max_snippet_chars: int) -> List[SearchItem]:
124129
"""在 Exa 中搜索"""
125130
items: List[SearchItem] = []
@@ -264,11 +269,11 @@ def _internet_search(
264269
except Exception as e:
265270
sys_plugin_logger.error(f'Unexpected error in {provider_name} search: {str(e)}')
266271
errors.append(provider_name)
267-
272+
268273
# 如果所有搜索都失败了,才抛出异常
269274
if not items and errors:
270275
raise FitException(
271-
InternalErrorCode.CLIENT_ERROR,
276+
InternalErrorCode.CLIENT_ERROR,
272277
f'All search tools failed: {", ".join(errors)}'
273278
)
274279

0 commit comments

Comments
 (0)