练习 - 提高完成质量

已完成 100 XP

现在,我们了解了提示的组件,以及如何使用这些组件来构造提示以生成高质量的完成。

让我们更新在上一个练习中启动的徒步旅行建议应用程序,以纳入其中一些技术。

更新系统提示

对产品评论进行分类时,我们只希望模型告诉我们评论是正面的、中立的还是负面的。 让我们更新模型收到的提示,使其最有机会提供高质量的响应。

当前的系统提示没有问题,但我们可以通过遵循提示构造的最佳做法,让模型推荐更合适、更令人兴奋的徒步旅行。 让我们更清楚地说明模型应如何运行

添加说明

  1. 打开你之前创建的 HikingConversationsAI 项目。

  2. 在 Program.cs 文件中,找到用于告知模型其个性特征及其需要遵循的任何规则的 systemPrompt 变量。

  3. 从变量中移除所有现有文本并添加以下内容,这些内容概述了模型应如何运行及其应遵循的规则:

    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
    """;
    

添加主要内容

主要内容是指模型正在转换的文本及其处理方式。 在本例中是徒步旅行建议本身。

  1. 更新 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.
    """;
    

改进徒步旅行建议请求

现在,模型已经更清楚地了解了它应该如何运行以及应该遵循哪些规则,让我们来改进它收到的请求,以便它建议更加合适的徒步旅行。

更具体些

之前的要求只是说徒步旅行应该是艰苦的,但风景却很美。 让我们确切地告诉模型我们要查找的内容。

  1. 找到 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.
    """;
    
  2. 使用 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 表明它既是点到点徒步旅行,也是往返徒步旅行。 让我们更改建议请求提示,看看是否可以避免这种错误信息。

思维链

要求模型逐步说明其思维过程应该有助于它推荐更准确的建议。

  1. 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.
    """;
    
  2. 使用 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!    
    

下一单元: 总结

上一篇 下一步