確保回應安全
你正在為醫療團隊設定一個內部聊天機器人。為了讓回應一致,你需要透過設定權杖上限並限制權杖挑選的方式來降低變異性。
系統已在變數 llm 中提供 Llama 類別的實例,以及呼叫補全文的程式碼。也提供了一個範例提示可供你測試。
本練習屬於課程
使用 Llama 3
練習說明
- 設定模型參數:將最大權杖數限制為 10,並讓模型在每一步補全時只在最可能的 2 個詞之間進行選擇。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
output = llm(
"What are the symptoms of strep throat?",
# Set the model parameters
max_tokens=____, #Limit response length
top_k=____ #Restrict word choices
)
print(output['choices'][0]['text'])