LLM Prompt Engineering - 如何用進行摘要
back-to:: LLM Prompt Engineering MOC
指定 summary 的字數
範例的 product review :
Got this panda plush toy for my daughter's birthday,
who loves it and takes it everywhere. It's soft and super cute, and its face has a friendly look. It's a bit small for what I paid though. I think there might be other options that are bigger for the same price. It arrived a day earlier than expected, so I got to play with it myself before I gave it to her.
我在我女兒的生日時買了這隻熊貓毛絨玩具,她很喜歡它,無論去哪裡都帶著它。它很軟,非常可愛,臉上的表情很友善。不過相對於我付的價錢來說,它有點小了。我覺得可能有其他同樣價格但更大的選擇。它提前一天到達,所以在交給她之前,我還有機會自己玩一下。
prompt = f"""
Your task is to generate a short summary of a product
review from an ecommerce site.
Summarize the review below, delimited by triple
backticks, in at most 30 words.
Review: ```{prod_review}```
"""
response = get_completion(prompt)
print(response)
結果 :
這款熊貓毛絨玩具很受孩子歡迎,軟軟的、可愛且表情友善。價格有點小貴,但可能有更大的選擇。提前送達,我還有機會玩一下。
調整總結方向 專注於物流相關訊息
focusing on any aspects that mention shipping and delivery of the product.
請專注於提及產品運輸和交付的任何方面。
調整總結方向 專注於價格相關訊息
focusing on any aspects that are relevant to the price and perceived value.
著重關注與價格和價值感受相關的任何方面。
使用 extract 替代 summarize 來更專注於所需訊息
prompt = f"""
Your task is to extract relevant information from
a product review from an ecommerce site to give
feedback to the Shipping department.
From the review below, delimited by triple quotes
extract the information relevant to shipping and
delivery. Limit to 30 words.
Review: ```{prod_review}```
"""
response = get_completion(prompt)
print(response)
Your task is to extract relevant information
這個方法更像從一大段文字中,只抽取我們想要的訊息,而非像 summary 有比較長的敘述性文字
output :
The product arrived a day earlier than expected.
總結多筆評論
reviews = [review_1, review_2, review_3, review_4]
for i in range(len(reviews)):
prompt = f"""
Your task is to generate a short summary of a product
review from an ecommerce site.
Summarize the review below, delimited by triple
backticks in at most 20 words.
Review: ```{reviews[i]}```
"""
response = get_completion(prompt)
print(i, response, "\n")
還可以再延伸進一步處理成 JSON 存到資料庫