Telegram电影推荐机器人响应异常求助:所有输入均返回错误提示
Telegram电影推荐机器人故障排查与修复
你的机器人所有输入都返回默认回复的问题,根源在handle_response函数的匹配逻辑:
你将用户输入转为全小写:
processed: str = text.lower()
但判断条件里用的是首字母大写的关键词(比如'Comedy'),全小写的字符串里不可能包含大写的关键词,导致所有匹配都失败。
修复后的handle_response函数
def handle_response(text: str): processed: str = text.lower() if 'comedy' in processed: return 'Super choice! Here are top 5 films: "Blazing Saddles"; "Airplane!"; "Monty Python and the Holy Grail"; "Animal House"; "Young Frankenstein"' if 'horror' in processed: return 'Wow! Love watching horrors? Here are some of Horror Movies from my collection: The Exorcist (1973); Halloween (1978); Paranormal Activity (2007); The Shining (1980); It Follows (2014)' if 'drama' in processed: return 'Nice choice! Here are some of Drama films I have: Citizen Kane (1941); The Godfather (1972); 12 Angry Men (1957); Casablanca (1942); Tokyo Story (1953)' return 'I did not understand...'
额外修正
顺便修正了喜剧列表里重复的《Monty Python and the Holy Grail》条目,让推荐列表符合Top5的预期。
内容的提问来源于stack exchange,提问作者Aaron Sukhanov
相关产品推荐
相关产品推荐

