jamesrochabrun / SwiftAnthropic

An open-source Swift package for interacting with Anthropic's public API.
90 stars 29 forks source link

Support for alternative base URL? #8

Closed bcherry closed 6 months ago

bcherry commented 6 months ago

We're going to be using this library in a production iOS app. We have setup our own proxy service and per-user key management to support that.

We need support for changing the URL base to our own service. I've done a quick spike that makes it work here: https://github.com/bcherry/SwiftAnthropic/compare/624aec8916cc4b039a7efca1efae9e4941c16c2a..3c5dce4b2f267048fdcc22c751ac318cf5a7e54d but I thought I'd send a note before writing a PR in case you have a different idea for the best way to integrate it with the structure of your networking code (I had to change AnthropicAPI from an enum to a struct to get this to work, for instance).

Let me know if you'd like a pull request!

jamesrochabrun commented 6 months ago

Thanks for bringing this up, this commit should allow you to make the base URL configurable. https://github.com/jamesrochabrun/SwiftAnthropic/commit/6ad5a29e7323dab6d83c636be3726d6a32ad06e2 Let me know if this is not sufficient!

bcherry commented 6 months ago

awesome, thank you! I will try this out and get back to you. Our proxy currently has an extra URL path component that's needed in front so I still need this bit from my change

      var components = URLComponents(string: base)!
      components.path = path
      components.path = (components.path ?? "") + path
      if !queryItems.isEmpty {
         components.queryItems = queryItems
      }

But we're removing that today or tomorrow so I'll pick up yours then