Refact: Consolidate Azure OpenAI and OpenAI implementations#2403
Refact: Consolidate Azure OpenAI and OpenAI implementations#2403danielaskdd merged 5 commits intoHKUDS:mainfrom
Conversation
• Unified OpenAI/Azure client creation • Azure module now re-exports functions • Backward compatibility maintained • Reduced code duplication
|
@codex review |
|
Codex Review: Didn't find any major issues. Another round soon, please! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
• Remove redundant @Retry decorator • Call openai_embed.func directly • Add detailed decorator documentation • Prevent double parameter injection • Fix EmbeddingFunc wrapping issues
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
- Handle None client_configs case - Merge configs with explicit params - Override client_configs with params - Use dict unpacking for client init - Maintain parameter precedence
• Add missing parameters to wrappers • Update docstrings for clarity • Ensure API consistency • Fix parameter forwarding • Maintain backward compatibility
|
@codex review |
|
Codex Review: Didn't find any major issues. Bravo. ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Refactor: Consolidate Azure OpenAI and OpenAI implementations
Summary
This PR consolidates the Azure OpenAI and OpenAI LLM implementations by merging their core logic into a unified codebase, significantly reducing code duplication while maintaining full backward compatibility.
Problem
The
azure_openai.pyandopenai.pymodules contained nearly identical implementations (~250 lines of duplicated code), differing only in client initialization parameters. This led to:Solution
1. Extended
openai.pywith unified client creationcreate_openai_async_client()to support both OpenAI and Azure OpenAI clientsuse_azure,azure_deployment, andapi_versionparameters2. Unified core functions
openai_complete_if_cache()to handle both OpenAI and Azure configurationsopenai_embed()with the same Azure support3. Added Azure wrapper functions in
openai.pyazure_openai_complete_if_cache()- Handles Azure-specific environment variablesazure_openai_complete()- Compatibility wrapperazure_openai_embed()- Azure embedding wrapper4. Simplified
azure_openai.pyto a thin compatibility layeropenai.pyChanges
Files Modified:
lightrag/llm/openai.py- Added Azure support and wrapper functions (+170 lines)lightrag/llm/azure_openai.py- Simplified to compatibility layer (-227 lines)Code Metrics:
Backward Compatibility
✅ 100% backward compatible - All existing import statements continue to work:
Testing
lightrag.llm.azure_openaiimports works unchangedBenefits
openai.py) and compatibility layer (azure_openai.py)Migration Guide
No migration needed! All existing code continues to work without any changes. The refactoring is completely transparent to users.