This commit is contained in:
Timothy Jaeryang Baek
2026-06-18 10:45:35 +02:00
Unverified
parent 86ffe37cd8
commit c152eac632
13 changed files with 43 additions and 5 deletions
@@ -18,6 +18,7 @@
let tavilyKey = $state('');
let braveKey = $state('');
let perplexityKey = $state('');
let perplexityBaseUrl = $state('');
let ccKey = $state('');
let ccBaseUrl = $state('');
let ccModel = $state('');
@@ -44,6 +45,7 @@
tavilyKey = (config['web.tavily_api_key'] as string) || '';
braveKey = (config['web.brave_api_key'] as string) || '';
perplexityKey = (config['web.perplexity_api_key'] as string) || '';
perplexityBaseUrl = (config['web.perplexity_base_url'] as string) || '';
ccKey = (config['web.chat_completions_api_key'] as string) || '';
ccBaseUrl = (config['web.chat_completions_base_url'] as string) || '';
ccModel = (config['web.chat_completions_model'] as string) || '';
@@ -74,6 +76,7 @@
'web.tavily_api_key': tavilyKey,
'web.brave_api_key': braveKey,
'web.perplexity_api_key': perplexityKey,
'web.perplexity_base_url': perplexityBaseUrl,
'web.chat_completions_api_key': ccKey,
'web.chat_completions_base_url': ccBaseUrl,
'web.chat_completions_model': ccModel,
@@ -185,6 +188,12 @@
class="w-full mt-1 h-7 px-2 rounded-lg text-xs bg-gray-100 dark:bg-white/6 text-gray-700 dark:text-gray-300 border border-gray-200 dark:border-white/8 outline-none focus:border-blue-400 dark:focus:border-blue-500 transition-colors" />
<p class="text-[11px] text-gray-400 dark:text-gray-600 mt-0.5">{$t('admin.webPerplexityHint')}</p>
</div>
<div>
<label class="text-xs text-gray-600 dark:text-gray-400" for="pplx-base-url">{$t('admin.webPerplexityBaseUrl')}</label>
<input id="pplx-base-url" type="text" bind:value={perplexityBaseUrl} placeholder="https://api.perplexity.ai"
class="w-full mt-1 h-7 px-2 rounded-lg text-xs bg-gray-100 dark:bg-white/6 text-gray-700 dark:text-gray-300 border border-gray-200 dark:border-white/8 outline-none focus:border-blue-400 dark:focus:border-blue-500 transition-colors" />
<p class="text-[11px] text-gray-400 dark:text-gray-600 mt-0.5">{$t('admin.webPerplexityBaseUrlHint')}</p>
</div>
{:else if searchProvider === 'chat_completions'}
<div>
<label class="text-xs text-gray-600 dark:text-gray-400" for="cc-base-url">{$t('admin.webCcBaseUrl')}</label>
@@ -251,6 +251,8 @@
"admin.webDuckDuckGoNote": "DuckDuckGo benötigt keinen API-Schlüssel (Fallback).",
"admin.webPerplexityKey": "Perplexity API-Schlüssel",
"admin.webPerplexityHint": "API-Schlüssel unter perplexity.ai erhalten",
"admin.webPerplexityBaseUrl": "Basis-URL",
"admin.webPerplexityBaseUrlHint": "Leer lassen für api.perplexity.ai. Ändern für LiteLLM oder andere kompatible Proxys.",
"admin.webChatCompletions": "Chat Completions",
"admin.webCcBaseUrl": "Basis-URL",
"admin.webCcKey": "API-Schlüssel",
@@ -283,6 +283,8 @@
"admin.webDuckDuckGoNote": "DuckDuckGo requires no API key (fallback).",
"admin.webPerplexityKey": "Perplexity API Key",
"admin.webPerplexityHint": "Get your API key at perplexity.ai",
"admin.webPerplexityBaseUrl": "Base URL",
"admin.webPerplexityBaseUrlHint": "Leave blank for api.perplexity.ai. Change for LiteLLM or other compatible proxies.",
"admin.webChatCompletions": "Chat Completions",
"admin.webCcBaseUrl": "Base URL",
"admin.webCcKey": "API Key",
@@ -251,6 +251,8 @@
"admin.webDuckDuckGoNote": "DuckDuckGo no requiere clave de API (respaldo).",
"admin.webPerplexityKey": "Clave de API de Perplexity",
"admin.webPerplexityHint": "Obtén tu clave de API en perplexity.ai",
"admin.webPerplexityBaseUrl": "URL base",
"admin.webPerplexityBaseUrlHint": "Dejar en blanco para api.perplexity.ai. Cambiar para LiteLLM u otros proxies compatibles.",
"admin.webChatCompletions": "Chat Completions",
"admin.webCcBaseUrl": "URL base",
"admin.webCcKey": "Clave de API",
@@ -251,6 +251,8 @@
"admin.webDuckDuckGoNote": "DuckDuckGo ne nécessite aucune clé API (solution de repli).",
"admin.webPerplexityKey": "Clé API Perplexity",
"admin.webPerplexityHint": "Obtenez votre clé API sur perplexity.ai",
"admin.webPerplexityBaseUrl": "URL de base",
"admin.webPerplexityBaseUrlHint": "Laisser vide pour api.perplexity.ai. Modifier pour LiteLLM ou d'autres proxies compatibles.",
"admin.webChatCompletions": "Chat Completions",
"admin.webCcBaseUrl": "URL de base",
"admin.webCcKey": "Clé API",
@@ -251,6 +251,8 @@
"admin.webDuckDuckGoNote": "DuckDuckGoはAPIキー不要です(フォールバック)。",
"admin.webPerplexityKey": "Perplexity APIキー",
"admin.webPerplexityHint": "perplexity.ai でAPIキーを取得",
"admin.webPerplexityBaseUrl": "ベースURL",
"admin.webPerplexityBaseUrlHint": "api.perplexity.ai を使用する場合は空欄。LiteLLM や他の互換プロキシの場合は変更してください。",
"admin.webChatCompletions": "Chat Completions",
"admin.webCcBaseUrl": "ベースURL",
"admin.webCcKey": "APIキー",
@@ -251,6 +251,8 @@
"admin.webDuckDuckGoNote": "DuckDuckGo는 API 키가 필요 없습니다(대체).",
"admin.webPerplexityKey": "Perplexity API 키",
"admin.webPerplexityHint": "perplexity.ai에서 API 키를 받으세요",
"admin.webPerplexityBaseUrl": "기본 URL",
"admin.webPerplexityBaseUrlHint": "api.perplexity.ai를 사용하려면 비워두세요. LiteLLM 또는 기타 호환 프록시의 경우 변경하세요.",
"admin.webChatCompletions": "Chat Completions",
"admin.webCcBaseUrl": "기본 URL",
"admin.webCcKey": "API 키",
@@ -251,6 +251,8 @@
"admin.webDuckDuckGoNote": "DuckDuckGo não exige chave de API (fallback).",
"admin.webPerplexityKey": "Chave de API do Perplexity",
"admin.webPerplexityHint": "Obtenha sua chave de API em perplexity.ai",
"admin.webPerplexityBaseUrl": "URL base",
"admin.webPerplexityBaseUrlHint": "Deixe em branco para api.perplexity.ai. Altere para LiteLLM ou outros proxies compatíveis.",
"admin.webChatCompletions": "Chat Completions",
"admin.webCcBaseUrl": "URL base",
"admin.webCcKey": "Chave de API",
@@ -251,6 +251,8 @@
"admin.webDuckDuckGoNote": "DuckDuckGo не требует API-ключа (резервный вариант).",
"admin.webPerplexityKey": "API-ключ Perplexity",
"admin.webPerplexityHint": "Получите API-ключ на perplexity.ai",
"admin.webPerplexityBaseUrl": "Базовый URL",
"admin.webPerplexityBaseUrlHint": "Оставьте пустым для api.perplexity.ai. Измените для LiteLLM или других совместимых прокси.",
"admin.webChatCompletions": "Chat Completions",
"admin.webCcBaseUrl": "Базовый URL",
"admin.webCcKey": "API-ключ",
@@ -251,6 +251,8 @@
"admin.webDuckDuckGoNote": "DuckDuckGo 不需要 API 密钥(备用)。",
"admin.webPerplexityKey": "Perplexity API 密钥",
"admin.webPerplexityHint": "在 perplexity.ai 获取你的 API 密钥",
"admin.webPerplexityBaseUrl": "基础 URL",
"admin.webPerplexityBaseUrlHint": "留空使用 api.perplexity.ai。如使用 LiteLLM 或其他兼容代理请修改。",
"admin.webChatCompletions": "Chat Completions",
"admin.webCcBaseUrl": "基础 URL",
"admin.webCcKey": "API 密钥",
@@ -251,6 +251,8 @@
"admin.webDuckDuckGoNote": "DuckDuckGo 不需要 API 金鑰(備用)。",
"admin.webPerplexityKey": "Perplexity API 金鑰",
"admin.webPerplexityHint": "在 perplexity.ai 取得你的 API 金鑰",
"admin.webPerplexityBaseUrl": "基礎 URL",
"admin.webPerplexityBaseUrlHint": "留空使用 api.perplexity.ai。如使用 LiteLLM 或其他相容代理請修改。",
"admin.webChatCompletions": "Chat Completions",
"admin.webCcBaseUrl": "基礎 URL",
"admin.webCcKey": "API 金鑰",
+7 -2
View File
@@ -9,11 +9,16 @@ from __future__ import annotations
import httpx
async def search(query: str, api_key: str, count: int = 5) -> str:
async def search(
query: str,
api_key: str,
count: int = 5,
base_url: str = "https://api.perplexity.ai",
) -> str:
"""Search using Perplexity's dedicated search API."""
async with httpx.AsyncClient(timeout=10) as client:
resp = await client.post(
"https://api.perplexity.ai/search",
f"{base_url.rstrip('/')}/search",
json={"query": query},
headers={
"Authorization": f"Bearer {api_key}",
+7 -3
View File
@@ -2,7 +2,7 @@
Priority in auto mode:
1. Exa (EXA_API_KEY or web.exa_api_key)
2. Perplexity (PERPLEXITY_API_KEY or web.perplexity_api_key)
2. Perplexity (PERPLEXITY_API_KEY or web.perplexity_api_key, optional PERPLEXITY_BASE_URL or web.perplexity_base_url)
3. Tavily (TAVILY_API_KEY or web.tavily_api_key)
4. Brave (BRAVE_API_KEY or web.brave_api_key)
5. DuckDuckGo (zero-config fallback)
@@ -52,6 +52,9 @@ async def web_search_handler(query: str) -> str:
exa_key = await _get_key("EXA_API_KEY", "web.exa_api_key")
perplexity_key = await _get_key("PERPLEXITY_API_KEY", "web.perplexity_api_key")
perplexity_url = (
await _get_config("web.perplexity_base_url")
) or os.environ.get("PERPLEXITY_BASE_URL", "")
tavily_key = await _get_key("TAVILY_API_KEY", "web.tavily_api_key")
brave_key = await _get_key("BRAVE_API_KEY", "web.brave_api_key")
cc_key = await _get_key("CHAT_COMPLETIONS_SEARCH_API_KEY", "web.chat_completions_api_key")
@@ -72,7 +75,7 @@ async def web_search_handler(query: str) -> str:
elif provider == "perplexity":
if not perplexity_key:
return "Error: Perplexity API key not configured."
return await perplexity.search(query, perplexity_key)
return await perplexity.search(query, perplexity_key, base_url=perplexity_url) if perplexity_url else await perplexity.search(query, perplexity_key)
elif provider == "tavily":
if not tavily_key:
return "Error: Tavily API key not configured."
@@ -98,7 +101,8 @@ async def web_search_handler(query: str) -> str:
if exa_key:
providers.append(("exa", lambda: exa.search(query, exa_key)))
if perplexity_key:
providers.append(("perplexity", lambda: perplexity.search(query, perplexity_key)))
_pplx_kw = {"base_url": perplexity_url} if perplexity_url else {}
providers.append(("perplexity", lambda: perplexity.search(query, perplexity_key, **_pplx_kw)))
if tavily_key:
providers.append(("tavily", lambda: tavily.search(query, tavily_key)))
if brave_key: