mellea.helpers.server_type
Utilities for detecting and classifying the target inference server.
Defines the _ServerType enum (LOCALHOST, OPENAI, REMOTE_VLLM,
UNKNOWN) and _server_type, which classifies a URL by hostname. Also provides
is_vllm_server_with_structured_output, which probes a server's /version
endpoint to determine whether it supports the structured_outputs parameter
introduced in vLLM ≥ 0.12.0. Used by the OpenAI-compatible backend to choose between
guided_json and structured_outputs request formats. vllm_server_version and
vllm_tokenize_single_tokens support one-token decision readouts, which ask a vLLM
server for the logprobs of exact token ids (logprob_token_ids).
Functions
FUNC is_vllm_server_with_structured_output
is_vllm_server_with_structured_output(base_url: str, headers: Mapping[str, Any]) -> bool
Attempts to determine if the backend is a vllm server with version >= v0.12.0. Defaults to false.
v0.12.0 was the last version to support guided_json params. It's now under structured_outputs.
Args:
base_url: Base url for LLM API.headers: Additional headers to pass to the request.
Returns:
- True if the server is vLLM >= v0.12.0, False otherwise.
FUNC vllm_server_version
vllm_server_version(base_url: str, headers: Mapping[str, Any]) -> Version | None
Return a vLLM server's version from its /version endpoint, or None.
Applies the same link-local and no-redirect guards as
is_vllm_server_with_structured_output.
Args:
base_url: Base url for LLM API.headers: Additional headers to pass to the request.
Returns:
- The parsed version, or None when the server is not vLLM, does not
- answer, or reports an unparsable version.
FUNC vllm_tokenize_single_tokens
vllm_tokenize_single_tokens(base_url: str, headers: Mapping[str, Any], model: str, texts: list[str]) -> list[int]
Token ids of texts that each encode to exactly one token, via a vLLM server.
Calls the server's /tokenize endpoint (a sibling of /v1, not under it)
without special tokens, so the ids match what the server will score.
Args:
base_url: Base url for LLM API.headers: Additional headers to pass to the request.model: Served model name, as the server knows it.texts: Strings that must each be a single token (for example decision labels).
Returns:
- One token id per text, in order.
Raises:
ValueError: If the base URL is link-local, the server rejects the request or answers in an unexpected shape, or a text does not encode to exactly one token.