Fix model_worker error
diff --git a/fastchat/serve/inference.py b/fastchat/serve/inference.py
index c97fd1c017..4e51916101 100644
--- a/fastchat/serve/inference.py
+++ b/fastchat/serve/inference.py
@@ -108,6 +108,7 @@ def generate_stream(
 
     past_key_values = out = None
     sent_interrupt = False
+    finish_reason = None
     for i in range(max_new_tokens):
         if i == 0:  # prefill
             if model.config.is_encoder_decoder:
@@ -240,12 +241,11 @@ def generate_stream(
             break
 
     # Finish stream event, which contains finish reason
-    if i == max_new_tokens - 1:
+    else:
         finish_reason = "length"
-    elif stopped:
+
+    if stopped:
         finish_reason = "stop"
-    else:
-        finish_reason = None
 
     yield {
         "text": output,

<!-- Thank you for your contribution! -->

<!-- Please add a reviewer to the assignee section when you create a PR. If you don't have the access to it, we will shortly find a reviewer and assign them to your PR. -->

## Why are these changes needed?

Fix the bug that `model_worker` will raise the error `local variable 'i' referenced before assignment` in some case.

## Related issue number (if applicable)

<!-- For example: "Closes #1234" -->
Closes #2382
## Checks

- [] I've run `format.sh` to lint the changes in this PR.
- [x] I've included any doc changes needed.
- [ ] I've made sure the relevant tests are passing (if applicable).
