Skip to content

Commit ba037af

Browse files
authored
fix(platform): Cleanup dependencies. (#667)
- Drop unused dependencies. Requiring and pinning `bcrypt>5.0.0` causes problems with projects using `passlib` (i.e FastAPI templates). - Replace `requests` with `httpx`. As it is a base dependency providing the same functionality we need.
1 parent 7a3fc3f commit ba037af

File tree

3 files changed

+12
-18
lines changed

3 files changed

+12
-18
lines changed

pyproject.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,7 @@ all = [
2222
]
2323

2424
platform = [
25-
"typing-extensions",
26-
"bcrypt>=5.0.0",
27-
"cryptography>=46.0.3",
2825
"pynacl>=1.6.0",
29-
"requests>=2.32.5",
3026
]
3127

3228
perplexity = []

src/any_llm/providers/platform/utils.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,13 @@
77
import uuid
88
from typing import TYPE_CHECKING, Any
99

10+
import httpx
1011
import nacl.bindings
1112
import nacl.public
12-
import requests
1313

1414
from any_llm.logging import logger
1515

1616
if TYPE_CHECKING:
17-
import httpx
18-
1917
from any_llm.any_llm import AnyLLM
2018
from any_llm.types.completion import ChatCompletion
2119

@@ -60,7 +58,7 @@ def _create_challenge(public_key: str, any_api_url: str) -> Any:
6058
"""Create an authentication challenge."""
6159
logger.info("Creating authentication challenge...")
6260

63-
response = requests.post(
61+
response = httpx.post(
6462
f"{any_api_url}/auth/",
6563
json={
6664
"encryption_key": public_key,
@@ -131,7 +129,7 @@ def _fetch_provider_key(
131129
"""Fetch the provider key using the solved challenge."""
132130
logger.info(f"Fetching provider key for {provider}...")
133131

134-
response = requests.get(
132+
response = httpx.get(
135133
f"{any_api_url}/provider-keys/{provider}",
136134
headers={"encryption-key": public_key, "AnyLLM-Challenge-Response": str(solved_challenge)},
137135
)

tests/unit/providers/test_platform_provider.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,8 @@ async def mock_stream(): # type: ignore[no-untyped-def]
319319
assert call_args.kwargs["completion"].usage.total_tokens == 15
320320

321321

322-
@patch("any_llm.providers.platform.utils.requests.post")
323-
@patch("any_llm.providers.platform.utils.requests.get")
322+
@patch("any_llm.providers.platform.utils.httpx.post")
323+
@patch("any_llm.providers.platform.utils.httpx.get")
324324
@patch("any_llm.providers.platform.utils._solve_challenge")
325325
def test_get_provider_key_success(
326326
mock_solve_challenge: Mock,
@@ -363,7 +363,7 @@ def test_get_provider_key_success(
363363
mock_decrypt.assert_called_once()
364364

365365

366-
@patch("any_llm.providers.platform.utils.requests.post")
366+
@patch("any_llm.providers.platform.utils.httpx.post")
367367
def test_get_provider_key_invalid_api_key_format(mock_post: Mock) -> None:
368368
"""Test error handling when ANY_LLM_KEY has invalid format."""
369369
invalid_key = "INVALID_KEY_FORMAT"
@@ -374,7 +374,7 @@ def test_get_provider_key_invalid_api_key_format(mock_post: Mock) -> None:
374374
mock_post.assert_not_called()
375375

376376

377-
@patch("any_llm.providers.platform.utils.requests.post")
377+
@patch("any_llm.providers.platform.utils.httpx.post")
378378
def test_get_provider_key_challenge_creation_failure(mock_post: Mock) -> None:
379379
"""Test error handling when challenge creation fails."""
380380
any_llm_key = "ANY.v1.kid123.fingerprint456-YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXoxMjM0NTY="
@@ -390,8 +390,8 @@ def test_get_provider_key_challenge_creation_failure(mock_post: Mock) -> None:
390390
mock_post.assert_called_once()
391391

392392

393-
@patch("any_llm.providers.platform.utils.requests.post")
394-
@patch("any_llm.providers.platform.utils.requests.get")
393+
@patch("any_llm.providers.platform.utils.httpx.post")
394+
@patch("any_llm.providers.platform.utils.httpx.get")
395395
@patch("any_llm.providers.platform.utils._solve_challenge")
396396
def test_get_provider_key_fetch_failure(
397397
mock_solve_challenge: Mock,
@@ -425,8 +425,8 @@ def test_get_provider_key_fetch_failure(
425425

426426

427427
@pytest.mark.asyncio
428-
@patch("any_llm.providers.platform.utils.requests.post")
429-
@patch("any_llm.providers.platform.utils.requests.get")
428+
@patch("any_llm.providers.platform.utils.httpx.post")
429+
@patch("any_llm.providers.platform.utils.httpx.get")
430430
@patch("any_llm.providers.platform.utils._solve_challenge")
431431
async def test_post_completion_usage_event_success(
432432
mock_solve_challenge: Mock,
@@ -515,7 +515,7 @@ async def test_post_completion_usage_event_success(
515515

516516

517517
@pytest.mark.asyncio
518-
@patch("any_llm.providers.platform.utils.requests.post")
518+
@patch("any_llm.providers.platform.utils.httpx.post")
519519
async def test_post_completion_usage_event_invalid_key_format(mock_post: Mock) -> None:
520520
"""Test error handling when ANY_LLM_KEY has invalid format."""
521521
invalid_key = "INVALID_KEY_FORMAT"

0 commit comments

Comments
 (0)