Skip to content

API Reference parrot.clients.vllm.client

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.clients.vllm.client

View source

vLLM client for AI-Parrot.

Extends LocalLLMClient to support vLLM-specific features including guided output (JSON schema, regex, choices), LoRA adapters, extended sampling parameters, and batch processing.

Alias AIMessage

Re-exported from parrot.models.responses.AIMessage.

Alias LocalLLMClient

Re-exported from parrot.clients.local.LocalLLMClient.

Alias LocalLLMModel

Re-exported from parrot.clients.local.models.LocalLLMModel.

Alias VLLMServerInfo

Re-exported from parrot.clients.vllm.models.VLLMServerInfo.

Attribute logger

Alias pydantic_to_guided_json

Re-exported from parrot.clients.vllm.models.pydantic_to_guided_json.

Class vLLMClient

vLLM client with vLLM-specific features.

Extends LocalLLMClient to add:

  • Guided output (JSON schema, regex, choices)
  • LoRA adapter support per request
  • Extended sampling parameters (top_k, min_p, repetition_penalty)
  • Health check and server info endpoints
  • Batch processing for high throughput
Parameter Type Default Description
base_url Optional[str] None vLLM server URL. Defaults to VLLM_BASE_URL env or "http://localhost:8000/v1".
api_key Optional[str] None Optional API key. Defaults to VLLM_API_KEY env.
timeout int 120 Request timeout in seconds (default 120).
**kwargs {} Additional arguments passed to LocalLLMClient.

Attributes:

Attribute Type Description
client_type str
client_name str
provider_keys tuple[str, ...]
models type[Enum]

Method vLLMClient.ask

Send a prompt to vLLM with optional guided output and LoRA support.

ask(prompt: str, model: Optional[Union[str, Enum]] = None, temperature: float = 0.7, max_tokens: Optional[int] = None, guided_json: Optional[Dict[str, Any]] = None, guided_regex: Optional[str] = None, guided_choice: Optional[List[str]] = None, guided_grammar: Optional[str] = None, structured_output: Optional[Type[BaseModel]] = None, lora_adapter: Optional[str] = None, top_k: int = -1, min_p: float = 0.0, repetition_penalty: float = 1.0, length_penalty: float = 1.0, **kwargs) -> AIMessage

Parameter Type Default Description
prompt str The prompt to send to the model.
model Optional[Union[str, Enum]] None Model identifier. Defaults to client's configured model.
temperature float 0.7 Sampling temperature (0.0 to 2.0).
max_tokens Optional[int] None Maximum tokens to generate.
guided_json Optional[Dict[str, Any]] None JSON schema for constrained generation.
guided_regex Optional[str] None Regex pattern for constrained generation.
guided_choice Optional[List[str]] None List of valid output choices.
guided_grammar Optional[str] None BNF grammar for constrained generation.
structured_output Optional[Type[BaseModel]] None Pydantic model class to convert to guided_json.
lora_adapter Optional[str] None Name of LoRA adapter to use for this request.
top_k int -1 Top-k sampling (-1 to disable).
min_p float 0.0 Minimum probability threshold (0.0 to 1.0).
repetition_penalty float 1.0 Repetition penalty (>1.0 discourages).
length_penalty float 1.0 Length penalty for beam search.
**kwargs {} Additional arguments passed to parent ask().

Returns: AIMessage — AIMessage with the model's response.

Raises:

  • ValueError — If multiple guided constraints are specified.
  • ConnectionError — If the server is unreachable.
  • TimeoutError — If the request exceeds timeout.

Method vLLMClient.ask_stream

Stream response from vLLM with optional guided output and LoRA support.

ask_stream(prompt: str, model: Optional[Union[str, Enum]] = None, temperature: float = 0.7, max_tokens: Optional[int] = None, guided_json: Optional[Dict[str, Any]] = None, guided_regex: Optional[str] = None, guided_choice: Optional[List[str]] = None, guided_grammar: Optional[str] = None, structured_output: Optional[Type[BaseModel]] = None, lora_adapter: Optional[str] = None, top_k: int = -1, min_p: float = 0.0, repetition_penalty: float = 1.0, length_penalty: float = 1.0, **kwargs) -> AsyncGenerator[str, None]

Parameter Type Default Description
prompt str The prompt to send to the model.
model Optional[Union[str, Enum]] None Model identifier. Defaults to client's configured model.
temperature float 0.7 Sampling temperature (0.0 to 2.0).
max_tokens Optional[int] None Maximum tokens to generate.
guided_json Optional[Dict[str, Any]] None JSON schema for constrained generation.
guided_regex Optional[str] None Regex pattern for constrained generation.
guided_choice Optional[List[str]] None List of valid output choices.
guided_grammar Optional[str] None BNF grammar for constrained generation.
structured_output Optional[Type[BaseModel]] None Pydantic model class to convert to guided_json.
lora_adapter Optional[str] None Name of LoRA adapter to use for this request.
top_k int -1 Top-k sampling (-1 to disable).
min_p float 0.0 Minimum probability threshold (0.0 to 1.0).
repetition_penalty float 1.0 Repetition penalty (>1.0 discourages).
length_penalty float 1.0 Length penalty for beam search.
**kwargs {} Additional arguments passed to parent ask_stream().

Returns: AsyncGenerator[str, None]

Raises:

  • ValueError — If multiple guided constraints are specified.
  • ConnectionError — If the server is unreachable.
  • TimeoutError — If the request exceeds timeout.

Method vLLMClient.health_check

Check vLLM server health via /health endpoint.

vLLM exposes a /health endpoint that returns 200 when the server is ready to accept requests.

health_check() -> bool

Returns: bool — True if the server is healthy, False otherwise.

Method vLLMClient.server_info

Get vLLM server version and configuration.

Queries the /version endpoint for server metadata.

server_info() -> VLLMServerInfo

Returns: VLLMServerInfo — VLLMServerInfo with server version and configuration.

Raises:

  • ConnectionError — If the server is unreachable or returns an error.

Method vLLMClient.list_models

List available models on the vLLM server.

Queries the /v1/models endpoint via the OpenAI SDK.

list_models() -> List[str]

Returns: List[str] — List of model ID strings available on the server.

Raises:

  • ConnectionError — If the server is unreachable.

Method vLLMClient.batch_process

Process multiple requests concurrently for optimal throughput.

vLLM excels at batching requests, and this method leverages asyncio.gather to send multiple requests in parallel.

batch_process(requests: List[Dict[str, Any]], **kwargs) -> List[AIMessage]

Parameter Type Default Description
requests List[Dict[str, Any]] List of request dicts, each containing: - prompt (str): Required prompt text - model (str, optional): Model identifier - temperature (float, optional): Sampling temperature - max_tokens (int, optional): Max tokens to generate - guided_json (dict, optional): JSON schema constraint - guided_regex (str, optional): Regex constraint - guided_choice (list, optional): Choice constraint - lora_adapter (str, optional): LoRA adapter name - Plus any other parameters accepted by ask()
**kwargs {} Default parameters applied to all requests.

Returns: List[AIMessage] — List of AIMessage responses in the same order as requests.

Raises:

  • ValueError — If requests list is empty.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally