Async generation interface Args: prompt: Input prompt sampling_params: Sampling parameters. If `sampling_params.n > 1`, will generate `n` completions sequentially. request_id: Request ID **kwargs: Other parameters
(
self,
prompt: Union[str, List[str], Dict[str, Any]],
sampling_params: Optional[SamplingParams] = None,
request_id: Optional[str] = None,
**kwargs,
)
| 453 | raise EngineError(f"async_llm add request failed: {e}", error_code=400) |
| 454 | |
| 455 | async def generate( |
| 456 | self, |
| 457 | prompt: Union[str, List[str], Dict[str, Any]], |
| 458 | sampling_params: Optional[SamplingParams] = None, |
| 459 | request_id: Optional[str] = None, |
| 460 | **kwargs, |
| 461 | ) -> AsyncGenerator[RequestOutput, None]: |
| 462 | """ |
| 463 | Async generation interface |
| 464 | |
| 465 | Args: |
| 466 | prompt: Input prompt |
| 467 | sampling_params: Sampling parameters. If `sampling_params.n > 1`, |
| 468 | will generate `n` completions sequentially. |
| 469 | request_id: Request ID |
| 470 | **kwargs: Other parameters |
| 471 | |
| 472 | Yields: |
| 473 | RequestOutput: Generated output |
| 474 | """ |
| 475 | |
| 476 | num_choices = sampling_params.n if sampling_params is not None and sampling_params.n else 1 |
| 477 | stream = True |
| 478 | include_stop_str_in_output = False |
| 479 | enable_thinking = kwargs.pop("enable_thinking", False) |
| 480 | |
| 481 | if isinstance(prompt, dict): |
| 482 | num_choices = prompt.get("n") |
| 483 | stream = prompt.get("stream", True) |
| 484 | include_stop_str_in_output = prompt.get("include_stop_str_in_output", False) |
| 485 | |
| 486 | # Ensure ZMQ client and connection manager are initialized in current process |
| 487 | if ( |
| 488 | self.request_client is None |
| 489 | or self.connection_manager is None |
| 490 | or not getattr(self.connection_manager, "running", False) |
| 491 | ): |
| 492 | raise EngineError( |
| 493 | "AsyncLLM engine not initialized. Call init_connections() before generate.", |
| 494 | error_code=500, |
| 495 | ) |
| 496 | |
| 497 | # Build request ids and connection key |
| 498 | if num_choices <= 1: |
| 499 | # Single-choice: keep user-provided request_id semantics |
| 500 | child_request_ids = [request_id or str(uuid.uuid4())] |
| 501 | conn_request_id = child_request_ids[0] |
| 502 | else: |
| 503 | # Multi-choice: use unified "cmpl-" base id so DealerConnectionManager |
| 504 | # can merge cmpl-xxx_0, cmpl-xxx_1, ... back to the same response queue. |
| 505 | user_request_id = request_id or str(uuid.uuid4()) |
| 506 | conn_request_id = f"cmpl-{user_request_id}" |
| 507 | child_request_ids = [f"{conn_request_id}_{i}" for i in range(num_choices)] |
| 508 | |
| 509 | try: |
| 510 | # 1) Send all sub-requests to engine |
| 511 | for child_request_id in child_request_ids: |
| 512 | await self.add_request(child_request_id, prompt, sampling_params, **kwargs) |
nothing calls this directly
no test coverage detected