開始使用免費開始

擷取回應

資料分析的 AI 助理必須回傳乾淨、易讀的內容給使用者,公司希望你只從模型回應中擷取相關文字。

請從已預先匯入的 Llama 的 response 中,僅擷取並印出產生的文字。

本練習屬於課程

使用 Llama 3

檢視課程

練習說明

  • response"choices" 清單的第一個元素擷取 "text",並將其存入 extracted
  • 印出 extracted

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Extract the first choice and generated text
extracted = response["choices"]____

# Print the extracted text
print(____)
編輯並執行程式碼