開始使用免費開始

單輪對話

來實際試用你的 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)
編輯並執行程式碼