mgallo / openai.ex

community-maintained OpenAI API Wrapper written in Elixir.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Library doesn't seem to load default config with Phoenix

johns10 opened this issue · comments

I am adding this library to my Phoenix Application.

In my runtime, I've added

case System.get_env("OPENAI_API_KEY") do
  nil -> nil
  key -> config :openai, api_key: key
end

I've validated this populates my api key with OpenAI.Config.api_key(). However, when I call OpenAI.audio_transcription(path, %{model: "whisper-1"}) I get back an error that I haven't populated my API key. From my read of the code, I don't know how this library would ever pick up these defaults. It just calls up an empty %Config{} struct.

Unless there's some magic in here where calling this empty struct picks up defaults from the GenServer state. That said, I've validated the genserver is running in my Phoenix application, and calling %OpenAI.Config{} just returns and empty struct:

%OpenAI.Config{
  api_key: nil,
  organization_key: nil,
  http_options: nil,
  api_url: nil
}

Just to be thorough, I also added the configs to my config.exs as well, in case they needed to be available at compile time. I still have the same issue.

Nope, I'm wrong.