Refactor and add tests for OpenAI namespace

This commit is contained in:
Claudio Ortolina
2026-03-02 14:11:51 +00:00
parent 5bd85013c6
commit 99674eb8bc
7 changed files with 273 additions and 19 deletions
+32
View File
@@ -0,0 +1,32 @@
defmodule OpenAI.Config do
@type t :: %__MODULE__{
api_key: String.t(),
req_options: Keyword.t()
}
@enforce_keys [:api_key]
defstruct api_key: "",
req_options: []
@schema NimbleOptions.new!(
api_key: [
type: :string,
required: true
],
req_options: [
type: :keyword_list,
required: false,
default: []
]
)
@doc NimbleOptions.docs(@schema)
@spec resolve(Application.app()) :: t | no_return
def resolve(otp_app) do
app_config =
Application.get_env(otp_app, OpenAI)
|> NimbleOptions.validate!(@schema)
struct(__MODULE__, app_config)
end
end