Infer Azure region from endpoint - #184
Closed
jnu wants to merge 1 commit into
Closed
Conversation
| return resource_name.rsplit("-", 1)[-1] or None | ||
|
|
||
|
|
||
| class OpenAIConfig(BaseModel): |
There was a problem hiding this comment.
Bug: The _azure_region function may incorrectly extract a region from an Azure OpenAI hostname if the name doesn't contain a hyphen, causing cost estimation to fail.
Severity: MEDIUM
Suggested Fix
The _azure_region function should be updated to handle hostnames without a hyphen. One approach is to return None if rsplit("-", 1) results in a list with only one element, indicating no hyphen was found. Alternatively, the extracted value could be validated against a list of known Azure region names.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: bc2/core/common/openai.py#L634
Potential issue: The `_azure_region` function attempts to infer the Azure region by
splitting the resource hostname on the last hyphen. However, if an Azure OpenAI resource
name does not contain a hyphen (e.g., `myresource.openai.azure.com`), the function will
incorrectly return the entire resource name as the region. This invalid region name is
then used to query the Azure Retail Prices API, which returns no results. Consequently,
the application will raise an `AzurePricingUnavailable` exception, preventing cost
estimation for that resource.
Did we get this right? 👍 / 👎 to inform future reviews.
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
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.
When the region is not set in the runtime config, it can be inferred from the openai service endpoints. This also solves the issue of having cross-region deployments.