-
Notifications
You must be signed in to change notification settings - Fork 533
Add Azure AI Foundry (Azure OpenAI) Support #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
caiorg
wants to merge
5
commits into
coleam00:main
Choose a base branch
from
caiorg:azure-ai-studio-integration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This commit introduces support for using Azure AI Studio as an alternative to OpenAI for generating embeddings and chat completions.
Key changes:
- I modified `src/utils.py` to include logic for using Azure OpenAI services if Azure-specific environment variables are set. The system gracefully falls back to the standard OpenAI API if Azure credentials are not provided or if Azure calls fail.
- I added new environment variables:
- `AZURE_OPENAI_API_KEY`
- `AZURE_OPENAI_ENDPOINT`
- `AZURE_OPENAI_CHAT_DEPLOYMENT`
- `AZURE_OPENAI_EMBEDDING_DEPLOYMENT`
- I updated `README.md` to document the new Azure AI Studio integration, including setup instructions for the new environment variables.
- I added unit tests in `tests/test_utils.py` to cover the new Azure integration logic and fallback mechanisms. Note: I was unable to run the tests due to Python environment version limitations, but the tests are structured to validate the implementation.
This commit updates the documentation to reflect the correct product name "Azure AI Foundry". - I replaced "Azure AI Studio" with "Azure AI Foundry" in README.md. - No code comment changes were necessary in src/utils.py as they did not specifically reference "Azure AI Studio".
This commit refactors the Azure OpenAI integration in `src/utils.py` to more closely align with the official openai-python SDK's recommendations for Azure endpoints.
Key changes:
- Modified `src/utils.py`:
- The `AzureOpenAI` client is now instantiated with `api_key`, `azure_endpoint`, and `api_version`.
- Introduced a new environment variable `AZURE_OPENAI_API_VERSION` which is now required for Azure client initialization.
- Ensured that `AZURE_OPENAI_CHAT_DEPLOYMENT` and `AZURE_OPENAI_EMBEDDING_DEPLOYMENT` are correctly used as the `model` parameter in API calls.
- Maintained fallback logic to standard OpenAI if Azure configuration is incomplete or if Azure API calls fail.
- Updated `README.md`:
- Documented the new `AZURE_OPENAI_API_VERSION` environment variable.
- Clarified the role of deployment name variables.
- Updated example configurations.
- Updated `tests/test_utils.py`:
- Aligned tests with the new Azure client instantiation and the `AZURE_OPENAI_API_VERSION` environment variable.
- Ensured test mocks and assertions reflect the refactored logic. (I'm currently unable to run the tests due to Python environment limitations).
Author
|
Changed to draft due to some rebasing inconsistencies. Working on it. |
Consolidates Azure OpenAI environment variables into the main .env example and adds a dedicated notes section for clarity.
a4ce113 to
f0937bb
Compare
Author
|
Reviewed and fixed! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This pull request introduces support for using Azure AI Foundry (Azure OpenAI Service) as an alternative backend for LLM and embedding operations in the Crawl4AI RAG MCP Server. Now it's possible to configure the server to use your Azure OpenAI deployments instead of the default OpenAI API.
Motivation
The primary motivations for this change are to offer greater flexibility and control by enabling the use of Azure OpenAI Service. This allows to:
An additional consideration may be the evolving landscape of data privacy and retention in AI services. For instance, recent discussions, such as those highlighted by Theo - t3.gg (OpenAI's privacy disaster (it isn’t their fault)) concerning legal proceedings like The New York Times lawsuit, underscore the importance of understanding data handling policies. OpenAI has also provided its perspective on such matters (see OpenAI's response on their blog). By offering Azure OpenAI as an alternative, comes an additional option to select a service provider whose data processing and retention policies, within the Azure ecosystem, that aligns with specific requirements and comfort levels, particularly when dealing with sensitive information.
Key Changes
src/utils.py:AzureOpenAIclient if Azure-specific environment variables are provided (AZURE_OPENAI_API_KEY,AZURE_OPENAI_ENDPOINT,AZURE_OPENAI_API_VERSION).create_embeddings_batch,create_embedding,generate_contextual_embedding,generate_code_example_summary,extract_source_summary) to use the Azure client for API calls if it's initialized and relevant deployment names (AZURE_OPENAI_CHAT_DEPLOYMENT,AZURE_OPENAI_EMBEDDING_DEPLOYMENT) are set.README.md:AZURE_OPENAI_API_KEYAZURE_OPENAI_ENDPOINTAZURE_OPENAI_API_VERSIONAZURE_OPENAI_CHAT_DEPLOYMENTAZURE_OPENAI_EMBEDDING_DEPLOYMENTtests/test_utils.py(if including tests):How to Configure for Azure OpenAI
.envfile:AZURE_OPENAI_API_KEY: Your Azure OpenAI API key.AZURE_OPENAI_ENDPOINT: Your Azure OpenAI resource endpoint (e.g.,https://your-resource.openai.azure.com/).AZURE_OPENAI_API_VERSION: The API version for your Azure OpenAI service (e.g.,2023-07-01-preview).AZURE_OPENAI_CHAT_DEPLOYMENT: The name of your chat model deployment in Azure.AZURE_OPENAI_EMBEDDING_DEPLOYMENT: The name of your embedding model deployment in Azure.The server will automatically prioritize Azure OpenAI if these core variables are correctly configured.
Considerations
A note on development: The Azure integration was initiated with AI assistance (Jules, Google AI) and then thoroughly reviewed, tested, and refined by me (@caiorg).
Feedback and review are welcome!