make_llm#

scikitplot.corpus.make_llm(provider, model=None, *, client=None, max_tokens=None, options=None, cache=None, clock=None)[source]#

Make an LLM for OpenAI, Anthropic, Gemini or a callable.

Parameters:
provider{“openai”, “anthropic”, “gemini”} or callable

A provider name, or fn(prompt, system) -> str (or -> Completion).

modelstr or None, default=None

Model name, required for a named provider (no default: model names change). For a callable it is the name reported (default: the callable’s __name__).

clientobject or None, default=None

A client with the provider SDK’s surface (openai.OpenAI(...), anthropic.Anthropic(...), google.genai.Client(...), or a compatible object). None constructs the SDK’s default client, which reads the API key from the environment.

max_tokensint or None, default=None

Output-token limit for every request. Required for "anthropic".

optionsmapping or None, default=None

Further request arguments, sent unchanged: keyword arguments of chat.completions.create (OpenAI) or messages.create (Anthropic), fields of GenerateContentConfig (Gemini), for example {"temperature": 0} where the model accepts it. Must be JSON-compatible: they are part of the judge’s recorded identity.

cachemutable mapping or None, default=None

Response cache keyed by LLM.cache_key.

clockcallable or None, default=None

clock() -> float seconds for latency; time.perf_counter when None.

Returns:
LLM
Raises:
ValueError

For an unknown provider, a missing model or max_tokens, an option that the adapter sets itself, or a request argument that the client’s explicit signature does not take (openai before 1.45 has no max_completion_tokens).

TypeError

For arguments of the wrong type, or options that are not JSON-compatible.

ImportError

If client is None and the provider’s SDK is not installed.

Parameters:
Return type:

LLM

See also

LLMJudge

Judges answers with an LLM.

Notes

User note. For an OpenAI-compatible server (vLLM, a gateway), pass client=openai.OpenAI(base_url=..., api_key=...). If it does not know max_completion_tokens, leave max_tokens=None and pass options={"max_tokens": n}.

Examples

>>> llm = make_llm(lambda prompt, system: '{"score": 5}', model="stub")
>>> llm.complete("Rate this.").text
'{"score": 5}'
>>> llm.identity()
{'provider': 'callable', 'model': 'stub', 'options': {}}