Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Sep 23, 2025

The migration modernizes the codebase to use the current OpenAI SDK API surface, removing deprecated Azure-specific constructors while maintaining full compatibility with Azure OpenAI services (passing in token_provider as api_key). Requires recent version of openai SDK.

Fixes #2751.

Steps

  • Analyzed repository structure and identified deprecated constructors
  • Found OpenAI version 1.99.8 is installed (>= 1.108.1 as required)
  • Located 3 instances of deprecated AzureOpenAI/AsyncAzureOpenAI constructors
  • Update requirements.in to specify openai>=1.108.1
  • Replace AsyncAzureOpenAI constructors with AsyncOpenAI
  • Remove api_version parameter usage
  • Remove AZURE_OPENAI_API_VERSION environment variable references
  • Update Bicep infrastructure to remove API version output
  • Clean up remaining AsyncAzureOpenAI imports
  • Fix Azure OpenAI endpoint URL format for embeddings service
  • Fix all endpoint URLs to use correct /openai/v1 format
  • Remove AZURE_OPENAI_API_VERSION from workflow files and documentation
  • Address PR review feedback:
    • Revert logging level from DEBUG back to WARNING
    • Remove redundant AZURE_OPENAI_ENDPOINT computation and use value from setup_openai_client
    • Revert unrelated type annotation changes in searchmanager.py

Key Changes Made:

  1. Constructor migration: AsyncAzureOpenAI()AsyncOpenAI()
  2. Parameter mapping: azure_endpointbase_url, azure_ad_token_providerapi_key
  3. Removed api_version: Deleted all api_version= arguments and related environment variables
  4. Updated requirements: Bumped minimum OpenAI version to 1.108.1
  5. Infrastructure updates: Removed AZURE_OPENAI_API_VERSION from Bicep files
  6. Clean imports: Removed unused AsyncAzureOpenAI imports
  7. Fix URL format: Updated all endpoint URLs to use /openai/v1 format
  8. Fix model parameter: Use deployment name for Azure OpenAI API calls
  9. Remove workflow references: Cleaned up AZURE_OPENAI_API_VERSION from GitHub Actions and Azure DevOps pipelines
  10. Update documentation: Removed API version settings from reasoning model setup docs

Validation Results:

✅ All Python files compile without syntax errors
✅ JSON configuration files are valid
✅ Requirements.in updated to openai>=1.108.1
✅ No remaining AZURE_OPENAI_API_VERSION references in core application code
✅ All AsyncAzureOpenAI constructor calls replaced with AsyncOpenAI
✅ Azure OpenAI endpoint URLs use correct /openai/v1 format
✅ Workflow files and documentation updated
✅ PR review feedback addressed

Copilot AI changed the title [WIP] Migrate AzureOpenAI constructors to OpenAI client Migrate AzureOpenAI constructors to standard OpenAI client Sep 23, 2025
Copilot AI requested a review from pamelafox September 23, 2025 22:14
Copilot finished work on behalf of pamelafox September 23, 2025 22:14
azure_deployment=self.open_ai_deployment,
api_version=self.open_ai_api_version,
# For Azure OpenAI, we need to include the deployment in the URL
base_url = f"{self.open_ai_endpoint}/openai/deployments/{self.open_ai_deployment}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot This should be {self.open_ai_endpoint}/openai/v1 now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed the Azure OpenAI endpoint URL format to use /openai/v1 and updated the model parameter to use the deployment name for Azure OpenAI API calls. Commit: 76e5cb6

