-
Notifications
You must be signed in to change notification settings - Fork 586
MAINT: Adding URL validation for openai responses targets #1148
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
base: main
Are you sure you want to change the base?
Conversation
| Prints a warning if the endpoint doesn't match any of the expected routes. | ||
| This validation helps ensure the endpoint is configured correctly for the specific API. | ||
| """ | ||
| if not self._endpoint or not self._expected_route: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expected route isn't really specific to the instance of a class, but the class itself. As such, we should set it as a constant on the class and pass it as an argument into this method
EXPECTED_URL_REGEX = ...
...
def _warn_if_irregular_endpoint(self, expected_url_regex):
....
|
|
||
| # Check if the endpoint matches any of the expected routes | ||
| for expected_route in expected_routes: | ||
| if expected_route is None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
None? Why would that be in there?
| normalized_route = parsed_url.path.lower().rstrip("/") | ||
|
|
||
| # Handle both single route (string) and multiple routes (list) | ||
| expected_routes = self._expected_route if isinstance(self._expected_route, list) else [self._expected_route] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not allow lists of 1 element instead of the special case?
| if "*" in expected_route: | ||
| if self._matches_wildcard_pattern(normalized_route, expected_route): | ||
| return | ||
| else: | ||
| # Exact matching for routes without wildcards | ||
| if normalized_route == expected_route: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wouldn't regex matching be easier here?
| else f"one of: {', '.join(self._expected_route)}" | ||
| ) | ||
| logger.warning( | ||
| f"Expected endpoint to end with {expected_routes_str} " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| f"Expected endpoint to end with {expected_routes_str} " | |
| f"Expected endpoint to end with {expected_routes_str} " |
| ) | ||
| logger.warning( | ||
| f"Expected endpoint to end with {expected_routes_str} " | ||
| f"Please verify your endpoint URL: '{self._endpoint}'." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also pointing to our env_example can help
| self._model_name = "tts-1" | ||
|
|
||
| # Set expected route for URL validation | ||
| self._expected_route = "/openai/deployments/*/audio/speech" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wherever we have AOAI patterns we should also have OAI ones. For Sora it should include both sora1 and sora2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think just /audio/speech should be good and cover both?
Description
Our endpoints need the URL to end in the correct ending. This adds a warning so users can be aware of this and better debug since the default error message is a harder to understand error 500. This way the warning can point users to check their endpoint URL (see bug here: #1144)
Closes #1144
Tests:
Added unit tests