جواب «Remember a Message» چالش 2 از جلسهی 39
سؤال
remember(history, role, text) یک دیکشنری {"role": role, "content": text} به آخر history اضافه کند. خروجی test:3user | What is my name?{'role': 'user', 'content': 'Hi! My name is Kian.'}
راهنما
یک خط کافی است: history.append({"role": role, "content": text}).
یک جواب درست
def remember(history, role, text):
history.append({"role": role, "content": text})
# ---- test (do not change) ----
history = []
remember(history, "user", "Hi! My name is Kian.")
remember(history, "assistant", "Hello Kian!")
remember(history, "user", "What is my name?")
print(len(history))
print(history[-1]["role"], "|", history[-1]["content"])
print(history[0])
اول خودت امتحان کن؛ جوابهای دیگر هم قبول است. برگرد و خودت حلش کن