import datetime import json def get_answer(input, context, engine): answer = engine({"question": input, "context": context}) return answer["answer"] def get_context(): BIRTHYEAR = 1952 OTHERBIRTHYEAR = 1984 now = datetime.datetime.now() with open("context.json") as f: context = ( json.load(f)["info"] .replace("[YEAR]", str(now.year)) .replace("[BIRTHYEAR]", str(BIRTHYEAR)) .replace("[AGE]", str(now.year - BIRTHYEAR)) .replace("[OTHERAGE]", str(now.year - OTHERBIRTHYEAR)) ) return context