ysharma HF Staff commited on
Commit
8648d06
·
verified ·
1 Parent(s): ffeaa56

Update chat_handler.py

Browse files
Files changed (1) hide show
  1. chat_handler.py +19 -6
chat_handler.py CHANGED
@@ -335,12 +335,25 @@ class ChatHandler:
335
  }
336
  ))
337
 
338
- # Add clean media display only if we extracted a valid URL and it's different from raw result
339
- if media_url and media_url not in result_text:
340
- chat_messages.append(ChatMessage(
341
- role="assistant",
342
- content={"path": media_url}
343
- ))
 
 
 
 
 
 
 
 
 
 
 
 
 
344
 
345
  else:
346
  # Add error message for failed tool call
 
335
  }
336
  ))
337
 
338
+ # Only add separate media display if:
339
+ # 1. We extracted a valid URL
340
+ # 2. The result text is NOT just a URL (to avoid double rendering)
341
+ # 3. The result text doesn't contain the exact URL
342
+ if media_url:
343
+ # Check if the result is essentially just the URL (with possible whitespace)
344
+ cleaned_result = result_text.strip()
345
+ is_just_url = (cleaned_result == media_url or
346
+ cleaned_result.startswith('http') and len(cleaned_result.split()) == 1)
347
+
348
+ # Only add separate media if the result is more than just the URL
349
+ if not is_just_url and media_url not in result_text:
350
+ logger.info(f"🎯 Adding separate media display for: {media_url}")
351
+ chat_messages.append(ChatMessage(
352
+ role="assistant",
353
+ content={"path": media_url}
354
+ ))
355
+ else:
356
+ logger.info(f"🚫 Skipping separate media - result is just URL: {is_just_url}, contains URL: {media_url in result_text}")
357
 
358
  else:
359
  # Add error message for failed tool call