Refactor and add tests for OpenAI namespace
This commit is contained in:
+4
-7
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user