Browse Source

fix: correct FINISH_REASON_TOOL_USE check (was 2, should be 3)

The proto enum has FINISH_REASON_TOOL_USE = 3, not 2. This was
preventing tool calls from being processed even when the LLM sent them.

Also added debug logging for tool call detection.
fszontagh 7 tháng trước cách đây
mục cha
commit
af0c9de6c2
1 tập tin đã thay đổi với 10 bổ sung và 3 xóa
  1. 10 3
      webui/src/contexts/ChatContext.tsx

+ 10 - 3
webui/src/contexts/ChatContext.tsx

@@ -426,7 +426,8 @@ export function ChatProvider({ children }: ChatProviderProps) {
                 const finishReason = typeof chunk.finish_reason === 'string'
                   ? parseInt(chunk.finish_reason, 10)
                   : chunk.finish_reason
-                if (finishReason === 2 && newToolCalls.length > 0) {
+                // finish_reason 3 = FINISH_REASON_TOOL_USE per proto enum
+                if (finishReason === 3 && newToolCalls.length > 0) {
                   hasMoreToolCalls = true
                 }
               }
@@ -498,6 +499,7 @@ export function ChatProvider({ children }: ChatProviderProps) {
           }
           // Collect tool calls
           if (chunk.tool_call) {
+            console.log('[Chat] Tool call received:', chunk.tool_call)
             collectedToolCalls.push(chunk.tool_call)
           }
           if (chunk.finish_reason) {
@@ -505,9 +507,14 @@ export function ChatProvider({ children }: ChatProviderProps) {
             finishReasonValue = typeof chunk.finish_reason === 'string'
               ? parseInt(chunk.finish_reason, 10)
               : chunk.finish_reason
-            // Check if tool use is needed (finish_reason 2 = FINISH_REASON_TOOL_USE)
-            if (finishReasonValue === 2 && collectedToolCalls.length > 0) {
+            console.log('[Chat] Stream finished:', {
+              finishReason: finishReasonValue,
+              toolCallsCollected: collectedToolCalls.length
+            })
+            // Check if tool use is needed (finish_reason 3 = FINISH_REASON_TOOL_USE per proto enum)
+            if (finishReasonValue === 3 && collectedToolCalls.length > 0) {
               needsToolProcessing = true
+              console.log('[Chat] Tool processing needed, collected tool calls:', collectedToolCalls)
             }
           }
         },