OpenDive / OpenAIKit

Swift Package for OpenAI's API
MIT License
248 stars 46 forks source link

Proxy through server #37

Open aehlke opened 1 year ago

aehlke commented 1 year ago

Describe the feature or improvement you're requesting

I want to meter users by proxying requests through my server, but I still want to use your nice interface to the API instead of creating a new one for the server interaction. So I'd love to be able to send the requests to a custom hostname or base URL, without needing an API key and then I can ship this to iOS apps too.

Additional context

No response

MarcoDotIO commented 1 year ago

So more or less a way of changing the base URL used for the API? I can add in a parameter to change out the URL for proxies, as long as your own proxy has the same mechanisms of handling traffic from and to the app.

aehlke commented 1 year ago

Thanks for the reply. I've read through more of your source and think the ideal for my use case at least would be to be able to swap in both a custom base URL as well as a custom "base API client" so that I can use my own server's auth schemes.

In my case I generate OpenAPI clients for my server via openapi-generator using URLTask async/await in swift5. I'm thinking how best to abstract OpenAI.swift in this project to allow swapping in alternative API clients for users who already have something working for server auth or other network/header needs for delivering the request payload. Maybe define a protocol and let the user swap in something that bridges to the user's API client library to the payload you want to deliver

MarcoDotIO commented 1 year ago

Thanks for the reply. I've read through more of your source and think the ideal for my use case at least would be to be able to swap in both a custom base URL as well as a custom "base API client" so that I can use my own server's auth schemes.

In my case I generate OpenAPI clients for my server via openapi-generator using URLTask async/await in swift5. I'm thinking how best to abstract OpenAI.swift in this project to allow swapping in alternative API clients for users who already have something working for server auth or other network/header needs for delivering the request payload. Maybe define a protocol and let the user swap in something that bridges to the user's API client library to the payload you want to deliver

I'll create a branch for this repo, and I will let you try it out to see if it fits within your requirements. Once a decision is a made, I'll go ahead and release the feature for my next version that'll include Whisper's endpoints.

aehlke commented 1 year ago

Thank you, happy to give feedback. For now I've forked to meet my needs but didn't find a nice way to contribute something back upstream, so it's great if you have a better way in mind.

MarcoDotIO commented 1 year ago

Heyo,

It's a pleasure to have you suggest the feature in the first place. I'd be more than happy to see how your own implementation went. I do agree that having a more advanced feature for proxy servers would be beneficial for this project. Let me know if you're interested in publishing a PR or just willing to share your own code.