fix(cli/serve): import serve handlers lazily so the CLI works without the `serve` extra
Author: Anai-Guo
Pull request: yes

### What this fixes

Fixes the `transformers` CLI crashing with `NameError` when the optional `serve` extra (which provides `openai`) is **not** installed.

Importing **any** CLI command triggers this chain:

```
transformers <cmd>
 └─ cli/transformers.py  ->  from transformers.cli.serve import Serve
     └─ serve.py          ->  from .serving.utils import set_torch_seed   # triggers serving/__init__
         └─ serving/__init__.py -> from .server import build_server
             └─ server.py -> from .chat_completion import ChatCompletionHandler   # unconditional
                 └─ chat_completion.py:
                       class TransformersCompletionCreateParamsStreaming(CompletionCreateParamsStreaming, ...):
```

`CompletionCreateParamsStreaming` (and the other `openai.types` symbols) are only imported inside `if is_serve_available():`, but the handler classes reference them at **class-definition time**. With the `serve` extra absent, `is_serve_available()` is `False`, the symbol is never imported, and the module raises:

```
NameError: name 'CompletionCreateParamsStreaming' is not defined
```

Because `server.py` imports the four handler modules **unconditionally** (only the `fastapi` imports were guarded), the whole CLI becomes unusable without `serve` deps — e.g. `transformers env`, as reported in #46468.

### The fix

In `cli/serving/server.py`:

1. Add `from __future__ import annotations` so `build_server`'s parameter/return annotations (`ChatCompletionHandler`, `FastAPI`, …) are not evaluated at definition time.
2. Move the four serve-only handler imports (`chat_completion`, `completion`, `response`, `transcription`) into the existing `if is_serve_available():` guard, next to the `fastapi` imports. `ModelManager` and `.utils` stay unconditional — they have no serve-only dependencies.

This is sufficient and minimal:

- `build_server` only uses the handlers in **annotations**, never as values in its body, so the guarded imports aren't needed at import time.
- `serve.py` already imports the handler classes itself (lazily, inside the run path) when it actually starts a server, so guarding them in `server.py` does not affect serving.
- `tests/cli/test_serve.py` imports only `build_server` from this module (and is gated with `@require_serve`), so it is unaffected.

### Verification

With the `serve` extra absent (`is_serve_available()` is `False`):
- **Before:** `python -c "import transformers.cli.serving.server"` → `NameError: name 'CompletionCreateParamsStreaming' is not defined`
- **After:** imports cleanly; `transformers env` / `version` / `download` work again.

With the extra present, serving behaviour is unchanged.

Note: the `TypeError` in the issue's main traceback originates in the model's remote `modeling_nemotron_h.py` (`trust_remote_code`), which is outside this repo; this PR addresses the `transformers env` `NameError` regression reported in the same issue.

🤖 Generated with [Claude Code](https://claude.com/claude-code)


Comments:
cc @lysandrejik for `serve`/CLI final approval but the fix LGTM

@Rocketknight1 you can request reviews from @SunMarc or @remi-or for serve reviews as well as me, thanks!

Also, unfortunately, this would introduce the same error as this PR: https://github.com/huggingface/transformers/pull/44256#issuecomment-4044557118

Namely, annotations imported from future do not play well with fastapi and result in everything being 422 unprocessable entity: https://github.com/huggingface/transformers/pull/44620

Sorry, will ping the others in future!

The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_46473). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

a6f5f5c9f0f69d31e46e46c2825e7f6ff86c3b18