Move API Key to configuration

This commit is contained in:
Claudio Ortolina
2024-12-10 16:50:37 +03:00
parent b68a7ac734
commit 44a8650c6c
2 changed files with 10 additions and 1 deletions
+4
View File
@@ -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")
+6 -1
View File
@@ -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