stopping editet
#29
by ismailhakki37 - opened
346 unmodified lines34734834935035035135235335435535635735835635936036136236336436536636736836937037137237337437535 unmodified lines411412413414415416417418419235 unmodified lines655656657644658346 unmodified lines prompt, our_chatbot.tokenizer, IMAGE_TOKEN_INDEX, return_tensors="pt" ).unsqueeze(0).to(our_chatbot.model.device) # Set up stopping criteria # Set up stopping criteria - make it more flexible stop_str = ( our_chatbot.conversation.sep if our_chatbot.conversation.sep_style != SeparatorStyle.TWO else our_chatbot.conversation.sep2 ) print(f"[DEBUG] Original stop_str: {stop_str}") # Use more flexible stopping criteria to allow longer responses keywords = [stop_str] keywords = [stop_str] if stop_str else [] if not keywords: # If no separator, use common end tokens keywords = ["</s>", "<s>", "Human:", "Assistant:"] print(f"[DEBUG] Using keywords for stopping: {keywords}") stopping_criteria = KeywordsStoppingCriteria( keywords, our_chatbot.tokenizer, input_ids ) # Generate response print(f"[DEBUG] Generating with max_new_tokens: {max_output_tokens}") print(f"[DEBUG] Stopping criteria: {stop_str}") with torch.no_grad(): outputs = our_chatbot.model.generate( inputs=input_ids,35 unmodified lines our_chatbot.conversation.append_message(our_chatbot.conversation.roles[1], response) print(f"[DEBUG] Generated response length: {len(response)}") print(f"[DEBUG] Response word count: {len(response.split())}") print(f"[DEBUG] Response preview: {response[:100]}...") print(f"[DEBUG] Response ends with: {response[-50:] if len(response) > 50 else response}") except Exception as e: print(f"[DEBUG] Response decoding error: {str(e)}") return {"error": f"Response decoding failed: {str(e)}"}235 unmodified lines print("Handler module loaded successfully!") print("This handler is now ready for Hugging Face endpoints.") print("Use the 'query' function as the main endpoint.") print("Or use EndpointHandler class for Hugging Face compatibility.") print("Or use EndpointHandler class for Hugging Face compatibility.")handler.py+17-3