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

Enable use of Azure OpenAI client #592

Merged
merged 4 commits into from
May 23, 2024
Merged

Enable use of Azure OpenAI client #592

merged 4 commits into from
May 23, 2024

Conversation

drdavella
Copy link
Member

Overview

Enable use of Azure OpenAI client as alternative to OpenAI

Details

Copy link

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud


azure_openapi_key = os.getenv("CODEMODDER_AZURE_OPENAI_API_KEY")
azure_openapi_endpoint = os.getenv("CODEMODDER_AZURE_OPENAI_ENDPOINT")
if bool(azure_openapi_key) ^ bool(azure_openapi_endpoint):
Copy link
Contributor

Choose a reason for hiding this comment

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

could use walrus here for 2 lines above

Copy link
Member Author

Choose a reason for hiding this comment

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

That's true although I think in this case it might make it a little harder to read 😅

if not Client:
logger.debug("OpenAI API client not available")
def _setup_llm_client(self) -> OpenAI | None:
if not AzureOpenAI:
Copy link
Contributor

Choose a reason for hiding this comment

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

the PR description is not very descriptive so I'm guessing here but if the goal is to use either OpenAI or AzureOpenAI (or nothing), shouldn't the if not OpenAI: check also be up here and not short circuit ` if not AzureOpenAI:``

Copy link
Member Author

Choose a reason for hiding this comment

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

The order of precedence is to check for Azure OpenAI first and then OpenAI as per the spec linked above. However there's not really going to be a case where AzureOpenAI is defined but OpenAI is not. That means the check below for OpenAI is theoretically redundant although it does help satisfy the type checker.

Copy link
Contributor

Choose a reason for hiding this comment

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

ah thanks for clarifying. if there isn't such case you could if not AzureOpenAI or OpenAI but it's all good

Copy link
Member Author

Choose a reason for hiding this comment

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

That's true, that's probably a bit clearer.

@@ -77,3 +82,120 @@ def test_failed_dependency_description(self, mocker):
```"""
in description
)

def test_setup_llm_client_no_env_vars(self, mocker):
Copy link
Contributor

Choose a reason for hiding this comment

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

could add some caplog assertions for the logging, maybe that would clear up my misunderstanding above

@drdavella drdavella requested a review from clavedeluna May 23, 2024 21:10
@drdavella drdavella added this pull request to the merge queue May 23, 2024
Merged via the queue into main with commit a66333c May 23, 2024
12 checks passed
@drdavella drdavella deleted the azure-openai-client branch May 23, 2024 21:29
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.

2 participants