DetoxifySh (DetoxifySh v0.1.0)

Copy Markdown

The 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

analyze(client, text)

@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.

analyze!(client, text)

Like analyze/2, but returns the result and raises the error.

new(options \\ [])

@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 the DETOXIFY_API_KEY environment variable. nil calls 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 a DetoxifySh.Cache you started keeps them there; false or nil keeps none.
  • :req_options - options passed to Req.request/1 on every attempt, such as finch: MyApp.Finch to use your own connection pool.

version()

@spec version() :: String.t()

This client's version.