refactor: extract helper method to reduce code duplication
Co-authored-by: Soulter <37870767+Soulter@users.noreply.github.com>
This commit is contained in:
@@ -51,15 +51,21 @@ class Main(star.Star):
|
||||
|
||||
# Deactivate built-in web search tools if web_search is disabled
|
||||
# This allows MCP to provide custom web_search tools
|
||||
websearch_enable = (
|
||||
provider_settings.get("web_search", False) if provider_settings else False
|
||||
)
|
||||
websearch_enable = (provider_settings or {}).get("web_search", False)
|
||||
if not websearch_enable:
|
||||
func_tool_mgr = self.context.get_llm_tool_manager()
|
||||
for tool_name in self.TOOLS:
|
||||
tool = func_tool_mgr.get_func(tool_name)
|
||||
if tool:
|
||||
tool.active = False
|
||||
self._set_tools_active(False)
|
||||
|
||||
def _set_tools_active(self, active: bool) -> None:
|
||||
"""Set the active status of all built-in web search tools.
|
||||
|
||||
Args:
|
||||
active: True to activate tools, False to deactivate them
|
||||
"""
|
||||
func_tool_mgr = self.context.get_llm_tool_manager()
|
||||
for tool_name in self.TOOLS:
|
||||
tool = func_tool_mgr.get_func(tool_name)
|
||||
if tool:
|
||||
tool.active = active
|
||||
|
||||
async def _tidy_text(self, text: str) -> str:
|
||||
"""清理文本,去除空格、换行符等"""
|
||||
@@ -406,14 +412,9 @@ class Main(star.Star):
|
||||
websearch_enable = prov_settings.get("web_search", False)
|
||||
provider = prov_settings.get("websearch_provider", "default")
|
||||
|
||||
func_tool_mgr = self.context.get_llm_tool_manager()
|
||||
|
||||
# Globally activate/deactivate built-in web search tools based on config
|
||||
# This allows MCP to provide custom web_search tools when built-in is disabled
|
||||
for tool_name in self.TOOLS:
|
||||
tool = func_tool_mgr.get_func(tool_name)
|
||||
if tool:
|
||||
tool.active = websearch_enable
|
||||
self._set_tools_active(websearch_enable)
|
||||
|
||||
tool_set = req.func_tool
|
||||
if isinstance(tool_set, FunctionToolManager):
|
||||
|
||||
Reference in New Issue
Block a user