單輪對話
來實際試用你的 Conversation 類別吧!你會用這個類別建立一個旅遊推薦聊天機器人。它會接收你想找的描述或規格,然後由模型回傳一個地點。
你在上一個練習建立的 Conversation 類別依然可用,且包含以下方法:
__init__(self, llm: Llama, system_prompt='', history=[])create_completion(self, user_prompt='')
本練習屬於課程
使用 Llama 3
練習說明
- 以已定義的
instruction和預先載入的llm,初始化一個Conversation類別實例。 - 傳送一個提示給模型以取得旅遊推薦(你也可以自由加入自己的提示)。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
instruction = "You are a travel expert that recommends a travel destination based on a specification. Return the location name only in City, Country form."
# Define a chatbot using the Conversation class
chatbot = ____(llm, system_prompt=____)
# Send a prompt to the model
result = chatbot.____("I'd like to learn about the Aztecs.")
print(result)