套用提示工程技巧

Amazon Bedrock 入門

Nikhil Rangarajan

Data Scientist

Few-shot learning

  • 什麼是 few-shot learning?
    • 在提示中提供少量範例,引導模型
    • 幫助模型推斷模式並提升回應品質
  • 主要優點:
    • 降低提示的模糊性
    • 產出更一致、準確的輸出

以範例學習的概念圖。

Amazon Bedrock 入門

模型中的 few-shot learning

prompt = """Here are examples of AWS service summaries:

Service: Amazon S3
Summary: Object storage service for storing and retrieving any amount of data.

Service: Amazon EC2
Summary: Virtual servers in the cloud for running applications.

Now, write a similar summary for:
Service: AWS Lambda\n\nSummary:"""
Amazon Bedrock 入門

什麼是結構化輸出格式?

  • 讓模型回應以清楚、可預測的格式呈現
  • 適合自動化與資料擷取任務

DOC.png

Amazon Bedrock 入門

控制回應格式

  • 要求特定輸出結構
  • 使用清楚標記以利剖析
  • 定義格式限制
prompt = """Analyze AWS Lambda and provide output in this format:
DESCRIPTION:[2-3 sentence description]
KEY FEATURES:
- [feature 1]
- [feature 2]
USE CASES:
1. [use case 1]
2. [use case 2]"""
Amazon Bedrock 入門

打造有效的提示

  • 結合 few-shot 範例與 system 提示
  • 在範例中使用結構化格式
  • 分層運用技巧以取得更佳結果
prompt = """You are an AWS technical writer. 
Here's an example of how to document APIs:
API: GetItem
Format: - Purpose: [one line], 
- Parameters: [list], 
- Returns: [description]
Now document the following API:
API: PutItem"""
Amazon Bedrock 入門

一起來練習吧!

Amazon Bedrock 入門

Preparing Video For Download...