Empty or None API keys resulted in "Bearer " header values which cause httpx.LocalProtocolError. Use truthiness checks instead of `is not None` to also reject empty strings before constructing Authorization headers. Datadog: https://us5.datadoghq.com/error-tracking/issue/ad3c1e38-d557-11f0-a65d-da7ad0900000 🤖 Generated with [Letta Code](https://letta.com) Co-authored-by: Letta <noreply@letta.com>
23 lines
650 B
Python
23 lines
650 B
Python
import aiohttp
|
|
|
|
from letta.log import get_logger
|
|
from letta.utils import smart_urljoin
|
|
|
|
logger = get_logger(__name__)
|
|
|
|
|
|
async def mistral_get_model_list_async(url: str, api_key: str) -> dict:
|
|
url = smart_urljoin(url, "models")
|
|
|
|
headers = {"Content-Type": "application/json"}
|
|
if api_key:
|
|
headers["Authorization"] = f"Bearer {api_key}"
|
|
|
|
logger.debug("Sending request to %s", url)
|
|
|
|
async with aiohttp.ClientSession() as session:
|
|
# TODO add query param "tool" to be true
|
|
async with session.get(url, headers=headers) as response:
|
|
response.raise_for_status()
|
|
return await response.json()
|