OpenAI
OpenAI copied to clipboard
Enable basePath when proxy openai with own host with base path
Is your feature request related to a problem? Please describe. Right, it's pretty nice we can init a OpenAI with custom host, like
let openAI = OpenAI(configuration: OpenAI.Configuration(
token: "sk-xxx",
organizationIdentifier: "org-xxx",
host: "api.myhost",
timeoutInterval: 60.0)
)
It would even move better enabling a basePath like this,
let openAI = OpenAI(configuration: OpenAI.Configuration(
token: "sk-xxx",
organizationIdentifier: "org-xxx",
host: "api.myhost",
basePath: "/openai/api",
timeoutInterval: 60.0)
)
Since most of the time we have multiple endpoints for a host.
Describe the solution you'd like
It will be a simple changes on the current implementation actually.
public init(
token: String,
organizationIdentifier: String? = nil,
host: String = "api.openai.com",
basePath: String? = "",
timeoutInterval: TimeInterval = 60.0
) {
self.token = token
self.organizationIdentifier = organizationIdentifier
self.host = host
self.basePath = basePath ?? ""
self.timeoutInterval = timeoutInterval
}
....
extension OpenAI {
func buildURL(path: String) -> URL {
var components = URLComponents()
components.scheme = "https"
components.host = configuration.host
components.path = self.configuration.basePath + path
return components.url!
}
}
If it's an acceptable changes, I can draft a PR.
Describe alternatives you've considered None.
Additional context None.
It makes sense to me; would the basePath solution also solve #61?
Cool, a PR drafted, please help review it.
Hey @SunburstEnzo , could you help review it? thanks a lot.