Avoid intermediate variables, and use consistent names
This commit is contained in:
+2
-6
@@ -7,16 +7,12 @@ defmodule Discogs do
|
|||||||
|
|
||||||
@spec get_artist(integer() | String.t()) :: {:ok, map()} | {:error, term()}
|
@spec get_artist(integer() | String.t()) :: {:ok, map()} | {:error, term()}
|
||||||
def get_artist(id) do
|
def get_artist(id) do
|
||||||
discogs_config = discogs_config()
|
API.get_artist(id, discogs_config())
|
||||||
|
|
||||||
API.get_artist(id, discogs_config)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec get_artist_image(String.t()) :: {:ok, binary()} | {:error, :cover_not_available}
|
@spec get_artist_image(String.t()) :: {:ok, binary()} | {:error, :cover_not_available}
|
||||||
def get_artist_image(url) do
|
def get_artist_image(url) do
|
||||||
discogs_config = discogs_config()
|
API.get_artist_image(url, discogs_config())
|
||||||
|
|
||||||
API.get_artist_image(url, discogs_config)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
defp discogs_config, do: Discogs.Config.resolve(:music_library)
|
defp discogs_config, do: Discogs.Config.resolve(:music_library)
|
||||||
|
|||||||
+4
-10
@@ -7,8 +7,7 @@ defmodule LastFm do
|
|||||||
|
|
||||||
@spec get_tracks(keyword()) :: {:ok, [Track.t()]} | {:error, term()}
|
@spec get_tracks(keyword()) :: {:ok, [Track.t()]} | {:error, term()}
|
||||||
def get_tracks(opts) do
|
def get_tracks(opts) do
|
||||||
last_fm_config = last_fm_config()
|
API.get_recent_tracks(opts, last_fm_config())
|
||||||
API.get_recent_tracks(opts, last_fm_config)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec get_artist_info(String.t(), String.t()) :: {:ok, LastFm.Artist.t()} | {:error, term()}
|
@spec get_artist_info(String.t(), String.t()) :: {:ok, LastFm.Artist.t()} | {:error, term()}
|
||||||
@@ -69,24 +68,19 @@ defmodule LastFm do
|
|||||||
|
|
||||||
@spec get_session(String.t()) :: {:ok, LastFm.Session.t()} | {:error, term()}
|
@spec get_session(String.t()) :: {:ok, LastFm.Session.t()} | {:error, term()}
|
||||||
def get_session(token) do
|
def get_session(token) do
|
||||||
last_fm_config = last_fm_config()
|
API.get_session(token, last_fm_config())
|
||||||
|
|
||||||
API.get_session(token, last_fm_config)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec scrobble([Scrobble.t()], String.t()) :: {:ok, map()} | {:error, term()}
|
@spec scrobble([Scrobble.t()], String.t()) :: {:ok, map()} | {:error, term()}
|
||||||
def scrobble(scrobbles, session_key) do
|
def scrobble(scrobbles, session_key) do
|
||||||
last_fm_config = last_fm_config()
|
|
||||||
|
|
||||||
scrobbles
|
scrobbles
|
||||||
|> Enum.map(&Scrobble.encode/1)
|
|> Enum.map(&Scrobble.encode/1)
|
||||||
|> API.scrobble(session_key, last_fm_config)
|
|> API.scrobble(session_key, last_fm_config())
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec get_profile(String.t()) :: {:ok, String.t()} | {:error, term()}
|
@spec get_profile(String.t()) :: {:ok, String.t()} | {:error, term()}
|
||||||
def get_profile(session_key) do
|
def get_profile(session_key) do
|
||||||
last_fm_config = last_fm_config()
|
API.get_user_info(session_key, last_fm_config())
|
||||||
API.get_user_info(session_key, last_fm_config)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec auth_url() :: String.t()
|
@spec auth_url() :: String.t()
|
||||||
|
|||||||
+4
-4
@@ -14,7 +14,7 @@ defmodule OpenAI do
|
|||||||
|
|
||||||
@spec gpt(OpenAI.Completion.t()) :: {:ok, map()} | {:error, term()}
|
@spec gpt(OpenAI.Completion.t()) :: {:ok, map()} | {:error, term()}
|
||||||
def gpt(completion) do
|
def gpt(completion) do
|
||||||
API.gpt(completion, config())
|
API.gpt(completion, open_ai_config())
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec chat_stream([map()], chat_stream_opts()) :: :ok | {:error, term()}
|
@spec chat_stream([map()], chat_stream_opts()) :: :ok | {:error, term()}
|
||||||
@@ -24,7 +24,7 @@ defmodule OpenAI do
|
|||||||
instructions = Keyword.get(opts, :instructions, "")
|
instructions = Keyword.get(opts, :instructions, "")
|
||||||
on_chunk = Keyword.fetch!(opts, :on_chunk)
|
on_chunk = Keyword.fetch!(opts, :on_chunk)
|
||||||
|
|
||||||
case API.chat_stream(messages, instructions, model, temperature, config(), on_chunk) do
|
case API.chat_stream(messages, instructions, model, temperature, open_ai_config(), on_chunk) do
|
||||||
:ok -> :ok
|
:ok -> :ok
|
||||||
{:error, _reason} = error -> error
|
{:error, _reason} = error -> error
|
||||||
end
|
end
|
||||||
@@ -32,8 +32,8 @@ defmodule OpenAI do
|
|||||||
|
|
||||||
@spec embeddings(String.t()) :: {:ok, [float()]} | {:error, term()}
|
@spec embeddings(String.t()) :: {:ok, [float()]} | {:error, term()}
|
||||||
def embeddings(text) do
|
def embeddings(text) do
|
||||||
API.get_embeddings(text, config())
|
API.get_embeddings(text, open_ai_config())
|
||||||
end
|
end
|
||||||
|
|
||||||
defp config, do: OpenAI.Config.resolve(:music_library)
|
defp open_ai_config, do: OpenAI.Config.resolve(:music_library)
|
||||||
end
|
end
|
||||||
|
|||||||
+5
-4
@@ -7,11 +7,12 @@ defmodule Wikipedia do
|
|||||||
|
|
||||||
@spec get_artist_summary(String.t()) :: {:ok, map()} | {:error, :no_english_wikipedia | term()}
|
@spec get_artist_summary(String.t()) :: {:ok, map()} | {:error, :no_english_wikipedia | term()}
|
||||||
def get_artist_summary(wikidata_id) do
|
def get_artist_summary(wikidata_id) do
|
||||||
config = wikipedia_config()
|
wikipedia_config = wikipedia_config()
|
||||||
|
|
||||||
with {:ok, title} when not is_nil(title) <- API.get_wikipedia_title(wikidata_id, config),
|
with {:ok, title} when not is_nil(title) <-
|
||||||
{:ok, summary} <- API.get_article_summary(title, config),
|
API.get_wikipedia_title(wikidata_id, wikipedia_config),
|
||||||
{:ok, intro_html} <- API.get_article_extract(title, config) do
|
{:ok, summary} <- API.get_article_summary(title, wikipedia_config),
|
||||||
|
{:ok, intro_html} <- API.get_article_extract(title, wikipedia_config) do
|
||||||
{:ok, Map.put(summary, "intro_html", intro_html)}
|
{:ok, Map.put(summary, "intro_html", intro_html)}
|
||||||
else
|
else
|
||||||
{:ok, nil} -> {:error, :no_english_wikipedia}
|
{:ok, nil} -> {:error, :no_english_wikipedia}
|
||||||
|
|||||||
Reference in New Issue
Block a user