Skip to content
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

Enable basePath when proxy openai with own host with base path #68

Open
metrue opened this issue May 15, 2023 · 3 comments
Open

Enable basePath when proxy openai with own host with base path #68

metrue opened this issue May 15, 2023 · 3 comments

Comments

@metrue
Copy link

metrue commented May 15, 2023

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.

@SunburstEnzo
Copy link
Contributor

It makes sense to me; would the basePath solution also solve #61?

@metrue
Copy link
Author

metrue commented May 16, 2023

Cool, a PR drafted, please help review it.

@metrue
Copy link
Author

metrue commented May 29, 2023

Hey @SunburstEnzo , could you help review it? thanks a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants