mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-07 02:59:05 +00:00
fix(e2e): drop search_api_router os.environ expansion from vendor suite
Keep the PR test-only. Search tools register without an api_key so the proxy falls back to its own PERPLEXITY/TAVILY env, same pattern as a2a.
This commit is contained in:
parent
b4898b4797
commit
2e9d83d3b9
3 changed files with 5 additions and 58 deletions
|
|
@ -37,14 +37,8 @@ class SearchAPIRouter:
|
|||
Returns:
|
||||
Tuple of (api_key, api_base) from tool configuration
|
||||
"""
|
||||
from litellm.secret_managers.main import get_secret_str
|
||||
|
||||
resolved_api_key: Optional[str] = tool_litellm_params.get("api_key")
|
||||
resolved_api_base: Optional[str] = tool_litellm_params.get("api_base")
|
||||
if isinstance(resolved_api_key, str) and resolved_api_key.startswith("os.environ/"):
|
||||
resolved_api_key = get_secret_str(resolved_api_key)
|
||||
if isinstance(resolved_api_base, str) and resolved_api_base.startswith("os.environ/"):
|
||||
resolved_api_base = get_secret_str(resolved_api_base)
|
||||
|
||||
return resolved_api_key, resolved_api_base
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ pytestmark = pytest.mark.e2e
|
|||
|
||||
class SearchToolLiteLLMParams(BaseModel):
|
||||
search_provider: str
|
||||
api_key: str
|
||||
|
||||
|
||||
class SearchToolBody(BaseModel):
|
||||
|
|
@ -56,17 +55,16 @@ class SearchResponse(BaseModel):
|
|||
results: list[SearchResultItem] = []
|
||||
|
||||
|
||||
def _search_credentials() -> tuple[str, str]:
|
||||
def _search_provider() -> str:
|
||||
if os.environ.get("PERPLEXITY_API_KEY") or os.environ.get("PERPLEXITYAI_API_KEY"):
|
||||
env_name = "PERPLEXITY_API_KEY" if os.environ.get("PERPLEXITY_API_KEY") else "PERPLEXITYAI_API_KEY"
|
||||
return "perplexity", f"os.environ/{env_name}"
|
||||
return "perplexity"
|
||||
if os.environ.get("TAVILY_API_KEY"):
|
||||
return "tavily", "os.environ/TAVILY_API_KEY"
|
||||
return "tavily"
|
||||
pytest.fail("set PERPLEXITY_API_KEY or TAVILY_API_KEY for /v1/search e2e coverage")
|
||||
|
||||
|
||||
def _register_search_tool(proxy: ProxyClient, resources: ResourceManager) -> str:
|
||||
provider, api_key = _search_credentials()
|
||||
provider = _search_provider()
|
||||
name = f"e2e-search-{unique_marker()}"
|
||||
created = unwrap(
|
||||
proxy.transport.post(
|
||||
|
|
@ -75,9 +73,7 @@ def _register_search_tool(proxy: ProxyClient, resources: ResourceManager) -> str
|
|||
json=CreateSearchToolRequest(
|
||||
search_tool=SearchToolBody(
|
||||
search_tool_name=name,
|
||||
litellm_params=SearchToolLiteLLMParams(
|
||||
search_provider=provider, api_key=api_key
|
||||
),
|
||||
litellm_params=SearchToolLiteLLMParams(search_provider=provider),
|
||||
search_tool_info={"description": "e2e search tool"},
|
||||
)
|
||||
),
|
||||
|
|
|
|||
|
|
@ -1,43 +0,0 @@
|
|||
from litellm.router_utils.search_api_router import SearchAPIRouter
|
||||
|
||||
|
||||
def test_resolve_search_provider_credentials_expands_os_environ_refs(
|
||||
monkeypatch,
|
||||
) -> None:
|
||||
monkeypatch.setenv("E2E_SEARCH_API_KEY", "secret-from-env")
|
||||
monkeypatch.setenv("E2E_SEARCH_API_BASE", "https://search.example")
|
||||
|
||||
api_key, api_base = SearchAPIRouter._resolve_search_provider_credentials(
|
||||
tool_litellm_params={
|
||||
"api_key": "os.environ/E2E_SEARCH_API_KEY",
|
||||
"api_base": "os.environ/E2E_SEARCH_API_BASE",
|
||||
}
|
||||
)
|
||||
|
||||
assert api_key == "secret-from-env"
|
||||
assert api_base == "https://search.example"
|
||||
|
||||
|
||||
def test_resolve_search_provider_credentials_passes_through_plain_values() -> None:
|
||||
api_key, api_base = SearchAPIRouter._resolve_search_provider_credentials(
|
||||
tool_litellm_params={
|
||||
"api_key": "sk-literal",
|
||||
"api_base": "https://literal.example",
|
||||
}
|
||||
)
|
||||
|
||||
assert api_key == "sk-literal"
|
||||
assert api_base == "https://literal.example"
|
||||
|
||||
|
||||
def test_resolve_search_provider_credentials_missing_env_returns_none(
|
||||
monkeypatch,
|
||||
) -> None:
|
||||
monkeypatch.delenv("MISSING_SEARCH_KEY_XYZ", raising=False)
|
||||
|
||||
api_key, api_base = SearchAPIRouter._resolve_search_provider_credentials(
|
||||
tool_litellm_params={"api_key": "os.environ/MISSING_SEARCH_KEY_XYZ"}
|
||||
)
|
||||
|
||||
assert api_key is None
|
||||
assert api_base is None
|
||||
Loading…
Add table
Reference in a new issue