logger.info("AZURE_OPENAI_API_KEY_OVERRIDE found, using as api_key for Azure OpenAI client")
openai_client = AsyncAzureOpenAI(
api_version=azure_openai_api_version, azure_endpoint=endpoint, api_key=azure_openai_api_key
openai_client = AsyncOpenAI(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot The endpoint must end with "/openai/v1" now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed all Azure OpenAI endpoints in prepdocs.py to use the correct /openai/v1 format. Commit: 5d23055

)

# https://learn.microsoft.com/azure/ai-services/openai/api-version-deprecation#latest-ga-api-release
azure_openai_api_version = os.getenv("AZURE_OPENAI_API_VERSION") or "2024-06-01"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Isn't AZURE_OPENAI_API_VERSION in other files as well, like the GitHub actions workflows?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're absolutely right! Found and removed AZURE_OPENAI_API_VERSION references from GitHub Actions workflows (.github/workflows/azure-dev.yml, .github/workflows/evaluate.yaml), Azure DevOps pipeline (.azdo/pipelines/azure-dev.yml), and documentation (docs/reasoning.md). The only remaining reference is in evals/generate_ground_truth.py which uses LangChain wrappers, not the OpenAI SDK directly. Commit: 5d23055

Copy link
Collaborator

@pamelafox pamelafox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments

Copilot AI requested a review from pamelafox September 23, 2025 23:42
Copilot finished work on behalf of pamelafox September 23, 2025 23:42
Copilot finished work on behalf of pamelafox September 23, 2025 23:49
@pamelafox pamelafox requested a review from Copilot October 29, 2025 06:15
@github-actions
Copy link

Check Broken URLs

We have automatically detected the following broken URLs in your files. Review and fix the paths to resolve this issue.

Check the file paths and associated broken URLs inside them.
For more details, check our Contributing Guide.

File Full Path Issues
data/Contoso_Electronics_Company_Overview.md
#LinkLine Number
1http://www.contoso.com46
2http://www.contoso.com48

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR migrates the embeddings implementation from separate AzureOpenAIEmbeddingService and OpenAIEmbeddingService classes to a unified OpenAIEmbeddings class, simplifying the architecture by accepting a pre-configured OpenAI client. The change removes the need for API version configuration and consolidates authentication logic.

Key Changes:

  • Unified embeddings service using a single OpenAIEmbeddings class
  • Removed AZURE_OPENAI_API_VERSION configuration parameter across all infrastructure and application code
  • Updated OpenAI SDK from version 1.99.8 to 2.6.1
  • Refactored test mocks to work with the new unified embeddings approach

Reviewed Changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
app/backend/prepdocslib/embeddings.py Removed separate Azure/OpenAI service classes; unified into OpenAIEmbeddings with client injection
app/backend/prepdocs.py Updated setup_embeddings_service to accept pre-configured client instead of creating clients internally
app/backend/app.py Removed API version parameter; updated client setup and endpoint construction
app/backend/requirements.in Updated OpenAI SDK minimum version requirement to 1.109.1
app/backend/requirements.txt Updated OpenAI SDK to version 2.6.1
tests/test_*.py Refactored tests to use unified embeddings class and simplified mocking
infra/main.bicep Removed AZURE_OPENAI_API_VERSION parameter and environment variable
docs/reasoning.md Removed API version configuration instructions
Comments suppressed due to low confidence (1)

tests/test_prepdocs.py:33

  • The MockEmbeddingsClient and MockClient classes are duplicated from tests/mocks.py (lines 333-343). This duplication creates a maintenance burden. Consider importing these classes from tests.mocks instead of redefining them, similar to how MOCK_EMBEDDING_DIMENSIONS and MOCK_EMBEDDING_MODEL_NAME are imported.
class MockEmbeddingsClient:
    def __init__(self, create_embedding_response: openai.types.CreateEmbeddingResponse):
        self.create_embedding_response = create_embedding_response

    async def create(self, *args, **kwargs) -> openai.types.CreateEmbeddingResponse:
        return self.create_embedding_response


class MockClient:
    def __init__(self, embeddings_client):
        self.embeddings = embeddings_client

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions
Copy link

Check Broken URLs

We have automatically detected the following broken URLs in your files. Review and fix the paths to resolve this issue.

Check the file paths and associated broken URLs inside them.
For more details, check our Contributing Guide.

File Full Path Issues
CONTRIBUTING.md
#LinkLine Number
1https://opensource.microsoft.com/codeofconduct/11
2https://opensource.microsoft.com/codeofconduct/faq/12
README.md
#LinkLine Number
1https://azure.microsoft.com/pricing/details/monitor/97
2https://learn.microsoft.com/azure/cognitive-services/openai/overview279
docs/data_ingestion.md
#LinkLine Number
1https://learn.microsoft.com/azure/search/search-howto-schedule-indexers104
docs/productionizing.md
#LinkLine Number
1https://oai.azure.com/20
2https://learn.microsoft.com/azure/developer/python/get-started-app-chat-scaling-with-azure-container-apps29
docs/deploy_features.md
#LinkLine Number
1https://learn.microsoft.com/azure/ai-services/openai/concepts/models41
2https://learn.microsoft.com/azure/ai-services/openai/concepts/models79
docs/reasoning.md
#LinkLine Number
1https://learn.microsoft.com/azure/ai-services/openai/concepts/models#standard-deployment-model-availability19
docs/safety_evaluation.md
#LinkLine Number
1https://learn.microsoft.com/azure/ai-studio/how-to/develop/simulator-interaction-data76
2https://learn.microsoft.com/azure/ai-studio/how-to/develop/evaluate-sdk77
docs/deploy_private.md
#LinkLine Number
1https://azure.microsoft.com/pricing/details/container-registry/32
docs/login_and_acl.md
#LinkLine Number
1https://learn.microsoft.com/azure/app-service/configure-common?tabs=portal#configure-app-settings240
2https://learn.microsoft.com/azure/storage/blobs/data-lake-storage-acl-cli325
3https://learn.microsoft.com/entra/identity-platform/v2-oauth2-client-creds-grant-flow364
docs/deploy_existing.md
#LinkLine Number
1https://learn.microsoft.com/azure/ai-services/document-intelligence/concept-layout90
docs/localdev.md
#LinkLine Number
1https://code.visualstudio.com/docs/copilot/chat/chat-modes107

@github-actions
Copy link

Check Broken URLs

We have automatically detected the following broken URLs in your files. Review and fix the paths to resolve this issue.

Check the file paths and associated broken URLs inside them.
For more details, check our Contributing Guide.

File Full Path Issues
CONTRIBUTING.md
#LinkLine Number
1https://opensource.microsoft.com/codeofconduct/11
2https://opensource.microsoft.com/codeofconduct/faq/12
docs/data_ingestion.md
#LinkLine Number
1https://learn.microsoft.com/azure/search/search-howto-schedule-indexers104
docs/productionizing.md
#LinkLine Number
1https://oai.azure.com/20
docs/deploy_features.md
#LinkLine Number
1https://learn.microsoft.com/azure/ai-services/openai/concepts/models41
2https://learn.microsoft.com/azure/ai-foundry/foundry-models/concepts/deployment-types117
3https://learn.microsoft.com/azure/ai-services/openai/concepts/models?tabs=global-standard%2Cstandard-chat-completions#models-by-deployment-type223
4https://learn.microsoft.com/azure/ai-services/speech-service/overview309
docs/reasoning.md
#LinkLine Number
1https://learn.microsoft.com/azure/ai-services/openai/concepts/models#standard-deployment-model-availability19
docs/safety_evaluation.md
#LinkLine Number
1https://learn.microsoft.com/azure/ai-studio/how-to/develop/simulator-interaction-data76
docs/login_and_acl.md
#LinkLine Number
1https://learn.microsoft.com/entra/identity/role-based-access-control/permissions-reference#cloud-application-administrator54
2https://learn.microsoft.com/entra/identity-platform/scenario-spa-app-registration58
3https://learn.microsoft.com/entra/identity-platform/publisher-verification-overview242
4https://learn.microsoft.com/azure/storage/blobs/data-lake-storage-acl-cli325
docs/deploy_existing.md
#LinkLine Number
1https://learn.microsoft.com/dotnet/api/microsoft.azure.search.models.field.analyzer?view=azure-dotnet-legacy&viewFallbackFrom=azure-dotnet67
docs/localdev.md
#LinkLine Number
1https://code.visualstudio.com/docs/copilot/chat/chat-modes107

@github-actions
Copy link

Check Broken URLs

We have automatically detected the following broken URLs in your files. Review and fix the paths to resolve this issue.

Check the file paths and associated broken URLs inside them.
For more details, check our Contributing Guide.

File Full Path Issues
CONTRIBUTING.md
#LinkLine Number
1https://opensource.microsoft.com/codeofconduct/11
2https://opensource.microsoft.com/codeofconduct/faq/12
README.md
#LinkLine Number
1https://azure.microsoft.com/pricing/details/cognitive-services/openai-service/90
2https://azure.microsoft.com/pricing/details/monitor/97
docs/data_ingestion.md
#LinkLine Number
1https://learn.microsoft.com/azure/search/search-howto-schedule-indexers104
docs/productionizing.md
#LinkLine Number
1https://oai.azure.com/20
2https://learn.microsoft.com/azure/developer/python/get-started-app-chat-scaling-with-azure-api-management28
docs/deploy_features.md
#LinkLine Number
1https://learn.microsoft.com/entra/identity-platform/howto-restrict-your-app-to-a-set-of-users358
2https://learn.microsoft.com/azure/developer/python/get-started-app-chat-scaling-with-azure-api-management416
docs/deploy_private.md
#LinkLine Number
1https://azure.microsoft.com/pricing/details/dns/40
2https://azure.microsoft.com/pricing/details/dns/41
docs/localdev.md
#LinkLine Number
1https://code.visualstudio.com/docs/copilot/chat/chat-modes107

@github-actions
Copy link

Check Broken URLs

We have automatically detected the following broken URLs in your files. Review and fix the paths to resolve this issue.

Check the file paths and associated broken URLs inside them.
For more details, check our Contributing Guide.

File Full Path Issues
CONTRIBUTING.md
#LinkLine Number
1https://opensource.microsoft.com/codeofconduct/11
2https://opensource.microsoft.com/codeofconduct/faq/12
docs/productionizing.md
#LinkLine Number
1https://oai.azure.com/20
docs/login_and_acl.md
#LinkLine Number
1https://learn.microsoft.com/entra/identity/role-based-access-control/permissions-reference#cloud-application-administrator54
2https://learn.microsoft.com/graph/permissions-reference#user-permissions151
3https://learn.microsoft.com/entra/identity-platform/quickstart-create-new-tenant239
docs/localdev.md
#LinkLine Number
1https://code.visualstudio.com/docs/copilot/chat/chat-modes107

@pamelafox pamelafox marked this pull request as ready for review October 29, 2025 22:15
dimensions: int


class OpenAIEmbeddings(ABC):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I simplified this file to reuse the openai_client that we set up in another part of the code, as I didn't like that we were doing the same setup in two places.



class IntegratedVectorizerStrategy(Strategy):
class IntegratedVectorizerStrategy(Strategy): # pragma: no cover
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This currently has no tests, and it doesn't feel necessary to add tests given the plans to move to prepdocs-as-a-function.

AZURE_OPENAI_CUSTOM_URL = os.getenv("AZURE_OPENAI_CUSTOM_URL")
# https://learn.microsoft.com/azure/ai-services/openai/api-version-deprecation#latest-ga-api-release
AZURE_OPENAI_API_VERSION = os.getenv("AZURE_OPENAI_API_VERSION") or "2024-10-21"
AZURE_OPENAI_ENDPOINT = (
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Remove this line that sets AZURE_OPENAI_ENDPOINT, and pass azure_openai_endpoint from setup_openai_client to setup_embeddings instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in commit ee14c51 - removed the redundant AZURE_OPENAI_ENDPOINT computation and now pass the azure_openai_endpoint value returned from setup_openai_client directly to setup_embeddings_service.

openai_api_key=clean_key_if_exists(os.getenv("OPENAI_API_KEY")),
openai_organization=os.getenv("OPENAI_ORGANIZATION"),
)
openai_embeddings_service = setup_embeddings_service(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved after, since its now dependent on the client

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense, and it's simpler at the end of the day

azure-identity
quart
quart-cors
flask==3.1.2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quart should bring in flask

pamelafox and others added 2 commits October 29, 2025 15:22
…putation, and revert unrelated type annotation changes

Co-authored-by: pamelafox <[email protected]>
@github-actions
Copy link

Check Broken URLs

We have automatically detected the following broken URLs in your files. Review and fix the paths to resolve this issue.

Check the file paths and associated broken URLs inside them.
For more details, check our Contributing Guide.

File Full Path Issues
CONTRIBUTING.md
#LinkLine Number
1https://opensource.microsoft.com/codeofconduct/faq/12

Copilot AI requested a review from pamelafox October 29, 2025 22:27
Copilot finished work on behalf of pamelafox October 29, 2025 22:27
@github-actions
Copy link

Check Broken URLs

We have automatically detected the following broken URLs in your files. Review and fix the paths to resolve this issue.

Check the file paths and associated broken URLs inside them.
For more details, check our Contributing Guide.

File Full Path Issues
docs/localdev.md
#LinkLine Number
1https://code.visualstudio.com/docs/copilot/chat/chat-modes107

@github-actions
Copy link

Check Broken URLs

We have automatically detected the following broken URLs in your files. Review and fix the paths to resolve this issue.

Check the file paths and associated broken URLs inside them.
For more details, check our Contributing Guide.

File Full Path Issues
docs/deploy_private.md
#LinkLine Number
1https://learn.microsoft.com/azure/private-link/private-endpoint-overview107

Copy link
Collaborator

@mattgotteiner mattgotteiner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, this is simpler now that we don't have separate AOAI and OAI clients

@pamelafox pamelafox merged commit 4d933cc into main Nov 3, 2025
59 of 62 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate AzureOpenAI constructors to OpenAI client

3 participants