SwiftOpenAI icon indicating copy to clipboard operation
SwiftOpenAI copied to clipboard

`baseURL` does not work for services that has the OpenAI compatible API under a sub-path

Open sindresorhus opened this issue 1 year ago • 1 comments

For example, https://api.groq.com/openai does not work as a baseURL. The openai parts gets replaced and the URL ends up as https://api.groq.com/v1/chat/completions instead.

It's what Groq uses to access their OpenAI compatible API: https://console.groq.com/docs/openai

sindresorhus avatar Aug 09 '24 23:08 sindresorhus

@jamesrochabrun feel free to borrow my approach in AIProxySwift to solve this:

https://github.com/lzell/AIProxySwift/blob/main/Sources/AIProxy/AIProxyURLRequest.swift#L23-L30

Basically, create two URLComponents (one for the baseURL, and one for the completions path), then concatenate their paths. Remember to put the query params back in (line 31)

lzell avatar Aug 11 '24 18:08 lzell

@jamesrochabrun Would you accept a pull request for this?

sindresorhus avatar Oct 07 '24 19:10 sindresorhus

@sindresorhus yes!

jamesrochabrun avatar Oct 08 '24 05:10 jamesrochabrun

support for Groq is now available https://github.com/jamesrochabrun/SwiftOpenAI/releases/tag/v3.8.2 @sindresorhus

jamesrochabrun avatar Oct 12 '24 06:10 jamesrochabrun