-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
feat: make RequestBuilder configurable #725
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #725 +/- ##
==========================================
+ Coverage 98.46% 98.67% +0.21%
==========================================
Files 24 24
Lines 1364 1135 -229
==========================================
- Hits 1343 1120 -223
+ Misses 15 9 -6
Partials 6 6 ☔ View full report in Codecov by Sentry. |
cf4f435
to
4b70b10
Compare
@WqyJh thank you for the PR! Could you outline some cases where exposed HTTPClient is not enough? |
HTTPClient is not enough for setting custom headers, which needs to modify Custom headers is useful if you use an non-official api-key. What's more, it's also useful to pass tracing information through headers. |
@WqyJh it is possible to modify requests with custom On another note, I think the biggest problem with custom request builders is that users would need to substitute full request builder logic every time: go-openai/internal/request_builder.go Lines 31 to 50 in c84ab5f
It might make sense to introduce instrumentation just before request is sent similar to gRPC interceptors concept. That might have better ergonomics than implementing custom HTTP transport. |
RequestBuilder
is an interface, therefore, it's designed to be extensible.However, currently it's a private field of
Client
, which make it impossible to customize.This PR moves
requestBuilder
toClientConfig
, making it configurable, so that users can implement their ownRequestBuilder
, which is very useful in situation of adding custom request headers and injecting tracing attributes.