stop criteria
#30
by ismailhakki37 - opened
326 unmodified lines32732832933033133233333433533433533633733833934034134234334434534634733834834935035135235335435535635735835936036136236336436536636747 unmodified lines415416417418419420421422423424425426427428429430431432433434435436326 unmodified lines return {"error": f"Image processing failed: {str(e)}"} # Prepare conversation - reset for each request to avoid history issues print(f"[DEBUG] Resetting conversation for new request...") try: if hasattr(our_chatbot, 'conv_mode') and our_chatbot.conv_mode and LLAVA_AVAILABLE: our_chatbot.conversation = conv_templates[our_chatbot.conv_mode].copy() print(f"[DEBUG] Conversation reset using conv_mode: {our_chatbot.conv_mode}") else: # Use default conversation template our_chatbot.conversation = our_chatbot.conversation.__class__() # Create a completely new conversation instance from llava.conversation import conv_templates, SeparatorStyle default_conv_mode = "llava_v1" if default_conv_mode in conv_templates: our_chatbot.conversation = conv_templates[default_conv_mode].copy() print(f"[DEBUG] Conversation reset using default conv_mode: {default_conv_mode}") else: # Fallback: create minimal conversation our_chatbot.conversation.messages = [] print(f"[DEBUG] Conversation reset using fallback method") except Exception as e: print(f"[DEBUG] Failed to reset conversation: {e}") # Continue with existing conversation # Emergency fallback: clear messages try: our_chatbot.conversation.messages = [] print(f"[DEBUG] Emergency conversation reset completed") except: print(f"[DEBUG] Emergency conversation reset failed") inp = DEFAULT_IMAGE_TOKEN + "\n" + message_text print(f"[DEBUG] Conversation roles: {our_chatbot.conversation.roles}") print(f"[DEBUG] Adding user message: {inp[:100]}...") our_chatbot.conversation.append_message(our_chatbot.conversation.roles[0], inp) our_chatbot.conversation.append_message(our_chatbot.conversation.roles[1], None) prompt = our_chatbot.conversation.get_prompt() print(f"[DEBUG] Generated prompt length: {len(prompt)}") print(f"[DEBUG] Prompt preview: {prompt[:200]}...") # Tokenize input input_ids = tokenizer_image_token(47 unmodified lines response = our_chatbot.tokenizer.decode(outputs[0][input_ids.shape[1]:], skip_special_tokens=True) # Validate response if not response or not response.strip(): print(f"[DEBUG] Empty response detected, trying alternative decoding...") # Try decoding without skip_special_tokens response = our_chatbot.tokenizer.decode(outputs[0][input_ids.shape[1]:], skip_special_tokens=False) if not response or not response.strip(): print(f"[DEBUG] Still empty response, checking raw outputs...") # Check if outputs are valid raw_response = our_chatbot.tokenizer.decode(outputs[0], skip_special_tokens=True) print(f"[DEBUG] Raw response: {raw_response[:200]}...") # Extract only the new part response = raw_response[len(our_chatbot.tokenizer.decode(input_ids[0], skip_special_tokens=True)):] response = response.strip() print(f"[DEBUG] Final response: {response[:100]}...") print(f"[DEBUG] Conversation messages length: {len(our_chatbot.conversation.messages)}") if len(our_chatbot.conversation.messages) > 0: last_message = our_chatbot.conversation.messages[-1]handler.py+40-3