Draft: Decouple modules from (ok)http client #1103
Draft
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.
Issue
#1044
Change
This is the first step towards decoupling modules from (ok)http client.
This PR introduces an abstraction layer (in
langchain4j-core
module) over various http clients.Main components:
HttpClient
HttpClientBuilder
HttpRequest
HttpResponse
This PR also provides 2 implementations of
HttpClient
:OkHttpHttpClient
(uses okhttp that is currently used in most modules, but does not use retrofit)SpringRestClientHttpClient
(usesRestClient
from Spring)More implementations (e.g. JDK 11
HttpClient
) can be added later.The first module to migrate is
langchain4j-anthropic
, this PR decouples it from okhttp.Users are able to provide a
HttpClientBuilder
when creatingAnthropic*Model
. If not provided, default (okhttp) will be loaded via SPI.With this change, request/response logging is also unified and moved to
HttpRequestLogger
andHttpResponseLogger
. So all modules can now get logging for free.General checklist
Checklist for adding new model integration