From afba1eaa3856d096c571af07f7660bcefbbaae09 Mon Sep 17 00:00:00 2001
From: Aaron Jimenez <aaronjimv@gmail.com>
Date: Wed, 15 Nov 2023 08:21:08 -0800
Subject: [PATCH] Add support for custom httpx client configuration in
 AzureOpenAI (#8920)

---
 llama_index/llms/azure_openai.py | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/llama_index/llms/azure_openai.py b/llama_index/llms/azure_openai.py
index 444f0b2c71..5978f0e748 100644
--- a/llama_index/llms/azure_openai.py
+++ b/llama_index/llms/azure_openai.py
@@ -1,5 +1,6 @@
 from typing import Any, Dict, Optional, Tuple
 
+import httpx
 from openai import AsyncAzureOpenAI
 from openai import AzureOpenAI as SyncAzureOpenAI
 
@@ -72,6 +73,8 @@ class AzureOpenAI(OpenAI):
         deployment_name: Optional[str] = None,
         deployment_id: Optional[str] = None,
         deployment: Optional[str] = None,
+        # custom httpx client
+        http_client: Optional[httpx.Client] = None,
         **kwargs: Any,
     ) -> None:
         engine = resolve_from_aliases(
@@ -88,6 +91,10 @@ class AzureOpenAI(OpenAI):
             "azure_endpoint", azure_endpoint, "AZURE_OPENAI_ENDPOINT", ""
         )
 
+        # Use the custom httpx client if provided.
+        # Otherwise the value will be None.
+        self._http_client = http_client
+
         super().__init__(
             engine=engine,
             model=model,
@@ -140,6 +147,7 @@ class AzureOpenAI(OpenAI):
             "azure_endpoint": self.azure_endpoint,
             "azure_deployment": self.azure_deployment,
             "api_version": self.api_version,
+            "http_client": self._http_client,
         }
 
     def _get_model_kwargs(self, **kwargs: Any) -> Dict[str, Any]:
-- 
GitLab