-
Notifications
You must be signed in to change notification settings - Fork 42
Make HTTP transporter setup in registry more flexible to not throw discovery exception when no HTTP request is even being attempted #164
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: trunk
Are you sure you want to change the base?
Conversation
…scovery exception when no HTTP request is even being attempted.
|
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 Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @dgrieser. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. 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. |
|
Really interesting, @felixarntz! If I'm following, this comes down to the fact that the WP AI Client doesn't connect the I mean, really, the discovery system can be hooked up as soon as possible. It doesn't require that anything in WordPress itself is loaded at that time. I could see providers wanting to be registered (and even usable) prior to As a note, while the WP AI Client does load in If I'm tracking with all that, the goal of this PR is to at least make it so that when a provider is registered prior to this point it still works. This done is by suppressing the My only concern with this is the remaining race condition of someone trying to use Am I tracking with all this? |
|
@JasonTheAdams I think you're right on all accounts. But I'd like us to look at this from a less WordPress-centric angle too. While we can shuffle things around in the WP AI Client, and maybe set up the HTTP client very early in the WordPress bootstrap cycle, I think there's still no point in throwing an HTTP discovery exception when a provider is registered. So this PR is mostly about being more "forgiving", or less aggressive. An HTTP client and HTTP transporter only need to be set up once any AI HTTP request is made (e.g. via So to your last point, I'm not sure I follow what your concern is with |
|
Got it. I'm tracking with what you mean. The think the nested I think if we drop the use of that trait and make it a nullable property, then we can clean that up. The only other place the getter is used is in |
|
Hmm, but why not use the trait? Can you clarify what you think is the problem with it? |
The problem is that the trait assumes the transporter is non-nullable, which is why we're having to catch the exception for the getter. In the case of the Make sense? |
This partially will fix WordPress/wp-ai-client#41 - specifically, when a provider is registered before an HTTP client has been configured in the PSR-17 discovery mechanism.
This is probably not sufficient by itself as a proper fix for that issue, but it's already a partial fix, which means a workaround will no longer be needed. And since this library is not meant to be only used with WordPress, it makes sense to optimize for general flexibility:
This PR fixes that, by dynamically attempting to set the default HTTP transporter when no (other) HTTP transporter has already been set, and doing that in a way that is forgiving in terms of the discovery exception.
cc @martin-helmich @LukasFritzeDev