Skip to content
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

Refactor Azure client initialization to reduce code duplication #823

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ylnsnv
Copy link

@ylnsnv ylnsnv commented Nov 15, 2023

Changes being requested

This PR streamlines the initialization process for AzureOpenAI and AsyncAzureOpenAI clients by centralizing common configuration steps. The main change involves the introduction of a _configure_client_settings method in BaseAzureClient, which handles the setup of API keys, tokens, and endpoints.

Key Changes:

  • Centralized configuration logic in BaseAzureClient.
  • Updated AzureOpenAI and AsyncAzureOpenAI to use the new configuration method.
  • Improved error handling for configuration parameters.

Benefits:

  • Reduces repetitive code across client classes.
  • Simplifies future updates and maintenance of the initialization process.

This update enhances the code's clarity and maintainability without introducing breaking changes.

Additional context & links

Centralized the configuration logic for AzureOpenAI and AsyncAzureOpenAI clients into the _configure_client_settings method in BaseAzureClient. This change eliminates repetitive code and enhances maintainability by consolidating common initialization steps such as setting up API keys, tokens, and endpoints.
@ylnsnv ylnsnv requested a review from a team as a code owner November 15, 2023 03:41
src/openai/lib/azure.py Outdated Show resolved Hide resolved
@gleason-m
Copy link

I'm not able to mark comments as Unresolved, so putting my feedback to your iteration in a separate comment:

Ahh, no you still want to check the env var, just raise the error if api_verison isn't provided and there is no env var set. Here's the original init snippet:

if api_version is None:
    api_version = os.environ.get("OPENAI_API_VERSION"

if api_version is None:
    raise ValueError(
        "Must provide either the `api_version` argument or the `OPENAI_API_VERSION` environment variable"
    )

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.

None yet

2 participants