開始使用免費開始

為 Llama 設計良好格式的提示

模型有時難以從冗長且未結構化的提示中,清楚區分任務、預期輸出與額外脈絡。為了改善這點,你可以加入清楚的標籤,將這些資訊分段並加以區隔,讓模型更好理解。

Llama 模型已以 llm 提供,並會在本課程的其餘單元中持續可用。

本練習屬於課程

使用 Llama 3

檢視課程

練習說明

  • 在提示中加入 InstructionQuestionAnswer 等標籤,讓其格式更清楚。
  • 將該提示傳給模型。

動手互動練習

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

# Add formatting to the prompt
prompt="""
____: Explain the concept of gravity in simple terms.
____: What is gravity?
____:
"""

# Send the prompt to the model
output = llm(____, max_tokens=15, stop=["Question:"]) 
print(output['choices'][0]['text'])
編輯並執行程式碼