マルチターンの会話
旅行用チャットボットを拡張し、モデルの最初のおすすめに対してユーザーが返答できるようにしましょう。今回も Conversation クラスを使いますが、モデルに繰り返し呼び出しを行い、モデルが過去の情報をどのように扱うかを確認します。
参考として、Conversation クラスのメソッドを再掲します。
__init__(self, llm: Llama, system_prompt='', history=[])create_completion(self, user_prompt='')
この演習はコースの一部です
Llama 3 を使いこなす
演習の手順
- まず旅行のおすすめを尋ね、最初のモデルの返答のあとに追加入力のリクエストを行ってください。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
chatbot = Conversation(llm, system_prompt="You are a travel expert that recommends a travel destination based on a prompt. Return the location name only as 'City, Country'.")
# Ask for the initial travel recommendation
first_recommendation = chatbot.____("Recommend a Spanish-speaking city.")
print(first_recommendation)
# Add an additional request to update the recommendation
second_recommendation = chatbot.____("A different city in the same country")
print(second_recommendation)