Explorar o código

fix: openai usage display issue

Timothy Jaeryang Baek hai 2 meses
pai
achega
7e2b2ec761
Modificáronse 1 ficheiros con 10 adicións e 0 borrados
  1. 10 0
      backend/open_webui/utils/middleware.py

+ 10 - 0
backend/open_webui/utils/middleware.py

@@ -1487,6 +1487,16 @@ async def process_chat_response(
                                 else:
                                     choices = data.get("choices", [])
                                     if not choices:
+                                        usage = data.get("usage", {})
+                                        if usage:
+                                            await event_emitter(
+                                                {
+                                                    "type": "chat:completion",
+                                                    "data": {
+                                                        "usage": usage,
+                                                    },
+                                                }
+                                            )
                                         continue
 
                                     delta = choices[0].get("delta", {})