dvcrn / ex_openai

Auto-generated Elixir SDK for OpenAI APIs with full typespecs, docs and streaming support
MIT License
71 stars 27 forks source link

Using ex_openai with other OpenAI compatible API providers #24

Open preciz opened 1 month ago

preciz commented 1 month ago

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?

dvcrn commented 1 month ago

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

it’s already merged, just not released yet

preciz commented 1 month ago

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

dvcrn commented 1 month ago

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?

preciz commented 1 month ago

It would be one way to solve it now yes.

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