mirror of
https://github.com/agent0ai/agent-zero.git
synced 2026-12-04 17:38:45 +00:00
Add Brave Search, Perplexity Fast, and DeepSeek Search to Search Engine settings. Keep SearXNG as the default and route every provider through the shared CLI and existing JSON contract. Preserve the old SearXNG command as an alias. Store provider keys through the framework's dotenv helper and cover provider routing, response normalization, and status checks with regression tests.
39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
import re
|
|
|
|
from helpers import dotenv
|
|
|
|
KEY_NAMES = {
|
|
'brave': 'BRAVE_SEARCH_API_KEY',
|
|
'perplexity': 'PERPLEXITY_SEARCH_API_KEY',
|
|
'deepseek': 'DEEPSEEK_SEARCH_API_KEY',
|
|
}
|
|
API_KEY_PATTERN = re.compile(r'[A-Za-z0-9._~+/=-]+')
|
|
|
|
|
|
def provider_label(provider):
|
|
return 'DeepSeek Search' if provider == 'deepseek' else f'{provider.capitalize()} Search'
|
|
|
|
|
|
def get_provider(config):
|
|
provider = config.get('provider', 'searxng')
|
|
if provider not in ('searxng', *KEY_NAMES):
|
|
raise ValueError('Unsupported web search provider.')
|
|
return provider
|
|
|
|
|
|
def save_plugin_config(settings):
|
|
provider = get_provider(settings)
|
|
keys = {}
|
|
for name, env_name in KEY_NAMES.items():
|
|
value = settings.get(f'{name}_api_key', '')
|
|
if not isinstance(value, str):
|
|
raise ValueError(f'Invalid {provider_label(name)} API key.')
|
|
value = value.strip()
|
|
if value:
|
|
if not API_KEY_PATTERN.fullmatch(value):
|
|
raise ValueError(f'Invalid {provider_label(name)} API key.')
|
|
keys[env_name] = value
|
|
for env_name, value in keys.items():
|
|
dotenv.save_dotenv_value(env_name, value)
|
|
return {'provider': provider}
|