jack преди 1 месец
родител
ревизия
e28985362f
променени са 1 файла, в които са добавени 6 реда и са изтрити 3 реда
  1. 6 3
      app/core/runner/llm_callback_handler.py

+ 6 - 3
app/core/runner/llm_callback_handler.py

@@ -46,6 +46,9 @@ class LLMCallbackHandler:
                 logging.debug(chunk)
 
                 if not chunk.choices:
+                    if chunk.usage:
+                        self.event_handler.pub_message_usage(chunk)
+                        continue
                     continue
 
                 choice = chunk.choices[0]
@@ -53,6 +56,9 @@ class LLMCallbackHandler:
                 delta = choice.delta
                 logging.debug(delta)
                 if not delta:
+                    if chunk.usage:
+                        self.event_handler.pub_message_usage(chunk)
+                        continue
                     continue
                 logging.debug(
                     "delta.tool_callstool_callstool_callstool_callstool_callstool_callstool_callstool_callstool_callstool_calls"
@@ -89,9 +95,6 @@ class LLMCallbackHandler:
                     self.event_handler.pub_message_delta(
                         self.message.id, index, delta.content, delta.role
                     )
-                if chunk.usage:
-                    self.event_handler.pub_message_usage(chunk)
-                    continue
         except Exception as e:
             logging.error("handle_llm_response error: %s", e)
             raise e