# Lab 2 - Exploring the Power of LLM
在實作課上 pecu 老師 demo 了如何使用 (Azure) OpenAI 的 API 並且包進自己的網頁應用(web application)中。在該練習中我們透過題詞工程(Prompt Engineering)完成了一個模擬對話的機器人介面,那這次的作業希望各位同學試試看利用題詞工程來完成第一次作業的推薦系統,感受一下 LLM 可以創造的無限可能。
- **hint 1**:可以使用我在課堂上提供的 Azure OpanAI endpoint,以這個 request 做為 template:
```
curl "https://ntnu-ml.openai.azure.com/openai/deployments/ntnu-ml-gpt4-32k/chat/completions?api-version=2023-07-01-preview" \
-H "Content-Type: application/json" \
-H "api-key: YOUR_API_KEY" \
-d "{
\"messages\": [{\"role\":\"system\",\"content\":\"根據 ``` 中提供的 rating.csv 資料,用協同過濾的概念推薦餐廳給使用者,請以 json array 格式回答\n```\ncustomerId,restaurantId,rating\nc1,r2,3\nc1,r3,1\nc1,r5,3\nc1,r6,2\nc2,r1,3\nc2,r3,1\nc2,r5,1\nc2,r6,1\nc3,r4,3\nc3,r5,3\nc3,r6,3\nc4,r1,1\nc4,r4,1\nc4,r5,3\nc5,r2,1\nc5,r3,2\nc5,r4,3\nc6,r2,3\nc6,r3,3\nc6,r5,3\nc7,r2,3\nc7,r3,3\nc7,r4,1\nc8,r1,2\nc8,r2,1\nc8,r5,1\nc8,r6,2\n```\"},{\"role\":\"user\",\"content\":\"c1\"}],
\"max_tokens\": 800,
\"temperature\": 0.5,
\"frequency_penalty\": 0,
\"presence_penalty\": 0,
\"top_p\": 0.95,
\"stop\": null
}"
```
- **hint 2**:因為 LLM 的隨機性,每次回答的結果有可能會不如預期(例如回傳的 json array 裡面的欄位可能會不一樣),除了在 template 中利用 prompt 提示 output format 的方法以外,另一個常見的做法是透過[少量樣本提示(Few-Shot Prompting)](https://promptingguide.azurewebsites.net/techniques/fewshot)來讓回應結果符合我們期望的樣子。
可以使用上課時的[範例資料](https://github.com/microsoft/hol-azure-machine-learning/blob/master/008-lab-recommendation-system.md)或自行提供,作業的要求格式是一個靜態網頁,有輸入框可以輸入 customerId 然後可以顯示回傳的推薦結果(restaurantId 的列表)