[UX] Add thinking support to `vllm chat` (#57045)

Misha Goin committed Sep 16, 2026 at 04:54 UTC 0384e72693985d0eddae70bd330b9cb283ff4313
1 file changed +19 -5
vllm/entrypoints/cli/openai.py
+19 -5
@@ -46,21 +46,35 @@ def _interactive_cli(args: argparse.Namespace) -> tuple[str, OpenAI]:
46
47
48 def _print_chat_stream(stream, stats: bool = False) -> str:
49 - output = ""
50 - start = time.perf_counter()
49 + output: str = ""
50 + in_reasoning: bool = False
51 + start: float = time.perf_counter()
52 ttft: float | None = None
52 - completion_tokens = 0
53 + completion_tokens: int = 0
54 for chunk in stream:
55 if chunk.usage is not None:
56 completion_tokens = chunk.usage.completion_tokens
57 if not chunk.choices:
58 continue
59 delta = chunk.choices[0].delta
60 + reasoning = getattr(delta, "reasoning", None) or getattr(
61 + delta, "reasoning_content", None
62 + )
63 + if ttft is None and (reasoning or delta.content):
64 + ttft = time.perf_counter() - start
65 + if reasoning:
66 + if not in_reasoning:
67 + print("<think>", flush=True)
68 + in_reasoning = True
69 + print(reasoning, end="", flush=True)
70 if delta.content:
60 - if ttft is None:
61 - ttft = time.perf_counter() - start
71 + if in_reasoning:
72 + print("\n</think>", flush=True)
73 + in_reasoning = False
74 output += delta.content
75 print(delta.content, end="", flush=True)
76 + if in_reasoning:
77 + print("\n</think>", end="", flush=True)
78 print()
79 if stats:
80 _print_metrics(start, ttft, completion_tokens)