ex_openai icon indicating copy to clipboard operation
ex_openai copied to clipboard

Using ex_openai with other OpenAI compatible API providers

Open preciz opened this issue 1 year ago • 4 comments

Currently multiple companies provide OpenAI API compatible endpoints.

At the moment my observation is that the library can only be used with OpenAI due to how configuration works.

Are there any plans to change the library so configuration is more flexible and multiple providers could be used at the same time?

preciz avatar May 22 '24 18:05 preciz

Sounds like https://github.com/dvcrn/ex_openai/pull/21

it’s already merged, just not released yet

dvcrn avatar May 22 '24 21:05 dvcrn

I saw that, but will that allow using multiple API providers at the same time from the same app?

I think that config should be moved from the Application env to be able to do that.

def MyOpenAICompatibleProviderOne do
  use ExOpenAI, base_url: "url-one..."
end

def MyOpenAICompatibleProviderTwo do
  use ExOpenAI, base_url: "url-two..."
end

This is closer to how I mean it.

From Elixir docs:

If you are writing a library to be used by other developers, it is generally recommended to avoid the application environment, as the application environment is effectively a global storage. For more information, read our library guidelines.

https://hexdocs.pm/elixir/1.16.3/Application.html

preciz avatar May 23 '24 09:05 preciz

It is possible to pass api key and org key into the calls itself, eg:

ExOpenAI.Models.list_models(openai_api_key: "abc", openai_organization_key: "def")

Would it solve your usecase if the env could be overwritten in a similar way?

dvcrn avatar May 30 '24 05:05 dvcrn

It would be one way to solve it now yes.

The better way would be similar to how multiple Repos in Ecto are configured.

preciz avatar May 30 '24 10:05 preciz

Solved in https://github.com/dvcrn/ex_openai/pull/29

preciz avatar Aug 30 '24 16:08 preciz