mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-25 10:44:24 +00:00
(Bug Fix) Add health check support for realtime models (#7453)
* add mode: realtime * add _realtime_health_check * test_realtime_health_check * azure _realtime_health_check * _realtime_health_check * Realtime Models * fix code quality
This commit is contained in:
parent
5c1e8b60d4
commit
4e65722a00
6 changed files with 110 additions and 1 deletions
|
@ -114,3 +114,45 @@ async def _arealtime(
|
|||
)
|
||||
else:
|
||||
raise ValueError(f"Unsupported model: {model}")
|
||||
|
||||
|
||||
async def _realtime_health_check(
|
||||
model: str,
|
||||
api_base: str,
|
||||
custom_llm_provider: str,
|
||||
api_key: Optional[str],
|
||||
api_version: Optional[str] = None,
|
||||
):
|
||||
"""
|
||||
Health check for realtime API - tries connection to the realtime API websocket
|
||||
|
||||
Args:
|
||||
model: str - model name
|
||||
api_base: str - api base
|
||||
api_version: Optional[str] - api version
|
||||
api_key: str - api key
|
||||
custom_llm_provider: str - custom llm provider
|
||||
|
||||
Returns:
|
||||
bool - True if connection is successful, False otherwise
|
||||
Raises:
|
||||
Exception - if the connection is not successful
|
||||
"""
|
||||
import websockets
|
||||
|
||||
url: Optional[str] = None
|
||||
if custom_llm_provider == "azure":
|
||||
url = azure_realtime._construct_url(
|
||||
api_base=api_base,
|
||||
model=model,
|
||||
api_version=api_version or "2024-10-01-preview",
|
||||
)
|
||||
elif custom_llm_provider == "openai":
|
||||
url = openai_realtime._construct_url(api_base=api_base, model=model)
|
||||
async with websockets.connect( # type: ignore
|
||||
url,
|
||||
extra_headers={
|
||||
"api-key": api_key, # type: ignore
|
||||
},
|
||||
):
|
||||
return True
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue