From 457689c31a8f70d3e59f51a1e089ac5909a1f5d9 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Sat, 29 Jun 2024 15:51:28 -0700 Subject: [PATCH 1/3] fix image gen connection error --- litellm/llms/custom_httpx/azure_dall_e_2.py | 27 +++++++++++++-------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/litellm/llms/custom_httpx/azure_dall_e_2.py b/litellm/llms/custom_httpx/azure_dall_e_2.py index f361ede5bf..75ab542a8b 100644 --- a/litellm/llms/custom_httpx/azure_dall_e_2.py +++ b/litellm/llms/custom_httpx/azure_dall_e_2.py @@ -1,4 +1,8 @@ -import time, json, httpx, asyncio +import asyncio +import json +import time + +import httpx class AsyncCustomHTTPTransport(httpx.AsyncHTTPTransport): @@ -7,15 +11,18 @@ class AsyncCustomHTTPTransport(httpx.AsyncHTTPTransport): """ async def handle_async_request(self, request: httpx.Request) -> httpx.Response: - if "images/generations" in request.url.path and request.url.params[ - "api-version" - ] in [ # dall-e-3 starts from `2023-12-01-preview` so we should be able to avoid conflict - "2023-06-01-preview", - "2023-07-01-preview", - "2023-08-01-preview", - "2023-09-01-preview", - "2023-10-01-preview", - ]: + _api_version = request.url.params.get("api-version", "") + if ( + "images/generations" in request.url.path + and _api_version + in [ # dall-e-3 starts from `2023-12-01-preview` so we should be able to avoid conflict + "2023-06-01-preview", + "2023-07-01-preview", + "2023-08-01-preview", + "2023-09-01-preview", + "2023-10-01-preview", + ] + ): request.url = request.url.copy_with( path="/openai/images/generations:submit" ) From 8a4cffa06ef180b2632560bd9245bfbc83991856 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Sat, 29 Jun 2024 17:25:41 -0700 Subject: [PATCH 2/3] fix _api_version check on CustomHttpTransport --- litellm/llms/custom_httpx/azure_dall_e_2.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/litellm/llms/custom_httpx/azure_dall_e_2.py b/litellm/llms/custom_httpx/azure_dall_e_2.py index 75ab542a8b..a6726eb98c 100644 --- a/litellm/llms/custom_httpx/azure_dall_e_2.py +++ b/litellm/llms/custom_httpx/azure_dall_e_2.py @@ -84,15 +84,18 @@ class CustomHTTPTransport(httpx.HTTPTransport): self, request: httpx.Request, ) -> httpx.Response: - if "images/generations" in request.url.path and request.url.params[ - "api-version" - ] in [ # dall-e-3 starts from `2023-12-01-preview` so we should be able to avoid conflict - "2023-06-01-preview", - "2023-07-01-preview", - "2023-08-01-preview", - "2023-09-01-preview", - "2023-10-01-preview", - ]: + _api_version = request.url.params.get("api-version", "") + if ( + "images/generations" in request.url.path + and _api_version + in [ # dall-e-3 starts from `2023-12-01-preview` so we should be able to avoid conflict + "2023-06-01-preview", + "2023-07-01-preview", + "2023-08-01-preview", + "2023-09-01-preview", + "2023-10-01-preview", + ] + ): request.url = request.url.copy_with( path="/openai/images/generations:submit" ) From 0bda80ddea8c9a1995141c080476ac37fede387a Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Sat, 29 Jun 2024 17:28:08 -0700 Subject: [PATCH 3/3] test- router when using openai prefix --- litellm/tests/test_router.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/litellm/tests/test_router.py b/litellm/tests/test_router.py index 7c59611d73..5f22e88a17 100644 --- a/litellm/tests/test_router.py +++ b/litellm/tests/test_router.py @@ -1081,7 +1081,7 @@ async def test_aimg_gen_on_router(): { "model_name": "dall-e-3", "litellm_params": { - "model": "dall-e-3", + "model": "openai/dall-e-3", }, }, { @@ -1137,7 +1137,7 @@ def test_img_gen_on_router(): try: model_list = [ { - "model_name": "dall-e-3", + "model_name": "openai/dall-e-3", "litellm_params": { "model": "dall-e-3", },