(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:
Ishaan Jaff 2024-12-28 18:15:00 -08:00 committed by GitHub
parent 5c1e8b60d4
commit 4e65722a00
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 110 additions and 1 deletions

View file

@ -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