Download lib/perplexity_macro/adapters/dictionary.ex from Snapkitty/perplexity-macro-vm: direct link, hf CLI and curl.
- Browser
- Download file 783 Bytes
-
https://huggingface.co/Snapkitty/perplexity-macro-vm/resolve/main/lib/perplexity_macro/adapters/dictionary.ex
- Command line
-
hf download hf://Snapkitty/perplexity-macro-vm/lib/perplexity_macro/adapters/dictionary.ex
-
curl -L -o dictionary.ex https://huggingface.co/Snapkitty/perplexity-macro-vm/resolve/main/lib/perplexity_macro/adapters/dictionary.ex
783 Bytes
| defmodule PerplexityMacro.Adapters.Dictionary do | |
| @moduledoc "Dictionary research via dictionaryapi.dev + WordNet fallback." | |
| def run(word, _opts \\ []) do | |
| url = "https://api.dictionaryapi.dev/api/v2/entries/en/#{URI.encode(word)}" | |
| case Req.get(url) do | |
| {:ok, %{status: 200, body: body}} when is_list(body) -> | |
| content = body |> List.first() |> get_in(["meanings"]) |> inspect() |> String.slice(0,3000) | |
| {:ok, [%{title: "Dictionary: #{word}", url: url, content: content, score: 1.0, source_hash: :erlang.phash2(word,0xFFFFFFFF)}]} | |
| _ -> | |
| {:ok, [%{title: "Dictionary (WordNet fallback): #{word}", url: "wordnet://#{word}", content: "WordNet: #{word}", score: 0.5, source_hash: :erlang.phash2(word,0xFFFFFFFF)}]} | |
| end | |
| end | |
| end | |