make_llm#
- scikitplot.corpus.make_llm(provider, model=None, *, client=None, max_tokens=None, options=None, cache=None, clock=None)[source]#
Make an
LLMfor 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).Noneconstructs 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) ormessages.create(Anthropic), fields ofGenerateContentConfig(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() -> floatseconds for latency;time.perf_counterwhenNone.
- 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 (openaibefore 1.45 has nomax_completion_tokens).- TypeError
For arguments of the wrong type, or options that are not JSON-compatible.
- ImportError
If
clientisNoneand the provider’s SDK is not installed.
- Parameters:
- Return type:
Notes
User note. For an OpenAI-compatible server (vLLM, a gateway), pass
client=openai.OpenAI(base_url=..., api_key=...). If it does not knowmax_completion_tokens, leavemax_tokens=Noneand passoptions={"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': {}}