多輪對話
讓我們擴充旅遊聊天機器人,讓使用者可以對模型的初步推薦做出回應。你會再次使用 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)