-
Notifications
You must be signed in to change notification settings - Fork 52
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
Ensure we don't send unnecessary requests to the Watson API #415
Comments
Other Providers have an classifai/includes/Classifai/Providers/Watson/NLU.php Lines 903 to 910 in ae7f106
It seems like we could get rid of this classifai/includes/Classifai/Providers/Provider.php Lines 384 to 398 in ae7f106
Then NLU's If this sounds like a good approach, I'll update my PR to match. |
@benlk The That said, one of my main goals over the last month or two has been trying to clean up the codebase and bring alignment in approaches. The way NLU is set up differs from our other providers and the goal is to make those as similar as possible. So this is a great opportunity to help with that. I'd suggest looking to use the |
Next steps:
|
Describe the bug
While testing #405 I noticed I was getting HTTP requests to the Watson API even when on the OpenAI settings page. In investigating further, I was seeing requests to this API on every single page load, including the front-end. This can result in potentially thousands of extra API requests on sites with lots of traffic.
In investigating this, the issue is in the
can_register
method of theNLU
class. Thecan_register
method for eachProvider
is called oninit
, so this code runs on all requests. The problem in theNLU
class is we make an authentication request withincan_register
, so we hit the API on every single request.This may have just been an oversight when this was built or it may have been done purposely to ensure we always have a valid connection but I would classify this as a bug that we need to fix. I would suggest we change how this works to match what we do for ComputerVision and ChatGPT, where we check these credentials when settings are saved and store the result of that, which we then check in the
can_register
methods.The only downside I can think of is there is a scenario where credentials are valid when they are saved but later an API key may be revoked. Checking credentials more often allows us to alert the user sooner, though I don't think we are actually outputting any error message at the moment if that happens. So I don't think there's any issue with making this change.
Steps to Reproduce
Install a plugin like Query Monitor and inspect the HTTP requests that are made on any page load
Screenshots, screen recording, code snippet
No response
Environment information
No response
WordPress information
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: