stop criteria
#30
by ismailhakki37 - opened
326 unmodified lines32732832933033133233333433533633733833934034134234334434534647 unmodified lines394395396397398399326 unmodified linesreturn {"error": f"Image processing failed: {str(e)}"}# Prepare conversation - reset for each request to avoid history issuestry:if hasattr(our_chatbot, 'conv_mode') and our_chatbot.conv_mode and LLAVA_AVAILABLE:our_chatbot.conversation = conv_templates[our_chatbot.conv_mode].copy()else:# Use default conversation templateour_chatbot.conversation = our_chatbot.conversation.__class__()except Exception as e:print(f"[DEBUG] Failed to reset conversation: {e}")# Continue with existing conversationinp = DEFAULT_IMAGE_TOKEN + "\n" + message_textour_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()# Tokenize inputinput_ids = tokenizer_image_token(47 unmodified linesresponse = our_chatbot.tokenizer.decode(outputs[0][input_ids.shape[1]:], skip_special_tokens=True)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]326 unmodified lines32732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636747 unmodified lines415416417418419420421422423424425426427428429430431432433434435436326 unmodified linesreturn {"error": f"Image processing failed: {str(e)}"}# Prepare conversation - reset for each request to avoid history issuesprint(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:# Create a completely new conversation instancefrom llava.conversation import conv_templates, SeparatorStyledefault_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 conversationour_chatbot.conversation.messages = []print(f"[DEBUG] Conversation reset using fallback method")except Exception as e:print(f"[DEBUG] Failed to reset conversation: {e}")# Emergency fallback: clear messagestry: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_textprint(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 inputinput_ids = tokenizer_image_token(47 unmodified linesresponse = our_chatbot.tokenizer.decode(outputs[0][input_ids.shape[1]:], skip_special_tokens=True)# Validate responseif not response or not response.strip():print(f"[DEBUG] Empty response detected, trying alternative decoding...")# Try decoding without skip_special_tokensresponse = 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 validraw_response = our_chatbot.tokenizer.decode(outputs[0], skip_special_tokens=True)print(f"[DEBUG] Raw response: {raw_response[:200]}...")# Extract only the new partresponse = 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