DetoxifySh (DetoxifySh v0.1.0)
Copy MarkdownThe Detoxify API: toxicity scores for any text, from one call.
client = DetoxifySh.new() # reads DETOXIFY_API_KEY
{:ok, %DetoxifySh.Result{scores: scores}} = DetoxifySh.analyze(client, "You are a wonderful person")Calls that may succeed when repeated (rate limits, a busy or briefly unavailable service, network failures) are retried, waiting as the API asks or backing off. A call the API served but whose answer was lost on the way back is charged again when retried.
Results are kept in memory by DetoxifySh.Cache, so analyzing the same text again neither
calls the API nor is charged. Errors are never kept.
Calls are synchronous: run them in a Task to do other work meanwhile.
Summary
Functions
Scores one piece of text. Returns {:ok, %DetoxifySh.Result{}}, or {:error, exception}
with one of the exceptions listed in DetoxifySh.Error.
Like analyze/2, but returns the result and raises the error.
Makes a client. Each option falls back to config :detoxify_sh, <option>: …, then to its
default
This client's version.
Functions
@spec analyze(DetoxifySh.Client.t(), String.t()) :: {:ok, DetoxifySh.Result.t()} | {:error, DetoxifySh.Error.t()}
Scores one piece of text. Returns {:ok, %DetoxifySh.Result{}}, or {:error, exception}
with one of the exceptions listed in DetoxifySh.Error.
@spec analyze!(DetoxifySh.Client.t(), String.t()) :: DetoxifySh.Result.t()
Like analyze/2, but returns the result and raises the error.
@spec new(keyword()) :: DetoxifySh.Client.t()
Makes a client. Each option falls back to config :detoxify_sh, <option>: …, then to its
default:
:api_key- your API key (dtx_…). Defaults to configuration, then theDETOXIFY_API_KEYenvironment variable.nilcalls without a key, with the small anonymous allowance.:base_url- defaults to"https://api.detoxify.sh".:timeout- how long one attempt may take to connect, and to wait for the answer, in milliseconds. Default 30,000.:max_retries- how many times to retry a call that may succeed if retried. Default 2.:cache-true(the default) keeps results in the cache the application starts; the name of aDetoxifySh.Cacheyou started keeps them there;falseornilkeeps none.:req_options- options passed toReq.request/1on every attempt, such asfinch: MyApp.Finchto use your own connection pool.
@spec version() :: String.t()
This client's version.