mirror of
https://github.com/tiennm99/litellm.git
synced 2026-08-02 10:21:52 +00:00
Merge pull request #17260 from abi-jey/main
fix: GA path for azure openai realtime models
This commit is contained in:
@@ -12,6 +12,7 @@ from ....litellm_core_utils.litellm_logging import Logging as LiteLLMLogging
|
||||
from ....litellm_core_utils.realtime_streaming import RealTimeStreaming
|
||||
from ....llms.custom_httpx.http_handler import get_shared_realtime_ssl_context
|
||||
from ..azure import AzureChatCompletion
|
||||
from litellm._logging import verbose_proxy_logger
|
||||
|
||||
# BACKEND_WS_URL = "ws://localhost:8080/v1/realtime?model=gpt-4o-realtime-preview-2024-10-01"
|
||||
|
||||
@@ -51,18 +52,18 @@ class AzureOpenAIRealtime(AzureChatCompletion):
|
||||
|
||||
Examples:
|
||||
beta/default: "wss://.../openai/realtime?api-version=2024-10-01-preview&deployment=gpt-4o-realtime-preview"
|
||||
GA/v1: "wss://.../openai/v1/realtime?api-version=2024-10-01-preview&deployment=gpt-4o-realtime-preview"
|
||||
GA/v1: "wss://.../openai/v1/realtime?model=gpt-realtime-deployment"
|
||||
"""
|
||||
api_base = api_base.replace("https://", "wss://")
|
||||
|
||||
# Determine path based on realtime_protocol
|
||||
if realtime_protocol in ("GA", "v1"):
|
||||
path = "/openai/v1/realtime"
|
||||
path = "/openai/v1/realtime"
|
||||
return f"{api_base}{path}?model={model}"
|
||||
else:
|
||||
# Default to beta path for backwards compatibility
|
||||
path = "/openai/realtime"
|
||||
|
||||
return f"{api_base}{path}?api-version={api_version}&deployment={model}"
|
||||
return f"{api_base}{path}?api-version={api_version}&deployment={model}"
|
||||
|
||||
async def async_realtime(
|
||||
self,
|
||||
@@ -107,4 +108,5 @@ class AzureOpenAIRealtime(AzureChatCompletion):
|
||||
except websockets.exceptions.InvalidStatusCode as e: # type: ignore
|
||||
await websocket.close(code=e.status_code, reason=str(e))
|
||||
except Exception:
|
||||
verbose_proxy_logger.exception("Error in AzureOpenAIRealtime.async_realtime")
|
||||
pass
|
||||
|
||||
@@ -117,6 +117,7 @@ async def test_construct_url_beta_protocol_explicit():
|
||||
async def test_construct_url_ga_protocol():
|
||||
"""
|
||||
Test that realtime_protocol='GA' uses /openai/v1/realtime (GA path).
|
||||
GA path uses ?model= instead of ?api-version=&deployment= format.
|
||||
"""
|
||||
from litellm.llms.azure.realtime.handler import AzureOpenAIRealtime
|
||||
|
||||
@@ -132,8 +133,10 @@ async def test_construct_url_ga_protocol():
|
||||
assert "/openai/v1/realtime?" in url
|
||||
# Ensure it doesn't have both paths
|
||||
assert url.count("/realtime") == 1
|
||||
assert "api-version=2024-10-01-preview" in url
|
||||
assert "deployment=gpt-4o-realtime-preview" in url
|
||||
# GA path uses model= query param, not api-version and deployment
|
||||
assert "model=gpt-4o-realtime-preview" in url
|
||||
assert "api-version" not in url
|
||||
assert "deployment" not in url
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -203,8 +206,10 @@ async def test_async_realtime_uses_ga_protocol_end_to_end():
|
||||
called_url = mock_ws_connect.call_args[0][0]
|
||||
assert "/openai/v1/realtime" in called_url
|
||||
assert called_url.startswith("wss://")
|
||||
assert "api-version=2024-10-01-preview" in called_url
|
||||
assert "deployment=gpt-4o-realtime-preview" in called_url
|
||||
# GA path uses model= query param, not api-version and deployment
|
||||
assert "model=gpt-4o-realtime-preview" in called_url
|
||||
assert "api-version" not in called_url
|
||||
assert "deployment" not in called_url
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
||||
Reference in New Issue
Block a user