def respond(message, history, max_tokens, temperature, top_p): """Generate a response while preventing unnecessary repetition.""" # Ensure the message isn't directly repeated if history and message.strip() == history[-1][0].strip(): return "Tafadhali uliza swali tofauti." # Prevent direct repetition response = client.text_generation( message.strip(), max_new_tokens=max_tokens, temperature=temperature, top_p=top_p, ).strip() # Remove repeated input if response.lower() == message.lower(): response = "Samahani, naweza kusaidia vipi?" return response