jack 1 tháng trước cách đây
mục cha
commit
e28985362f

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

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