練習:改善完成品質
現在我們已經瞭解提示的元件,以及如何使用元件建構提示,來產生高品質的完成。
讓我們更新我們在上一個練習中啟動的登山建議應用程式,以納入其中一些技術。
更新系統提示
分類產品評論時,我們只希望模型告訴我們評論是不是正面、中性或負面。 讓我們更新模型收到的提示,讓它有最佳的機會提供高品質的回應。
目前的系統提示是正常的,但我們可以透過遵循提示建構的最佳做法,取得模型來建議更適當且令人興奮的登山道。 讓我們對模型如何更清楚地動作提出指令
新增指令
開啟您稍早建立的 HikingConversationsAI 專案。
在 Program.cs 檔案中,找出用來告訴模型其特質特徵的變數
systemPrompt
,以及它需要遵循的任何規則。移除變數中所有現有的文字,並新增下列內容,以概述模型應如何運作及其應遵循的規則:
var systemPrompt = """ You are a hiking enthusiast who helps people discover fun hikes in their area. You are upbeat and friendly. You introduce yourself when first saying hello. When helping people out, you always ask them for this information to inform the hiking recommendation you provide: 1. Where they are located 2. What hiking intensity they are looking for """;
新增主要內容
主要內容是指模型正在轉換的文字,以及其用途。 在此情況下,就是登山建議本身。
更新
systemPrompt
變數,以指示模型如何處理內容。var systemPrompt = """ You are a hiking enthusiast who helps people discover fun hikes in their area. You are upbeat and friendly. You introduce yourself when first saying hello. When helping people out, you always ask them for this information to inform the hiking recommendation you provide: 1. Where they are located 2. What hiking intensity they are looking for You will then provide three suggestions for nearby hikes that vary in length after you get that information. You will also share an interesting fact about the local nature on the hikes when making a recommendation. """;
改善登山建議要求
現在,模型對於其運作方式及其應遵循的規則有更好的資訊,讓我們將模型接收到的要求變得更好,讓它建議更適當的登山路線。
要具體
上一個要求只說了費力的登山道應該要有絕佳的視野。 讓我們確切地告訴模型我們要尋找的項目。
尋找
hikeRequest
變數,並將其更新為具有下列特定要求的資訊。var hikeRequest = """ I live near Seattle and would like a strenuous hike around the I-90 corridor that ends with a view that is amazing. I don't mind driving for a long time, even if it's over the pass. I've heard the Enchantments are nice. I don't want the hike to be over 10 miles round trip. I'd consider a point-to-point hike. I want the hike to be as seculuded as possible. I don't want to see many people. I would like it to be as bug free as possible. I would also like to avoid any Forest Service roads. """;
使用
dotnet run
執行應用程式,並查看它現在的建議。 以下是我們從一次執行接收的範例:Great! Based on your preferences, I'd recommend the following strenuous hikes with amazing views near the I-90 corridor: 1. Mt. Defiance - This hike is a challenging out-and-back trail that is about 10 miles long round trip and boasts stunning views of the Cascade Range from the summit. This trail is relatively secluded and is not located near any Forest Service roads. An interesting fact about this hike is that it passes through an old-growth forest with several old cedar trees. 2. Mailbox Peak - This is another challenging out-and-back trail that is roughly 9.4 miles long round trip. At the summit, hikers will be rewarded with breathtaking views of the surrounding mountains and valleys. Although this hike can be popular, starting early in the morning may help you avoid larger crowds. Additionally, this hike is known to be one of the steepest and most difficult hikes in the area. 3. Talapus and Ollalie Lakes - This hike is less strenuous than the first two and is a point-to-point hike that is about 8 miles long round trip. Despite being less challenging, this hike still offers stunning views of two beautiful alpine lakes and has a relatively low amount of traffic. Interesting fact, this trail is within the Alpine Lakes Wilderness and hikers should keep an eye out for wildlife, including black bears, during their visit. Hope this helps and happy hiking!
這好多了! 回應會遵循系統提示的規則,並提供所要求的登山道描述詳細資訊。
如果您仔細看一下,則登山道建議第 3 指出這兩者都是點對點和來回登山行程。 讓我們變更建議要求提示,以查看我們是否可以避免該錯誤資訊。
思維鏈結
要求模型提供其思考流程的逐步敘述,應該會有助於模型提出更精確的建議。
將變數
hikeRequest
更新為下列:var hikeRequest = """ I live near Seattle and would like a strenous hike around the I-90 corridor that ends with a view that is amazing. I don't mind driving for a long time, even if it's over the pass. I've heard the Enchantments are nice. I don't want the hike to be over 10 miles round trip. I'd consider a point-to-point hike. I want the hike to be as seculuded as possible. I don't want to see many people. I would like it to be as bug free as possible. I would also like to avoid any Forest Service roads. In the response for each hike, provide a step-by-step accounting of why you picked the hike that you did based off of the attributes I provided above. """;
使用
dotnet run
執行應用程式,並查看它現在的建議。 以下是我們從一次執行接收的範例:Great, based on your preferences, I have three hiking recommendations for you near the I-90 corridor. 1. Mount Si - Distance: 8 miles round-trip, Elevation gain: 3,150 ft Located near North Bend, Mount Si is a strenuous hike that ends with beautiful views of the Cascade Mountains and the Snoqualmie Valley. Although it's a popular hike, you can still find secluded areas if you hike a bit further from the trailhead. This trail offers a challenging uphill climb through forests and rocky terrain before reaching the summit. The bugs can be present in the summer, so be sure to bring some repellent. The trailhead is easy to find, and there is no need to take any forest service roads. 2. Snow Lake - Distance: 7.2 miles round-trip, Elevation gain: 1,800 ft Located off of the Snoqualmie Pass, Snow Lake is a moderately challenging hike that offers great views of alpine scenery and serene mountain lake. The trail is a bit rocky but is well-maintained. Although it's a popular hike, you can still find some secluded spots around the lake. The hike starts off on the Alpental Ski Area, with no need to take any forest service roads. There is some bug activity on this trail in the summer months. 3. Granite Mountain - Distance: 8.6 miles round-trip, Elevation gain: 3,800 ft Located off of the I-90 corridor near exit 47, Granite Mountain is a strenuous hike that offers sweeping views of the mountains and valleys of the Alpine Lakes Wilderness. The trail is challenging, but well worth it. The trailhead is easy to find, and there is no need to take any forest service roads. There may be some bug activity on this trail, so it's best to bring some repellent. I hope you find these recommendations helpful!