diff --git a/config/runtime.exs b/config/runtime.exs index 8414fca1..b1a87853 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -28,6 +28,10 @@ if user = System.get_env("LAST_FM_USER") do config :music_library, LastFm, user: user end +if openai_key = System.get_env("OPENAI_KEY") do + config :music_library, OpenAI, api_key: openai_key +end + config :music_library, MusicLibrary.Repo, load_extensions: [ MusicLibrary.Repo.extension_path("unicode") diff --git a/lib/open_ai.ex b/lib/open_ai.ex index 5aac8e2c..496a1139 100644 --- a/lib/open_ai.ex +++ b/lib/open_ai.ex @@ -53,7 +53,7 @@ defmodule OpenAI do stream: true, temperature: 0.2 }, - auth: {:bearer, System.fetch_env!("OPENAI_KEY")}, + auth: {:bearer, api_key()}, finch_request: fun ) end @@ -61,4 +61,9 @@ defmodule OpenAI do defp decode_body("", _), do: :ok defp decode_body("[DONE]", _), do: :ok defp decode_body(json, cb), do: cb.(Jason.decode!(json)) + + defp api_key do + Application.get_env(:music_library, OpenAI) + |> Keyword.fetch!(:api_key) + end end