---
# System prepended metadata

title: 大型語言模型實作讀書會第二組

---

---
#此區塊是此page style設定，更動時小心!
slideOptions:
slideNumber: true #顯示頁碼
# type: slide #投影片模式
tags: LLM,LangChain,TAIA,HIT #設定標籤
disqus: hackmd #允許user在文件下方寫評論
---

# 大型語言模型實作讀書會第二組
## 報告主題:[ChatGPT Prompt Engineering for Developers](https://learn.deeplearning.ai/chatgpt-prompt-eng/lesson/1/introduction)
## 報告日期 113/1/2
## PM:eric,joyce



## 12/19
### 簡報

- [讀書會說明](https://hackmd.io/s-ywY45mRICfWhZDgWB4PQ?view#/ =80%x)
- [八周課程內容簡介](https://gamma.app/docs/-vsoxoexxs6v3qzp?mode=doc =80%x)


## 12/26
### 李弘毅老師-80分鐘快速了解大型語言模型
影片 -> [80分鐘快速了解大型語言模型](https://youtu.be/wG8-IUtqu-s?si=zixD9AzNaDI1vWaC)

### Intro to Large Language Models
Andrej Karpathy -> [Intro to Large Language Models](https://youtu.be/zjkBMFhNj_g?si=lMQVupjunafqtFVa)

### 提問
> 同步試算表第二組的提問

- Q1:為什麼英文Toke不是單字，因為Token不能窮舉。什麼是窮舉?
- Q2:當提到 Let's work this out in a step by step way to be sure we have the right answer.什麼是APE?
- Q3:讓AI step by step思考可提昇回答的準確率，這在每個領域都是這樣嗎？還是某些領域特別突出，如程式設計？語文？

---
## 1/2(第二組)
### Introduction
影片中文翻譯" by Joyce

歡迎來到這個專為開發者設計的ChatGPT提示工程課程。
我真的很開心能夠跟Isa Fulford一起教這堂課。她是OpenAI的技術團隊成員，開發出了超受歡迎的ChatGPT檢索插件，而且她的主要工作就是教人們怎麼在產品中運用LLM（大型語言模型）技術。她還對OpenAI的Cookbook做出了貢獻，那本書教大家如何使用提示。非常興奮有她的加入。
我也很高興能在這裡跟大家分享一些關於提示的最佳做法。
所以啊，網路上有好多關於提示的資料，像是“每個人都必須知道的30個提示”這種文章。這些大多都集中在ChatGPT的網頁用戶介面上，很多人用它來做特定的、通常是一次性的任務。但是，我覺得作為開發工具的LLM（大型語言模型），也就是用API呼叫LLM來快速建立軟體應用，這個功能還被低估了。

其實啊，我在AI Fund的團隊，那是DeepLearning.ai的姐妹公司，我們跟好多新創公司合作，把這些技術應用在各種不同的應用上，看到LLM API可以讓開發者迅速建立的東西，真的很讓人興奮。所以在這堂課，我們會跟你分享一些可能性，還有你怎麼做的最佳實踐。
要講的東西可多了。首先，你會學到一些在軟體開發中使用提示的最佳做法，然後我們會講一些常見的使用案例，像是摘要、推斷、轉換、擴展，然後你會用LLM來建立一個聊天機器人。我們希望這能啟發你對建立新應用的想像。
在開發大型語言模型或LLM的過程中，大致上有兩種LLM，我會稱它們為基礎LLM和指令調整LLM。
所以啊，基礎LLM是根據文本訓練數據來預測下一個詞的，通常是用從網路和其他地方來的大量數據訓練的，來推測下一個可能的詞。比如說，如果你讓我們用“從前有一隻獨角獸”來提示，它可能會接下去寫“住在一個魔法森林裡，和所有的獨角獸朋友一起”。
但如果你用“法國的首都是什麼”來提示我們，那麼根據網路上的文章，基礎LLM可能會接下去寫“法國最大的城市是什麼”，“法國的人口有多少”之類的，因為網路上的文章很可能就是關於法國的測驗問題列表。
相對地，指令調整LLM就是LLM研究和實務上的主要方向，它被訓練來遵循指令。所以如果你問它法國的首都是什麼，它更有可能回答“法國的首都是巴黎”。指令調整LLM通常的訓練方式是從一個已經用大量文本數據訓練過的基礎LLM開始，再進一步訓練它，用包含指令和嘗試跟隨這些指令的輸入和輸出來微調，然後通常再用一種叫做RLHF（來自人類反饋的強化學習）的技術來進一步精煉，讓系統更能幫忙和遵循指令。因為指令調整LLM被訓練成有益、誠實和無害，比如說，它們比基礎LLM不太可能產生問題性的文本，像是有毒的輸出，許多實際使用的場景都轉向使用指令調整LLM。你在網路上找到的一些最佳做法可能更適合基礎LLM，但對於現今大部分的實際應用，我們建議大家專注於使用指令調整LLM，這些模型更容易使用，而且因為OpenAI和其他LLM公司的努力，變得更安全、更一致。

所以這門課程會專注在指令調整LLM的最佳做法上，這是我們推薦你在大多數應用中使用的。在繼續之前，我想感謝OpenAI和DeepLearning.ai的團隊，他們對Isa和我將要介紹的材料做出了貢獻。我很感謝OpenAI的Andrew Mayne、Joe Palermo、Boris Power、Ted Sanders和Lillian Weng，他們在我們集思廣益材料、審核材料方面參與很深，以便為這個短期課程編制課程。我也要感謝DeepLearning方面的Geoff Lodwig、Eddy Shyu和Tommy Nelson的工作。所以，當你使用指令調整LLM時，想像你在給另一個人指令，比如一個聰明但不知道你任務具體內容的人。所以，當LLM沒有達到效果時，有時是因為指令不夠清楚。比如說，如果你說，請寫一些關於艾倫·圖靈的東西。除此之外，更清楚地指出你想要的文本重點是他的科學工作、個人生活、歷史角色還是其他什麼會更有幫助。如果你指定你想要的文本調性，是專業記者的寫作風格，還是更像給朋友草草寫的隨筆？這會幫助LLM產生你想要的內容。當然，如果你想像自己是要求一個剛畢業的大學生幫你完成這項任務，如果你甚至可以指定他們應該提前讀哪些文本摘錄來寫這篇關於艾倫·圖靈的文本，那會更好地幫助這位剛畢業的大學生成功完成這項任務。因此，在下一個影片中，你會看到如何清晰和具體地指示的例子，這是提示LLM的一個重要原則。你也會從Isa那裡學到第二個提示原則，就是給LLM時間思考。那麼，我們就繼續下一個影片吧。


- [胖胖](/e_wvGKkZQdSMU6r5-vy0VQ)


### Guidelines**指導原則與技巧介紹** by Joyce
在這個影片中，Isa將介紹一些寫作提示的指導原則，幫助你獲得想要的結果。她會特別講解兩個關鍵原則，幫助你更有效地進行提示工程。稍後，當她介紹Jupyter Notebook範例時，也鼓勵你隨時暫停影片，親自運行代碼，這樣你可以看到輸出的效果，甚至改變提示，嘗試不同變化，以獲得提示的輸入和輸出經驗。

**語言模型工作原則**
Isa會概述一些在使用像是ChatGPT這樣的語言模型時有幫助的原則和策略。首先，她會從高層次介紹這些原則，然後用具體的範例應用這些策略，這些策略將貫穿整個課程。原則的第一條是寫出清晰且具體的指示，第二條是給模型一些思考的時間。開始前，需要做一些設置，整個課程中會使用OpenAI的Python庫來訪問OpenAI API。

### 1.清晰且具體的指示
應該盡可能清晰且具體地表達你希望模型執行的任務。這將引導模型朝向期望的輸出，減少獲得不相關或不正確回應的機會。清晰的提示不代表要寫得簡短，因為在許多情況下，較長的提示實際上可以為模型提供更多的清晰度和上下文，這可能導致更詳細和相關的輸出。為了寫出清晰且具體的指示，第一個技巧是使用分隔符清楚地指明輸入的不同部分。
Tactics

Delimiters can be anything like: ```, """, < >, <tag> </tag>, :
[[有關符號的說明可以參考這個筆記]](https://hackmd.io/_Vtc-WWYQ0q9Ph94wz-3ig?view)

```
text = f"""
You should express what you want a model to do by \ 
providing instructions that are as clear and \ 
specific as you can possibly make them. \ 
This will guide the model towards the desired output, \ 
and reduce the chances of receiving irrelevant \ 
or incorrect responses. Don't confuse writing a \ 
clear prompt with writing a short prompt. \ 
In many cases, longer prompts provide more clarity \ 
and context for the model, which can lead to \ 
more detailed and relevant outputs.
"""
prompt = f"""
Summarize the text delimited by triple backticks \ 
into a single sentence.
```{text}```
"""
response = get_completion(prompt)
print(response)
```


**結構化輸出的請求**
為了更容易解析模型的輸出，請求結構化輸出（如HTML或JSON）會有幫助。例如，要求模型生成一個包含書名、作者和類型的書籍列表，並以JSON格式提供。
```
prompt = f"""
Generate a list of three made-up book titles along \ 
with their authors and genres. 
Provide them in JSON format with the following keys: 
book_id, title, author, genre.
"""
response = get_completion(prompt)
print(response)
```




**檢查條件是否滿足**
如果任務假設了某些不一定會滿足的條件，可以告訴模型先檢查這些假設。如果沒有滿足，則指示此情況並停止完整的任務嘗試。
```
text_1 = f"""
Making a cup of tea is easy! First, you need to get some \ 
water boiling. While that's happening, \ 
grab a cup and put a tea bag in it. Once the water is \ 
hot enough, just pour it over the tea bag. \ 
Let it sit for a bit so the tea can steep. After a \ 
few minutes, take out the tea bag. If you \ 
like, you can add some sugar or milk to taste. \ 
And that's it! You've got yourself a delicious \ 
cup of tea to enjoy.
"""
prompt = f"""
You will be provided with text delimited by triple quotes. 
If it contains a sequence of instructions, \ 
re-write those instructions in the following format:

Step 1 - ...
Step 2 - …
…
Step N - …

If the text does not contain a sequence of instructions, \ 
then simply write \"No steps provided.\"

\"\"\"{text_1}\"\"\"
"""
response = get_completion(prompt)
print("Completion for Text 1:")
print(response)
```



**少量例子提示（Few-shot Prompting）**
提供成功執行你希望完成的任務的例子，然後再要求模型執行實際的任務。這種方法可以提高模型回應的準確性。
```
prompt = f"""
Your task is to answer in a consistent style.

<child>: Teach me about patience.

<grandparent>: The river that carves the deepest \ 
valley flows from a modest spring; the \ 
grandest symphony originates from a single note; \ 
the most intricate tapestry begins with a solitary thread.

<child>: Teach me about resilience.
"""
response = get_completion
(prompt)
print(response)
```

### 2.給予模型思考的時間
如果模型因為倉促得出錯誤結論而犯了推理錯誤，可以嘗試重新構建查詢，要求在提供最終答案之前進行一系列相關的推理。
```
text = f"""
In a charming village, siblings Jack and Jill set out on \ 
a quest to fetch water from a hilltop \ 
well. As they climbed, singing joyfully, misfortune \ 
struck—Jack tripped on a stone and tumbled \ 
down the hill, with Jill following suit. \ 
Though slightly battered, the pair returned home to \ 
comforting embraces. Despite the mishap, \ 
their adventurous spirits remained undimmed, and they \ 
continued exploring with delight.
"""
 
prompt_1 = f"""
Perform the following actions: 
1 - Summarize the following text delimited by triple \
backticks with 1 sentence.
2 - Translate the summary into French.
3 - List each name in the French summary.
4 - Output a json object that contains the following \
keys: french_summary, num_names.

Separate your answers with line breaks.

Text:
```{text}```
"""
response = get_completion(prompt_1)
print("Completion for prompt 1:")
print(response)
```

**指定完成任務所需的步驟**
具體指定完成任務所需的步驟，例如先摘要文本，再將摘要翻譯成法語，然後列出法文摘要中的每個名字，並輸出包含特定鍵值的JSON對象。
```
prompt_2 = f"""
Your task is to perform the following actions: 
1 - Summarize the following text delimited by 
  <> with 1 sentence.
2 - Translate the summary into French.
3 - List each name in the French summary.
4 - Output a json object that contains the 
  following keys: french_summary, num_names.

Use the following format:
Text: <text to summarize>
Summary: <summary>
Translation: <summary translation>
Names: <list of names in summary>
Output JSON: <json with summary and num_names>

Text: <{text}>
"""
response = get_completion(prompt_2)
print("\nCompletion for prompt 2:")
print(response)
```



**模型先行解決方案**
在模型匆忙得出結論之前，指示模型先解決自己的方案。有時，當我們明確指示模型在得出結論之前先進行自我推理時，會獲得更好的結果。
```
prompt = f"""
Determine if the student's solution is correct or not.

Question:
I'm building a solar power installation and I need \
 help working out the financials. 
- Land costs $100 / square foot
- I can buy solar panels for $250 / square foot
- I negotiated a contract for maintenance that will cost \ 
me a flat $100k per year, and an additional $10 / square \
foot
What is the total cost for the first year of operations 
as a function of the number of square feet.

Student's Solution:
Let x be the size of the installation in square feet.
Costs:
1. Land cost: 100x
2. Solar panel cost: 250x
3. Maintenance cost: 100,000 + 100x
Total cost: 100x + 250x + 100,000 + 100x = 450x + 100,000
"""
response = get_completion(prompt)
print(response)
```


### 3.語言模型的限制:Hallucinations by Joyce
即使語言模型在訓練過程中接觸到了大量知識，它並沒有完美記憶所見信息，因此不太了解自己知識的邊界。這意味著它可能試圖回答一些不常見主題的問題，並可能製造出聽起來合理但實際上不真實的內容。这些被称为“幻觉”。
```
Boie is a real company, the product name is not rea
prompt = f"""
Tell me about AeroGlide UltraSlim Smart Toothbrush by Boie
"""
response = get_completion(prompt)
print(response)

```

這就是對於提示的指導原則和策略的總結，接下來的影片將會討論迭代式提示開發過程。
- [胖胖](/Fv0nF1S0SGuiRxlmxKw3JA)


### Iterative**迭代式提示開發流程** by Joyce

在開發大型語言模型的應用時，我從來沒有在第一次嘗試就找到最終應用中使用的提示。這並不重要，重要的是擁有一個好的過程，可以逐步改進你的提示，最終找到適合你想要完成的任務的解決方案。
當我訓練機器學習模型時，它幾乎從來不會在第一次就成功。實際上，我會很驚訝如果我訓練的第一個模型就能工作。我認為對於提示來說，第一次成功的機率可能略高一些，但正如他所說，第一次提示是否成功並不重要，重要的是達到適合你應用的提示的過程。

**迭代式開發流程**
當你使用LLM開發應用時，過程與機器學習開發非常相似。你有一個想要完成的任務，可以嘗試寫出清晰且具體的提示，然後運行看看結果如何。如果第一次不夠好，就可以通過迭代過程，了解為什麼指示不夠清晰，或為什麼沒有給算法足夠的思考時間，從而改進你的想法和提示，多次循環，直到找到適合你應用的提示。

**提示開發的實際案例**
以椅子的事實表為例，來看看如何在代碼中一起開發提示。我在這裡有之前影片中看到的起始代碼，包括導入OpenAI、獲取OpenAI API金鑰等。我將使用總結椅子事實表的任務作為本影片的實例。讓我們來開發一個提示，幫助營銷團隊為網上零售網站撰寫產品描述。
```
fact_sheet_chair = """
OVERVIEW
- Part of a beautiful family of mid-century inspired office furniture, 
including filing cabinets, desks, bookcases, meeting tables, and more.
- Several options of shell color and base finishes.
- Available with plastic back and front upholstery (SWC-100) 
or full upholstery (SWC-110) in 10 fabric and 6 leather options.
- Base finish options are: stainless steel, matte black, 
gloss white, or chrome.
- Chair is available with or without armrests.
- Suitable for home or business settings.
- Qualified for contract use.

CONSTRUCTION
- 5-wheel plastic coated aluminum base.
- Pneumatic chair adjust for easy raise/lower action.

DIMENSIONS
- WIDTH 53 CM | 20.87”
- DEPTH 51 CM | 20.08”
- HEIGHT 80 CM | 31.50”
- SEAT HEIGHT 44 CM | 17.32”
- SEAT DEPTH 41 CM | 16.14”

OPTIONS
- Soft or hard-floor caster options.
- Two choices of seat foam densities: 
 medium (1.8 lb/ft3) or high (2.8 lb/ft3)
- Armless or 8 position PU armrests 

MATERIALS
SHELL BASE GLIDER
- Cast Aluminum with modified nylon PA6/PA66 coating.
- Shell thickness: 10 mm.
SEAT
- HD36 foam

COUNTRY OF ORIGIN
- Italy
"""
prompt = f"""
Your task is to help a marketing team create a 
description for a retail website of a product based 
on a technical fact sheet.

Write a product description based on the information 
provided in the **technical specifications** delimited by 
triple backticks.

Technical specifications: ```{fact_sheet_chair}```
"""
response = get_completion(prompt)
print(response)
```



**迭代改進提示**
我寫了一個提示，得到了結果，但發現它太長了。所以，我明確了提示，要求最多使用50個單詞，以更好地指導期望的長度。進一步地，我也嘗試了其他方法來控制輸出的長度，例如最多三句話或280個字符。這些是不同的方法，可以用來告訴大型語言模型你希望的輸出長度。
```
prompt = f"""
Your task is to help a marketing team create a 
description for a retail website of a product based 
on a technical fact sheet.

Write a product description based on the information 
provided in the technical specifications delimited by 
triple backticks.

**Use at most 50 words.**

Technical specifications: ```{fact_sheet_chair}```
"""
response = get_completion(prompt)
print(response)
len(response.split())

```

**細化提示目標**
當我們繼續精煉這個網站的文本時，我們可能會決定這個網站不是直接面向消費者銷售，而是打算向家具零售商銷售，他們可能更關注椅子的技術細節和材料。在這種情況下，你可以修改提示，使其更加注重技術細節。
```
prompt = f"""
Your task is to help a marketing team create a 
description for a retail website of a product based 
on a technical fact sheet.

Write a product description based on the information 
provided in the technical specifications delimited by 
triple backticks.

The description is intended for furniture retailers, 
so should be technical in nature and focus on the 
materials the product is constructed from.

At the end of the description, include every 7-character 
Product ID in the technical specification.

Use at most 50 words.

Technical specifications: ```{fact_sheet_chair}```
"""
response = get_completion(prompt)
print(response)
```



**高級提示開發**
我們在開發大型語言模型應用時，通常會經歷迭代式提示開發過程。我認為，成為一個有效的提示工程師的關鍵不在於知道完美的提示，而在於有一個好的過程來開發適合你應用的提示。在這個影片中，我只用一個例子來展示開發提示的過程。對於更複雜的應用，有時你會有多個例子，比如一份或多份事實表，並迭代開發提示，並根據大量案例進行評估。
```
prompt = f"""
Your task is to help a marketing team create a 
description for a retail website of a product based 
on a technical fact sheet.

Write a product description based on the information 
provided in the technical specifications delimited by 
triple backticks.

The description is intended for furniture retailers, 
so should be technical in nature and focus on the 
materials the product is constructed from.

At the end of the description, include every 7-character 
Product ID in the technical specification.

After the description, include a table that gives the 
product's dimensions. The table should have two columns.
In the first column include the name of the dimension. 
In the second column include the measurements in inches only.

Give the table the title 'Product Dimensions'.

Format everything as HTML that can be used in a website. 
Place the description in a <div> element.

**Technical specifications: ```{fact_sheet_chair}```
"""**

response = get_completion(prompt)
print(response)
```

**總結與下一步**
希望你從這個影片中了解到，提示開發是一個迭代過程。嘗試某些東西，看看它如何還未完全滿足你的需求，然後思考如何澄清你的指示，或在某些情況下，考慮如何給予它更多的思考空間，讓它更接近於提供你所需的結果。接下來，請你自己嘗試Jupyter代碼筆記本中的不同變化，看看你能得到什麼結果。完成後，我們將進入下一個影片，討論大型語言模型在軟件應用中的一個非常常見的用途：文本摘要。准備好後，我們就進入下一個影片吧。
- [胖胖](/Rb3ac9m7S7yWYgpGOn3xMQ)


### Summarizing**文本摘要的應用** by Joyce

在今天這個文字泛濫的世界中，幾乎沒有人有足夠的時間閱讀所有他們希望閱讀的東西。因此，我見過的最令人興奮的大型語言模型應用之一，就是使用它來摘要文本，這是我看到多個團隊在多個軟件應用中建立的功能。

**如何進行文本摘要**
你可以在chatGPT網頁介面中做到這一點。我經常用它來摘要文章，這樣我就可以閱讀更多文章的內容，如果你想以更程式化的方式做到這一點，你會在這堂課中看到如何做。接下來，讓我們深入代碼，看看你如何用它來為自己摘要文本。

**開始摘要文本**
讓我們從與之前相同的起始代碼開始：導入OpenAI，載入API密鑰，這裡是那個幫助函數getCompletion。我將使用摘要產品評論的任務作為實例。如果你正在建立一個電子商務網站，並且有大量的評論，擁有一個摘要冗長評論的工具可以讓你更快地瀏覽更多評論，從而更好地了解你的所有客戶的想法。
```
prod_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.
"""   
```



**生成摘要的提示**
這裡是一個用於生成摘要的提示。你的任務是生成一個來自電子商務網站產品評論的短摘要，最多30個單詞。這是一個相當不錯的摘要。正如你在上一個視頻中看到的，你還可以用控制字數或句子數來影響這個摘要的長度。
```
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)
```    



**根據特定目的修改提示**
有時創建摘要時，如果你有一個非常具體的目的，例如，如果你想給運輸部門提供反饋，你也可以修改提示以反映這一點，這樣他們就可以生成更適用於特定業務團隊的摘要。
```
prompt = f"""
Your task is to generate a short summary of a product \
review from an ecommerce site to give feedback to the \
Shipping deparmtment. 

Summarize the review below, delimited by triple 
backticks, in at most 30 words, and focusing on any aspects \
**that mention shipping and delivery of the product. **

Review: ```{prod_review}```
"""

response = get_completion(prompt)
print(response)


```


**提取信息而非摘要**
根據你想要的摘要方式，你也可以要求它提取信息而不是摘要。這裡有一個提示，你的任務是為運輸部門提取相關信息。現在它只說產品比預期提前一天到達，沒有所有其他對於一般摘要有幫助但對運輸部門來說不太具體的信息。
```
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)
```


**多個評論的摘要，在工作流程中使用摘要**
最後，讓我給你一個具體的例子，展示如何在工作流程中使用它來幫助摘要多個評論，使它們更容易閱讀。這裡有幾個評論，這有點長，但你知道，這是第二個評論關於立燈的，這是第三個評論關於電動牙刷的。如果你有一個有數百個評論的網站，你可以想像如何使用這個功能來建立一個儀表板，將大量評論生成簡短的摘要，這樣你或其他人就可以更快地瀏覽評論。然後，如果他們願意，也許可以點擊查看原始較長的評論。這可以幫助你有效地更好地了解你的所有客戶的想法。
```
review_1 = prod_review 

 review for a standing lamp
review_2 = """
Needed a nice lamp for my bedroom, and this one \
had additional storage and not too high of a price \
point. Got it fast - arrived in 2 days. The string \
to the lamp broke during the transit and the company \
happily sent over a new one. Came within a few days \
as well. It was easy to put together. Then I had a \
missing part, so I contacted their support and they \
very quickly got me the missing piece! Seems to me \
to be a great company that cares about their customers \
and products. 
"""

 review for an electric toothbrush
review_3 = """
My dental hygienist recommended an electric toothbrush, \
which is why I got this. The battery life seems to be \
pretty impressive so far. After initial charging and \
leaving the charger plugged in for the first week to \
condition the battery, I've unplugged the charger and \
been using it for twice daily brushing for the last \
3 weeks all on the same charge. But the toothbrush head \
is too small. I’ve seen baby toothbrushes bigger than \
this one. I wish the head was bigger with different \
length bristles to get between teeth better because \
this one doesn’t.  Overall if you can get this one \
around the $50 mark, it's a good deal. The manufactuer's \
replacements heads are pretty expensive, but you can \
get generic ones that're more reasonably priced. This \
toothbrush makes me feel like I've been to the dentist \
every day. My teeth feel sparkly clean! 
"""

 review for a blender
review_4 = """
So, they still had the 17 piece system on seasonal \
sale for around $49 in the month of November, about \
half off, but for some reason (call it price gouging) \
around the second week of December the prices all went \
up to about anywhere from between $70-$89 for the same \
system. And the 11 piece system went up around $10 or \
so in price also from the earlier sale price of $29. \
So it looks okay, but if you look at the base, the part \
where the blade locks into place doesn’t look as good \
as in previous editions from a few years ago, but I \
plan to be very gentle with it (example, I crush \
very hard items like beans, ice, rice, etc. in the \ 
blender first then pulverize them in the serving size \
I want in the blender then switch to the whipping \
blade for a finer flour, and use the cross cutting blade \
first when making smoothies, then use the flat blade \
if I need them finer/less pulpy). Special tip when making \
smoothies, finely cut and freeze the fruits and \
vegetables (if using spinach-lightly stew soften the \ 
spinach then freeze until ready for use-and if making \
sorbet, use a small to medium sized food processor) \ 
that you plan to use that way you can avoid adding so \
much ice if at all-when making your smoothie. \
After about a year, the motor was making a funny noise. \
I called customer service but the warranty expired \
already, so I had to buy another one. FYI: The overall \
quality has gone done in these types of products, so \
they are kind of counting on brand recognition and \
consumer loyalty to maintain sales. Got it in about \
two days.
"""

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

```
    

    
下一步
那就是關於摘要的全部內容。我希望你可以想象，如果你有許多文字的應用，你可以如何使用這樣的提示來摘要它們，幫助人們快速了解許多文字中的內容，並可能在他們希望時深入了解更多。在下一個視頻中，我們將看到大型語言模型的另一項能力，即使用文本進行推理。例如，如果你有產品評論，並且你想快速了解哪些產品評論具有積極或消極的情緒，我們將在下一個視頻中看到如何做到這一點。
- [胖胖](/QzChv9LnRviosv6JfKp3ow)


### Inferring**文本推理的應用** by Joyce

在這個視頻中，我們將探討如何利用大型語言模型進行文本推理。這些任務包括讓模型接收一段文本並進行某種分析，例如提取標籤、名稱、理解文本情感等。
傳統的機器學習工作流程中，如果想提取文本的情感（正面或負面），你需要收集標記數據集、訓練模型、弄清楚如何在雲端部署模型並進行推理。這個過程雖然可行，但需要大量工作。每個任務（如情感分析、提取名稱等）都需要訓練和部署獨立的模型。大型語言模型的好處在於，對於許多這樣的任務，你只需編寫一個提示，就可以立即開始生成結果，這在應用開發方面提供了極大的速度優勢。你還可以使用一個模型、一個API來完成多種不同的任務，而不需要訓練和部署許多不同的模型。

**利用代碼進行文本推理**
我們將以對燈具的評論為例，來看看如何進行情感分類。只需編寫一個提示，問系統該評論的情感是什麼，然後執行。結果表明該評論情感為正面。如果你想要更簡潔的回應以便於後續處理，你可以進一步修改提示，讓系統只用一個單詞回答“positive”或“negative”。
```
lamp_review = """
Needed a nice lamp for my bedroom, and this one had \
additional storage and not too high of a price point. \
Got it fast.  The string to our lamp broke during the \
transit and the company happily sent over a new one. \
Came within a few days as well. It was easy to put \
together.  I had a missing part, so I contacted their \
support and they very quickly got me the missing piece! \
Lumina seems to me to be a great company that cares \
about their customers and products!!
"""
prompt = f"""
What is the sentiment of the following product review, 
which is delimited with triple backticks?

Review text: '''{lamp_review}'''
"""
response = get_completion(prompt)
print(response)

prompt = f"""
What is the sentiment of the following product review, 
which is delimited with triple backticks?

Give your answer as a single word, either "positive" \
or "negative".

Review text: '''{lamp_review}'''
"""
response = get_completion(prompt)
print(response)
```


**提取更豐富的信息**
信息提取是自然語言處理（NLP）的一部分，它涉及從文本中提取你想知道的特定事物。例如，我們可以要求模型識別購買的商品和製造商品的公司名稱，並將回應格式化為JSON對象。這對於摘要來自線上購物電子商務網站的大量評論可能非常有用。]
```
prompt = f"""
Identify the following items from the review text: 
- Item purchased by reviewer
- Company that made the item

The review is delimited with triple backticks. \
Format your response as a JSON object with \
"Item" and "Brand" as the keys. 
If the information isn't present, use "unknown" \
as the value.
Make your response as short as possible.
  
Review text: '''{lamp_review}'''
"""
response = get_completion(prompt)
print(response)
    
```


**利用單個提示提取多個信息**
你可以編寫單個提示來同時提取所有這些信息。例如，“識別以下項目，提取情感，審查者是否表達憤怒，購買的商品，製造公司”，然後讓系統以JSON格式輸出。
```
prompt = f"""
Determine five topics that are being discussed in the \
following text, which is delimited by triple backticks.

Make each item one or two words long. 

Format your response as a list of items separated by commas.

Text sample: '''{story}'''
"""
response = get_completion(prompt)
print(response)

    response.split(sep=',')
 topic_list = [
    "nasa", "local government", "engineering", 
    "employee satisfaction", "federal government"
]   
```


**推斷話題**
利用大型語言模型的另一個酷炫應用是推斷主題。給定一篇長文本，該文本是關於什麼的？它涉及哪些話題？我們可以使用提示來確定文本中討論的五個主題，然後將回應格式化為逗號分隔的列表。
```
story = """
In a recent survey conducted by the government, 
public sector employees were asked to rate their level 
of satisfaction with the department they work at. 
The results revealed that NASA was the most popular 
department with a satisfaction rating of 95%.

One NASA employee, John Smith, commented on the findings, 
stating, "I'm not surprised that NASA came out on top. 
It's a great place to work with amazing people and 
incredible opportunities. I'm proud to be a part of 
such an innovative organization."

The results were also welcomed by NASA's management team, 
with Director Tom Johnson stating, "We are thrilled to 
hear that our employees are satisfied with their work at NASA. 
We have a talented and dedicated team who work tirelessly 
to achieve our goals, and it's fantastic to see that their 
hard work is paying off."

The survey also revealed that the 
Social Security Administration had the lowest satisfaction 
rating, with only 45% of employees indicating they were 
satisfied with their job. The government has pledged to 
address the concerns raised by employees in the survey and 
work towards improving job satisfaction across all departments.
"""
   prompt = f"""
Determine five topics that are being discussed in the \
following text, which is delimited by triple backticks.

Make each item one or two words long. 

Format your response as a list of items separated by commas.

Text sample: '''{story}'''
"""
response = get_completion(prompt)
print(response)
 response.split(sep=',')
    
topic_list = [
    "nasa", "local government", "engineering", 
    "employee satisfaction", "federal government"
]
```

    
    **將文本轉換為不同文本**
在下一個視頻中，我們將繼續探討你可以使用大型語言模型做的令人興奮的事情，並將討論“轉換”。比如，如何將一段文本轉換為不同的文本，例如將其翻譯成不同的語言。讓我們繼續下一個視頻。
- [胖胖](/J9Csm0zATQ-iPpUFnbKntw)


### Transforming**轉換格式的應用** by Joyce

大型語言模型非常擅長將其輸入轉換為不同的格式，例如將一段文本從一種語言翻譯成另一種語言，或幫助進行拼寫和語法修正。這包括將不完全符合語法的文本進行修正，或者轉換格式，如將HTML輸入轉換為JSON輸出。以前我們可能需要使用大量正則表達式來實現這些應用，現在通過大型語言模型和幾個提示就能更簡單地實現。

**使用ChatGPT進行文本校對**
我現在幾乎使用ChatGPT校對我寫的所有東西，所以我很興奮地向你展示更多筆記本中的例子。首先我們將導入OpenAI並使用我們一直在視頻中使用的相同get_completion幫助函數。首先，我們將執行一個翻譯任務。大型語言模型接受多種語言的大量文本訓練，這使得它們具有翻譯能力。
    
**簡單的翻譯示例**
在這個例子中，提示是將以下英文文本翻譯成西班牙語：“Hi, I would like to order a blender”。回應是“Hola, me gustaría ordenar una licuadora”。我們也可以嘗試其他翻譯示例，如識別語言或將文本翻譯成多種語言，甚至包括“英語海盜”版本。
```
prompt = f"""
Translate the following English text to Spanish: \ 
```Hi, I would like to order a blender```
"""
response = get_completion(prompt)
print(response)

prompt = f"""
Translate the following  text to French and Spanish
and English pirate: \
```I want to order a basketball```
"""
response = get_completion(prompt)
print(response)
```

    
**面向特定對象的翻譯**
我們還可以向語言模型解釋，翻譯可以根據說話者與聽眾的關係而變化，並相應地進行翻譯。例如，我們可以要求模型將文本翻譯成西班牙語的正式和非正式形式。

**跨語言用戶支援**
在這個例子中，我們假設自己負責一家跨國電子商務公司，用戶訊息將使用不同語言。我們需要一種通用的翻譯器來處理這些訊息。我們將循環遍歷這些用戶訊息，並要求模型將它們翻譯成英語和韓語。
```
user_messages = [
  "La performance du système est plus lente que d'habitude.",  # System performance is slower than normal         
  "Mi monitor tiene píxeles que no se iluminan.",              # My monitor has pixels that are not lighting
  "Il mio mouse non funziona",                                 # My mouse is not working
  "Mój klawisz Ctrl jest zepsuty",                             # My keyboard has a broken control key
  "我的屏幕在闪烁"                                               # My screen is flashing
] 
 for issue in user_messages:
    prompt = f"Tell me what language this is: ```{issue}```"
    lang = get_completion(prompt)
    print(f"Original message ({lang}): {issue}")

    prompt = f"""
    Translate the following  text to English \
    and Korean: ```{issue}```
    """
    response = get_completion(prompt)
    print(response, "\n")   
```


**語氣轉換**
ChatGPT還可以幫助產生不同的語氣。例如，我們可以將口語文本轉換為正式的商務信函，或者將JSON格式的文本轉換為HTML格式。
   **拼寫和語法檢查**
這是ChatGPT的一個非常流行的用途，特別是在使用非母語時。我們將遍歷一些含有語法或拼寫錯誤的句子，並要求模型進行校對和糾正。 
```
    prompt = f"""
Translate the following from slang to a business letter: 
'Dude, This is Joe, check out this spec on this standing lamp.'
"""
response = get_completion(prompt)
print(response)
    
data_json = { "resturant employees" :[ 
    {"name":"Shyam", "email":"shyamjaiswal@gmail.com"},
    {"name":"Bob", "email":"bob32@gmail.com"},
    {"name":"Jai", "email":"jai87@gmail.com"}
]}

prompt = f"""
Translate the following python dictionary from JSON to an HTML \
table with column headers and title: {data_json}
"""
response = get_completion(prompt)
print(response)
 from IPython.display import display, Markdown, Latex, HTML, JSON
display(HTML(response))   

    

```

    
**文本校對應用**
我們還將通過一個例子來檢查一篇關於毛絨熊貓的評論。我們將要求模型校對並糾正評論，並找出原始評論和模型輸出之間的差異。
```
text = [ 
  "The girl with the black and white puppies have a ball.",  # The girl has a ball.
  "Yolanda has her notebook.", # ok
  "Its going to be a long day. Does the car need it’s oil changed?",  # Homonyms
  "Their goes my freedom. There going to bring they’re suitcases.",  # Homonyms
  "Your going to need you’re notebook.",  # Homonyms
  "That medicine effects my ability to sleep. Have you heard of the butterfly affect?", # Homonyms
  "This phrase is to cherck chatGPT for speling abilitty"  # spelling
]
for t in text:
    prompt = f"""Proofread and correct the following text
    and rewrite the corrected version. If you don't find
    and errors, just say "No errors found". Don't use 
    any punctuation around the text:
    ```{t}```"""
    response = get_completion(prompt)
    print(response)
    
text = f"""
Got this for my daughter for her birthday cuz she keeps taking \
mine from my room.  Yes, adults also like pandas too.  She takes \
it everywhere with her, and it's super soft and cute.  One of the \
ears is a bit lower than the other, and I don't think that was \
designed to be asymmetrical. It's a bit small for what I paid for it \
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 my daughter.
"""
prompt = f"proofread and correct this review: ```{text}```"
response = get_completion(prompt)
print(response)
 
from redlines import Redlines

diff = Redlines(text,response)
display(Markdown(diff.output_markdown))
```

    
接下來的主題
下一個主題是“擴展”，我們將研究如何從一個較短的提示中生成更長、更自由形式的來自語言模型的回應。
- [胖胖](/z4hXcm9DQ_a7umZN4qgaXQ)

 
### Expanding**文本擴展的應用** by Joyce

文本擴展是指將較短的文本，例如一組指令或主題列表，通過大型語言模型生成更長的文本，如電子郵件或某個主題的文章。這種功能的應用非常廣泛，例如將大型語言模型作為腦力激盪的夥伴。然而，也要認識到這種功能可能存在一些問題性的使用情況，例如被用來生成大量垃圾郵件。因此，使用大型語言模型時，請負責任地使用，以幫助人們。

**生成個性化電子郵件**
在這個視頻中，我們將展示如何使用語言模型根據一些信息生成個性化電子郵件。這封電子郵件聲稱來自一個AI機器人，這一點非常重要。我們還將使用模型的另一個輸入參數“溫度”，這允許在模型回應中改變探索程度和多樣性。
```
    # given the sentiment from the lesson on "inferring",
# and the original customer message, customize the email
sentiment = "negative"

# review for a blender
review = f"""
So, they still had the 17 piece system on seasonal \
sale for around $49 in the month of November, about \
half off, but for some reason (call it price gouging) \
around the second week of December the prices all went \
up to about anywhere from between $70-$89 for the same \
system. And the 11 piece system went up around $10 or \
so in price also from the earlier sale price of $29. \
So it looks okay, but if you look at the base, the part \
where the blade locks into place doesn’t look as good \
as in previous editions from a few years ago, but I \
plan to be very gentle with it (example, I crush \
very hard items like beans, ice, rice, etc. in the \ 
blender first then pulverize them in the serving size \
I want in the blender then switch to the whipping \
blade for a finer flour, and use the cross cutting blade \
first when making smoothies, then use the flat blade \
if I need them finer/less pulpy). Special tip when making \
smoothies, finely cut and freeze the fruits and \
vegetables (if using spinach-lightly stew soften the \ 
spinach then freeze until ready for use-and if making \
sorbet, use a small to medium sized food processor) \ 
that you plan to use that way you can avoid adding so \
much ice if at all-when making your smoothie. \
After about a year, the motor was making a funny noise. \
I called customer service but the warranty expired \
already, so I had to buy another one. FYI: The overall \
quality has gone done in these types of products, so \
they are kind of counting on brand recognition and \
consumer loyalty to maintain sales. Got it in about \
two days.
"""
prompt = f"""
You are a customer service AI assistant.
Your task is to send an email reply to a valued customer.
Given the customer email delimited by ```, \
Generate a reply to thank the customer for their review.
If the sentiment is positive or neutral, thank them for \
their review.
If the sentiment is negative, apologize and suggest that \
they can reach out to customer service. 
Make sure to use specific details from the review.
Write in a concise and professional tone.
Sign the email as `AI customer agent`.
Customer review: ```{review}```
Review sentiment: {sentiment}
"""
response = get_completion(prompt)
print(response)
```
**客戶評論回應案例**
我們將使用語言模型生成對客戶評論的個性化回應。給定客戶評論和情感，我們將生成定制回應。我們已經從評論中提取出情感，並根據情感定制回應。指令是：“你是一個客戶服務AI助手。你的任務是向尊貴的客戶發送電子郵件回覆。根據客戶電子郵件生成回覆，感謝客戶的評論。如果情感是正面或中立的，感謝他們的評論。如果情感是負面的，道歉並建議他們聯繫客戶服務。”我們將使用具體的評論細節，用簡潔專業的語氣書寫，並簽名為'AI客戶代理'。
```
prompt = f"""
You are a customer service AI assistant.
Your task is to send an email reply to a valued customer.
Given the customer email delimited by ```, \
Generate a reply to thank the customer for their review.
If the sentiment is positive or neutral, thank them for \
their review.
If the sentiment is negative, apologize and suggest that \
they can reach out to customer service. 
Make sure to use specific details from the review.
Write in a concise and professional tone.
Sign the email as `AI customer agent`.
Customer review: ```{review}```
Review sentiment: {sentiment}
"""
response = get_completion(prompt, temperature=0.7)
print(response)
```
**使用溫度參數**
“溫度”參數允許我們改變模型回應的多樣性。溫度為零時，模型將始終選擇最有可能的下一個詞。較高的溫度會使模型選擇不太可能的詞。一般來說，當構建需要可預測回應的應用時，建議使用溫度為零。如果你想以更創意的方式使用模型，可能希望使用更高的溫度。

**實驗不同溫度**
我們將使用與剛才相同的提示，但嘗試使用更高的溫度生成電子郵件。我們將會看到使用不同溫度時，回應是如何變化的。例如，我們可以使用溫度為0.7，這將會產生不同的電子郵件回應。

總結
較高溫度下模型的輸出更加隨機。可以將高溫度下的助理視為更容易分心但可能更具創造性。下一個視頻中，我們將討論更多關於大型語言模型的激動人心的事情，並將轉向“轉換”。例如，如何將一段文本轉換成另一段文本，如將其翻譯成不同的語言。讓我們繼續下一個視頻。
- [胖胖](/9x0mfyJoT-OreOxFYlvPVw)


### Chatbot**建立自定義聊天機器人** by Joyce

使用大型語言模型之一個激動人心的特點是，你可以只需適量的努力就能建立自定義的聊天機器人。ChatGPT的網頁介面提供了一個與大型語言模型進行對話的界面，但你也可以利用大型語言模型來建立自己的自定義聊天機器人，比如作為AI客戶服務代理或餐廳的AI點餐員。在這個視頻中，你將學習如何自己做到這一點。

**OpenAI聊天完成格式的組件**
首先，我們將進行通常的設置，設置OpenAI Python包。像ChatGPT這樣的聊天模型實際上被訓練用來接收一系列消息作為輸入，並返回模型生成的消息作為輸出。雖然聊天格式旨在使多輪對話變得容易，但我們也看到它對於單輪任務同樣有用。接下來，我們將定義兩個輔助函數：我們一直在視頻中使用的“get_completion”函數，以及將要使用的另一個輔助函數。
```
import os
import openai
from dotenv import load_dotenv, find_dotenv
_ = load_dotenv(find_dotenv()) # read local .env file

openai.api_key  = os.getenv('OPENAI_API_KEY')


```
**聊天機器人的設置**
在這個視頻中，我們將使用不同的輔助函數，而不是輸入單一提示並獲得單一完成，我們將傳入一系列消息，這些消息可以來自不同的角色。例如，我們將展示系統消息的一個例子，它作為對話的整體指導，並在用戶和助手之間交替進行。
```
def get_completion(prompt, model="gpt-3.5-turbo"):
    messages = [{"role": "user", "content": prompt}]
    response = openai.ChatCompletion.create(
        model=model,
        messages=messages,
        temperature=0, # this is the degree of randomness of the model's output
    )
    return response.choices[0].message["content"]

def get_completion_from_messages(messages, model="gpt-3.5-turbo", temperature=0):
    response = openai.ChatCompletion.create(
        model=model,
        messages=messages,
        temperature=temperature, # this is the degree of randomness of the model's output
    )
#     print(str(response.choices[0].message))
    return response.choices[0].message["content"]
    
```

**使用消息進行對話**
現在，我們將使用這些消息進行一次對話。我們將使用新的輔助函數從消息中獲得完成。系統消息示例是：“你是一個會說莎士比亞式語言的助手”。然後用戶消息是“告訴我一個笑話”，“為什麼雞過馬路？”和“我不知道”。我們將運行這些消息並獲得回應。
```
messages =  [  
{'role':'system', 'content':'You are an assistant that speaks like Shakespeare.'},    
{'role':'user', 'content':'tell me a joke'},   
{'role':'assistant', 'content':'Why did the chicken cross the road'},   
{'role':'user', 'content':'I don\'t know'}  ]
 response = get_completion_from_messages(messages, temperature=1)
print(response)   
```
```
messages =  [  
{'role':'system', 'content':'You are friendly chatbot.'},    
{'role':'user', 'content':'Hi, my name is Isa'}  ]
response = get_completion_from_messages(messages, temperature=1)
print(response)
```
```
messages =  [  
{'role':'system', 'content':'You are friendly chatbot.'},    
{'role':'user', 'content':'Yes,  can you remind me, What is my name?'}  ]
response = get_completion_from_messages(messages, temperature=1)
print(response)
```
```
messages =  [  
{'role':'system', 'content':'You are friendly chatbot.'},
{'role':'user', 'content':'Hi, my name is Isa'},
{'role':'assistant', 'content': "Hi Isa! It's nice to meet you. \
Is there anything I can help you with today?"},
{'role':'user', 'content':'Yes, you can remind me, What is my name?'}  ]
response = get_completion_from_messages(messages, temperature=1)
print(response)
```
**建立訂單機器人**
現在，你將建立自己的聊天機器人，名為“OrderBot”。我們將自動收集用戶提示和助手回應，以建立這個“OrderBot”。它將在比薩餐廳接受訂單。首先，我們將定義一個輔助函數來收集我們的用戶消息，然後將其附加到名為“context”的列表中，並在每次呼叫模型時使用該context。
```
def collect_messages(_):
    prompt = inp.value_input
    inp.value = ''
    context.append({'role':'user', 'content':f"{prompt}"})
    response = get_completion_from_messages(context) 
    context.append({'role':'assistant', 'content':f"{response}"})
    panels.append(
        pn.Row('User:', pn.pane.Markdown(prompt, width=600)))
    panels.append(
        pn.Row('Assistant:', pn.pane.Markdown(response, width=600, style={'background-color': '#F6F6F6'})))
 
    return pn.Column(*panels)

```
**使用對話機器人**
我們將設置並運行一個界面來展示Autobot。context包含一個包含菜單的系統消息。每次調用語言模型時，我們都將使用相同的context，並且context會隨著時間積累。
```
import panel as pn  # GUI
pn.extension()

panels = [] # collect display 

context = [ {'role':'system', 'content':"""
You are OrderBot, an automated service to collect orders for a pizza restaurant. \
You first greet the customer, then collects the order, \
and then asks if it's a pickup or delivery. \
You wait to collect the entire order, then summarize it and check for a final \
time if the customer wants to add anything else. \
If it's a delivery, you ask for an address. \
Finally you collect the payment.\
Make sure to clarify all options, extras and sizes to uniquely \
identify the item from the menu.\
You respond in a short, very conversational friendly style. \
The menu includes \
pepperoni pizza  12.95, 10.00, 7.00 \
cheese pizza   10.95, 9.25, 6.50 \
eggplant pizza   11.95, 9.75, 6.75 \
fries 4.50, 3.50 \
greek salad 7.25 \
Toppings: \
extra cheese 2.00, \
mushrooms 1.50 \
sausage 3.00 \
canadian bacon 3.50 \
AI sauce 1.50 \
peppers 1.00 \
Drinks: \
coke 3.00, 2.00, 1.00 \
sprite 3.00, 2.00, 1.00 \
bottled water 5.00 \
"""} ]  # accumulate messages


inp = pn.widgets.TextInput(value="Hi", placeholder='Enter text here…')
button_conversation = pn.widgets.Button(name="Chat!")

interactive_conversation = pn.bind(collect_messages, button_conversation)

dashboard = pn.Column(
    inp,
    pn.Row(button_conversation),
    pn.panel(interactive_conversation, loading_indicator=True, height=300),
)

dashboard
```

**創建JSON訂單摘要**
最後，我們可以要求模型基於對話創建一個可以發送給訂單系統的JSON摘要。這就是建立自己的訂單聊天機器人的全部內容。請隨意自定義它，並嘗試改變系統消息以改變聊天機器人的行為，讓它扮演不同的角色和擁有不同的知識。
```
messages =  context.copy()
messages.append(
{'role':'system', 'content':'create a json summary of the previous food order. Itemize the price for each item\
 The fields should be 1) pizza, include size 2) list of toppings 3) list of drinks, include size   4) list of sides include size  5)total price '},    
)
 #The fields should be 1) pizza, price 2) list of toppings 3) list of drinks, include size include price  4) list of sides include size include price, 5)total price '},    

response = get_completion_from_messages(messages, temperature=0)
print(response)
```
- [胖胖](/4M8n2LWuSC20KFJ3vyecFQ)


### Conclusion

恭喜你完成了這個短期課程。總結來說，在這個課程中，你學到了兩個關鍵的提示原則：寫清晰具體的指示，以及在合適的時候給模型一些思考時間。你還學會了如何進行迭代式提示開發，以及擁有一個適合你應用的提示過程是關鍵的。我們還介紹了大型語言模型的一些功能，這些功能對許多應用程序都很有用，特別是摘要、推斷、轉換和擴展。你也看到了如何建立一個自定義聊天機器人。在這個短期課程中，你學到了很多，我希望你喜歡這些材料。

我們希望你能想出一些自己可以建立的應用程序。請試試看，並告訴我們你的成果。沒有什麼應用程序太小，從一個非常小的項目開始也沒關係，它可能只有一點點實用性，或者甚至可能根本沒有用，只是一些有趣的東西。

是的，我發現使用這些模型實際上非常有趣，所以去玩吧！我同意，這是一個不錯的周末活動，憑藉經驗而言。並且，請使用你第一個項目的經驗來建立一個更好的第二個項目，也許甚至是更好的第三個項目，等等。這也是我自己使用這些模型逐漸成長的方式。

或者如果你已經有一個更大的項目想法，那就大膽去做吧。作為提醒，這些大型語言模型是一項非常強大的技術，所以我們要求你負責任地使用它們，並且只建造那些將產生積極影響的東西。

是的，我完全同意。我認為在這個時代，建立AI系統的人可以對其他人產生巨大的影響。因此，我們比以往任何時候都更需要負責任地使用這些工具。我認為基於大型語言模型的應用程序開發是一個非常令人興奮且不斷發展的領域。現在你已經完成了這門課程，我認為你現在擁有了讓你能夠建立很少人今天知道如何建立的東西的豐富知識。所以，我希望你也幫助我們傳播這個消息，鼓勵其他人也來上這門課程。最後，我希望你在這門課程中玩得開心，並感謝你完成了這門課程。Isa和我都期待聽到你建立的驚人事物。
- [胖胖](/KgqnELPpQEilLOjlHGTarg)


### 其它補充資料
*  Joyce
[什麼是基於人類反饋的強化學習 (RLHF)](https://www.unite.ai/zh-TW/what-is-reinforcement-learning-from-human-feedback-rlhf/)
[RAG 檢索增強生成介紹](https://https://ithelp.ithome.com.tw/articles/10327895)
[艾倫·圖靈是誰？](https://www.unite.ai/zh-TW/%E4%BB%80%E9%BA%BC%E6%98%AF%E5%9C%96%E9%9D%88%E6%B8%AC%E8%A9%A6%E4%BB%A5%E5%8F%8A%E7%82%BA%E4%BB%80%E9%BA%BC%E5%AE%83%E5%BE%88%E9%87%8D%E8%A6%81/)

* LeoHung
[ChatGPT和高級提示工程：推動AI發展](https://www.unite.ai/zh-TW/chatgpt%E9%AB%98%E7%B4%9A%E6%8F%90%E7%A4%BA%E5%B7%A5%E7%A8%8B/)
[將您的ChatGPT技巧提高到新的水平](https://medium.com/%E7%B2%BE%E9%81%B8%E6%95%B8%E4%BD%8D%E8%A1%8C%E9%8A%B7%E6%96%87%E7%AB%A0-%E4%B8%AD%E6%96%87/%E5%B0%87%E6%82%A8%E7%9A%84chatgpt%E6%8A%80%E5%B7%A7%E6%8F%90%E9%AB%98%E5%88%B0%E6%96%B0%E7%9A%84%E6%B0%B4%E5%B9%B3-chatgpt%E6%8F%90%E7%A4%BA%E5%B7%A5%E7%A8%8B-prompt-engineering-b8045e7a67ca)
[人工智慧的風險是真實存在的- 比爾蓋茨](https://mp.weixin.qq.com/s/dTp4ETiF8SR2xflZ1TSLew)
[OpenAI官方ChatGPT提示工程- 最佳實務11篇（大合集）](https://ananashub.com/2023/10/07/openai%E5%AE%98%E6%96%B9chatgpt%E6%8F%90%E7%A4%BA%E5%B7%A5%E7%A8%8B-%E6%9C%80%E4%BD%B3%E5%AE%9E%E8%B7%B511%E7%AF%87%EF%BC%88%E5%A4%A7%E5%90%88%E9%9B%86%EF%BC%89/)



- [陳楊文](/OB501hjZSZOsXCuL5hkhaQ)
- [胖胖](/XEbE98oBRKeV9rLZOnCdsw)

---

## 1/9
* Joyce
* 因為擔心版面佔太多,我把課程的中文翻譯獨立寫一份 HACKMD
* 給對聽英文課有點不適應的人,希望在共讀過程中,有我的中文翻譯,可以幫助大家邊聽課邊了解
*[大型語言模型實作讀書會第二組 Joyce筆記](https://hackmd.io/6Ph0wa75RKScbkkhiofJCg)
---
- [胖胖](https://hackmd.io/@2YdnUWD8RpK3RWxZlSeg8Q/Hy5FgCwua)
---


# Building Systems with the ChatGPT API

 
---
## 第1次小組會議紀錄 by jing
12/25PM21:00~22:00
1.ㄧ月二日本組子題講師3位，各20分鐘：
1.1 曉婷 about API key / theme review
1.2 Atom about a small LLM sample
1.3 Eric about how to improve prompt engineering 
2.讀書會目標還是要促進整體的程式能力與做專案所需的技術；不過，本組負責的單元－ChatGPT Prompt Engineering for Developers，偏導讀性質，提綱契要，可著重在共通性prompt碼；教學內容和教材準備follow讀書會的學習目標，並以本組負責的單元為主，請講師自行準備PPT。
3.謝謝雅娟翻譯及整理QA；本組組員關於各組單元的問題和學習心得仍請值週副組長彙整和提報（給負責組？）
4.HackMD共筆原則：
4.1大家都可編寫（按左上編輯鍵）、表述。
4.2盡量不要改別人筆記。
4.3以“By 識別號或名”為始，已“（筆記時間）”為終。
5.每週ㄧ21:00～22:00小組會議。
6.想想看How could push everybody to  be engaged 
(1121226AM10:44)

---

## 1/16
# How Diffusion Models Work



- [胖胖](https://hackmd.io/@2YdnUWD8RpK3RWxZlSeg8Q/SJvRMRDdT)

---
# 常用連結
- [學習記錄表](https://docs.google.com/spreadsheets/d/1b5frS7nqzr22xfA3kMQQ49EbchN6t3r5/edit#gid=1763521204)




---
# 專題報告(TBD)






---
# 參考資料

