From ffd8da512eeb1d1fc27610fc845c3b82dcee21dd Mon Sep 17 00:00:00 2001 From: yangdx Date: Fri, 21 Nov 2025 23:51:18 +0800 Subject: [PATCH] Improve Azure OpenAI compatibility and error handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • Reduce log noise for Azure content filters • Add default API version fallback • Change warning to debug log level • Handle empty choices in streaming • Better Azure OpenAI integration --- lightrag/llm/openai.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lightrag/llm/openai.py b/lightrag/llm/openai.py index ae342657..54147311 100644 --- a/lightrag/llm/openai.py +++ b/lightrag/llm/openai.py @@ -352,7 +352,10 @@ async def openai_complete_if_cache( # Check if choices exists and is not empty if not hasattr(chunk, "choices") or not chunk.choices: - logger.warning(f"Received chunk without choices: {chunk}") + # Azure OpenAI sends content filter results in first chunk without choices + logger.debug( + f"Received chunk without choices (likely Azure content filter): {chunk}" + ) continue # Check if delta exists @@ -817,6 +820,7 @@ async def azure_openai_complete_if_cache( api_version or os.getenv("AZURE_OPENAI_API_VERSION") or os.getenv("OPENAI_API_VERSION") + or "2024-08-01-preview" ) # Call the unified implementation with Azure-specific parameters @@ -930,6 +934,7 @@ async def azure_openai_embed( api_version or os.getenv("AZURE_EMBEDDING_API_VERSION") or os.getenv("OPENAI_API_VERSION") + or "2024-08-01-preview" ) # CRITICAL: Call openai_embed.func (unwrapped) to avoid double decoration