Wiki.LiftWing (mediawiki_client v0.4.9)

View Source

This module provides an adapter for the Lift Wing API for machine learning predictions.

See this page for a catalog of models, https://wikitech.wikimedia.org/wiki/Machine_Learning/LiftWing#Current_Inference_Services

The server currently rate-limits requests to 50,000 per hour per IP address.

Examples

Wiki.LiftWing.new()
|> Wiki.LiftWing.request(wiki: "enwiki", model: "articlequality", rev_id: 12345)
# {:ok, %{
#   "enwiki" => %{
#     "models" => %{"articlequality" => %{"version" => "0.9.2"}},
#     "scores" => %{
#       "12345" => %{
#         "articlequality" => %{
#           "score" => %{
#             "prediction" => "Stub",
#             "probability" => %{
#               "B" => 0.04109666150848109,
#               "C" => 0.02060738177009099,
#               "FA" => 0.0029400688910391592,
#               "GA" => 0.004970401857774162,
#               "Start" => 0.17362493306327959,
#               "Stub" => 0.7567605529093352
#             }
#           }
#         }
#       }
#     }
#   }
# }}

Bad requests

Wiki.LiftWing.new()
|> Wiki.LiftWing.request(wiki: "enwiki", model: "unknown", rev_id: 12345)
# {:error, %Wiki.Error{message: "Error received with HTTP status 404"}}

Wiki.LiftWing.new()
|> Wiki.LiftWing.request(wiki: "enwiki", model: "articlequality", rev_id: -1)
# {:error,
#  %Wiki.Error{
#    message: "The MW API does not have any info related to the rev-id provided as input (-1), therefore it is not possible to extract features properly. One possible cause is the deletion of the page related to the revision id. Please contact the ML-Team if you need more info."
#  }}

Summary

Types

  • :adapter - Override the HTTP adapter
  • :debug - Turn on verbose logging by setting to true
  • :endpoint - Override the base URL to query
  • :user_agent - Override the user-agent header string

Functions

Create a new Lift Wing client.

Make a Lift Wing request.

Assertive variant of request.

Types

client_option()

@type client_option() ::
  {:adapter, module()}
  | {:debug, true}
  | {:endpoint, binary()}
  | {:user_agent, binary()}

client_options()

@type client_options() :: [client_option()]
  • :adapter - Override the HTTP adapter
  • :debug - Turn on verbose logging by setting to true
  • :endpoint - Override the base URL to query
  • :user_agent - Override the user-agent header string

Functions

new(opts \\ [])

@spec new(client_options()) :: Tesla.Client.t()

Create a new Lift Wing client.

Arguments

  • opts - Configuration options that can change client behavior

Return value

Returns an opaque client object, which should be passed to request/2.

request(client, params)

@spec request(Tesla.Client.t(), keyword() | map()) :: {:ok, map()} | {:error, any()}

Make a Lift Wing request.

Arguments

  • client - Client object as returned by new/1.
  • params - Keyword list of query parameters,
    • :wiki - Wiki database name, eg. "enwiki"
    • :model - Model name, eg. "articlequality"
    • Remaining parameters are passed in the POST body, for example :rev_id

request!(client, params)

@spec request!(Tesla.Client.t(), keyword() | map()) :: map()

Assertive variant of request.