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
+4 -7
View File
@@ -2,7 +2,7 @@ defmodule OpenAI do
alias OpenAI.API
def gpt(completion) do
API.gpt(completion, api_key())
API.gpt(completion, config())
end
def chat_stream(messages, opts \\ []) when is_list(messages) do
@@ -11,18 +11,15 @@ defmodule OpenAI do
instructions = Keyword.get(opts, :instructions, "")
on_chunk = Keyword.fetch!(opts, :on_chunk)
case API.chat_stream(messages, instructions, model, temperature, api_key(), on_chunk) do
case API.chat_stream(messages, instructions, model, temperature, config(), on_chunk) do
:ok -> :ok
{:error, _reason} = error -> error
end
end
def embeddings(text) do
API.get_embeddings(text, api_key())
API.get_embeddings(text, config())
end
defp api_key do
Application.get_env(:music_library, __MODULE__)
|> Keyword.fetch!(:api_key)
end
defp config, do: OpenAI.Config.resolve(:music_library)
end