-
Notifications
You must be signed in to change notification settings - Fork 382
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
Custom http headers #93
base: main
Are you sure you want to change the base?
Conversation
…e. Refactor URLRequestBuildable and its implementations to separate configuration concerns from URL building concerns.
… that the code better adheres to the Single Responsibility Principle.
…nly be used by the OpenAI class.
…o enable future extension and/or testing.
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
Hi! Is there anything more I need to do in order to get this merged? |
Hey, @benvolioT! |
// on the next pass in case that new data has completed the string to create valid (parsable) JSON, and so on. | ||
// Note that while OpenAI's API doesn't appear to return partial string fragments, proxy service such as Helicone | ||
// do seem to do so, making this logic necessary. | ||
accumulatedData.append(stringContent) |
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.
Could you extract this change to a separate PR, please?
Looks like this is a separate fix, that doesn't apply to custom headers.
} | ||
|
||
extension OpenAI { | ||
internal func generateHeaders() -> [String: String] { |
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.
I would change the naming to defaultHeaders
to add the knowledge that it is going to be appended further.
What do you think?
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.
Overall looks good to me, thanks for the contribution!
- Please fix the build.
- Fix merge conflicts
- Extract
StreamingSession
fix into a separate PR.
Thanks!
Feat: Get token usage data for streamed chat completion response.
Quality Gate passedIssues Measures |
What
This pull request adds the ability to specify custom HTTP headers when integrating with OpenAI via proxy APIs such as Helicone. It also refactors OpenAi's performRequest() by encapsulating the logic for handling the session data task in its own class, URLSessionDataTaskManager. This should simplify the OpenAI class and make the code easier to manage. This pull request simplifies JSONRequest and MultipartFormDataRequest by abstracting out common code to remove repetition that previously existed in these structs. Finally, it simplifies the protocol URLRequestBuildable, moving configuration-driven parameter setting to the constructors of these struct instances, rather than in the call to that protocol's build() function.
Why
The motivation for this change was to allow users to integrate with OpenAI via the Helicone proxy. To do so, they not only need to point the OpenAI client at the Helicone host, but they also have to set an additional HTTP header on the requests. This pull request makes that possible.
Affected Areas
The affected areas of the library include: