OpenAI icon indicating copy to clipboard operation
OpenAI copied to clipboard

Custom http headers

Open benvolioT opened this issue 2 years ago • 4 comments

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:

  • The OpenAI class within the OpenAI.swift file.
  • The client configuration within the constructor of the OpenAI class.
  • The construction of requests in the following methods: completions(), completionsStream(), images(), embeddings(), chats(), chatsStream(), edits(), model(), models(), moderations(), audioTranscriptions(), and audioTranslations().

benvolioT avatar Jul 30 '23 04:07 benvolioT

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

sonarqubecloud[bot] avatar Aug 07 '23 03:08 sonarqubecloud[bot]

Hi! Is there anything more I need to do in order to get this merged?

benvolioT avatar Aug 19 '23 17:08 benvolioT

Hey, @benvolioT! Thanks a lot for the contribution! Please fix build and merge conflicts 🙏

Krivoblotsky avatar Aug 22 '23 11:08 Krivoblotsky