Преглед на файлове

Fix: RateLimit requests were not released when a streaming generation exception occurred (#11540)

liuzhenghua преди 4 месеца
родител
ревизия
d05f189049
променени са 2 файла, в които са добавени 4 реда и са изтрити 1 реда
  1. 1 1
      api/core/app/features/rate_limiting/rate_limit.py
  2. 3 0
      api/services/app_generate_service.py

+ 1 - 1
api/core/app/features/rate_limiting/rate_limit.py

@@ -110,7 +110,7 @@ class RateLimitGenerator:
             raise StopIteration
         try:
             return next(self.generator)
-        except StopIteration:
+        except Exception:
             self.close()
             raise
 

+ 3 - 0
api/services/app_generate_service.py

@@ -108,6 +108,9 @@ class AppGenerateService:
                 raise ValueError(f"Invalid app mode {app_model.mode}")
         except RateLimitError as e:
             raise InvokeRateLimitError(str(e))
+        except Exception:
+            rate_limit.exit(request_id)
+            raise
         finally:
             if not streaming:
                 rate_limit.exit(request_id)