-
Notifications
You must be signed in to change notification settings - Fork 24
Disable Experiments when no valid AI credentials are found #100
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
Conversation
…set or if we have valid API credentials set
…dentials and if not, output an error message and force the toggle off
…f none are found, show an error. Remove check when saving since it's redundant
…if globally enabled, locally enabled or enabled via a filter. Ensure we load the AI Client before anything else so it's available to use
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
felixarntz
left a comment
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.
@dkotter Looks solid, only two things I think need to be fixed.
includes/helpers.php
Outdated
| return false; | ||
| } | ||
|
|
||
| return AI_Client::prompt( 'Test' )->is_supported_for_text_generation(); |
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.
This technically doesn't check whether AI credentials are valid. It only checks whether at least one model is available to satisfy the prompt requirements.
Now, in practice, all 3 default provider implementations require API keys even to call the endpoint to list the available models, which happens as part of that. So I suppose you can still use this here as a way to check. However, that'll only mean the API request that happens at some point will fail and throw an exception, so the code here doesn't cater for that.
I'd suggest the following:
- Immediate action: Wrap this in a try catch and return
falseif it throws. - Separately: Consider whether/how we want to more formally enable checking for credential validity in the PHP/WP AI Client packages or whether this technique here is how we think it should be done.
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.
Added that try/catch here: 12b716a, let me know if that looks better
includes/helpers.php
Outdated
| } | ||
|
|
||
| // If we have no AI credentials, return false. | ||
| if ( ! has_ai_credentials() ) { |
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.
Shouldn't this be called before the filter? If you don't have any AI credentials, you certainly don't have valid AI credentials.
It makes sense to me to allow filtering/overriding the validity check logic, but the prerequisite should always be that there are AI credentials at all.
Otherwise, this also throws a wrench in things when e.g. for the admin notice you're also checking has_ai_credentials(), which would lead to a misleading notice if that filter here was overriding the result to be true.
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.
Yep, makes sense. Moved this filter down: 12b716a
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## trunk #100 +/- ##
============================================
+ Coverage 29.19% 29.61% +0.41%
- Complexity 142 145 +3
============================================
Files 14 14
Lines 846 878 +32
============================================
+ Hits 247 260 +13
- Misses 599 618 +19
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
felixarntz
left a comment
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.
@dkotter LGTM!
One minor point, but not a blocker.
What?
Closes #30
Ensure we have valid AI credentials before we allow any Experiment to be used
Why?
Right now you can enable any Experiment even if you haven't added any AI credentials. This can lead to confusion for users that then try and use that Experiment and it doesn't work properly. This is also the case if you add invalid credentials.
The AI Credentials setting screen is coming from the WP AI Client package and doesn't do any validation when credentials are saved. This PR adds that validation, when someone lands on our settings screen, and an error message will be shown if they either have no credentials set up or their credentials aren't valid. They are then prompted to go add valid credentials before proceeding.
How?
has_ai_credentials,has_valid_ai_credentialshas_valid_ai_credentialsand return false appropriately, so an Experiment won't work if we don't have valid credentialsNote
If we ever introduce an Experiment that doesn't need to use AI, we'll want to update this logic.
Testing Instructions
Screenshots or screencast