# Prompt Engineering

Prompt Engineering - 提示工程

生成式 AI 應用程式傳回的回應品質不僅取決於模型本身，也取決於其所提供的提示類型。 「提示工程」一詞描述提示改善的流程。 設計應用程式的開發人員和使用這些應用程式的取用者，都可以考慮使用提示工程來改善生成式 AI 的回應品質。

提示是我們告知應用程式預期執行操作的方式。 工程師可以利用提示來新增程式的指示。 例如，開發人員可以為教師建置生成式 AI 應用程式，以建立與學生閱讀文字相關的複選問題。 在應用程式開發期間，開發人員可以新增其他規則，定義程式應該根據收到的提示執行哪些操作。

為什麼要使用英文 prompt 而不使用中文提問?

> 1. 英文的訓練語料庫占比超過93%，中文約0.04%，使用英文提問時，它能返回更準確的解答。
> 2. ChatGPT在一次輸入中，最多處理4096 token——超過上限的任何字符都將被忽略而不會顯示訊息。相較之下，英文的token使用量少，使用英文提問時，它能給予更多篇幅的答案(中文消耗的token約是英文兩倍)。詳細的可參考[OpenAI token解答](https://help.openai.com/en/articles/4936856-what-are-tokens-and-how-to-count-them)，以及使用[官方的token計算器](https://platform.openai.com/tokenizer)
> 3. 返回英文答案後，再使用[ChatGPT翻譯成中文](https://domychatgpt.org/#act-as-an-english-translator-and-improver)就行了。例如：**Please write in Traditional Chinese language.**

##### Prompt Fundamentals

- [Learning Path to Become a Prompt Engineer (analyticsvidhya.com)](https://www.analyticsvidhya.com/blog/2024/07/prompt-engineer/)
- [Microsoft Learn: Prompt engineering techniques](https://learn.microsoft.com/en-us/azure/ai-services/openai/concepts/prompt-engineering?tabs=chat)
- [提問(Prompt)的藝術：如何引導AI準確回答你的需求. 本文內容難度： ★ ☆ ☆ ☆ ☆ | by Simon Liu | InfuseAI](https://blog.infuseai.io/prompt-introduction-concept-d45fc79576d7)
- [提示工程指南 | Prompt Engineering Guide (promptingguide.ai)](https://www.promptingguide.ai/zh)
- [提示工程指南 | Learning Prompting](https://learnprompting.org/zh-tw/docs/introduction)
- [gemini-for-google-workspace-prompting-guide-101.pdf](https://osslab.tw/attachments/88)
    - Video: [Google’s NEW Prompting Guide is Incredible! - YouTube](https://www.youtube.com/watch?v=o64Mv-ArFDI)
- [Google 提示词最佳实践宝典导航](https://q9yxq74um5.app.yourware.so/)

##### Prompt Tips

- [Prompt library (anthropic.com)](https://docs.anthropic.com/claude/prompt-library)
- [Prompt 高阶 | 链与框架](https://www.bestblogs.dev/article/f5ff2e)
- [ChatGPT Prompt : 各職業詠唱大全(超過100個案例) | Domyweb多米](https://domyweb.org/chatgpt/)
- [LangGPT: Empowering everyone to become a prompt expert!🚀 Structured Prompt，Language of GPT, 结构化提示词，结构化Prompt (github.com)](https://github.com/langgptai/LangGPT)
- [⭐LangGPT 结构化提示词 - 飛書雲端文件 (feishu.cn)](https://langgptai.feishu.cn/wiki/RXdbwRyASiShtDky381ciwFEnpe)
- [世界上覆盖最全的优秀Qwen提示语大全](https://github.com/XiaomingX/awesome-qwen-prompt-insight)
- [Promptup.net](https://promptup.net) - Store and Share your prompts

提示詞框架

- [你要牢记的四个常用AI提示词框架：ICIO、CRISPE、BROKE、RASCEF，有助于获取更加稳定和高质量的内容-阿里云开发者社区 (aliyun.com)](https://developer.aliyun.com/article/1490356)
- [Prompt工程全攻略：15+Prompt框架一网打尽（BROKE、COAST、LangGPT）、学会提示词让大模型更高效-腾讯云开发者社区-腾讯云 (tencent.com)](https://cloud.tencent.com/developer/article/2400512)

##### Prompt Dev

- [Llama 2 Prompt Engineering — Extracting Information From Articles Examples | by Eliran Boraks | Medium](https://medium.com/@eboraks/llama-2-prompt-engineering-extracting-information-from-articles-examples-45158ff9bd23)
- [Advancing Chatbot Intelligence: Unlocking the Power of Step-Back Prompting | by Csakash | Medium](https://medium.com/@csakash03/advancing-chatbot-intelligence-unlocking-the-power-of-step-back-prompting-bb3ba0dc72e6)
- [Prompt Engineering Techniques: Comprehensive Repository for Development and Implementation](https://github.com/NirDiamant/Prompt_Engineering)

##### Prompt Generator

- [quality-prompts](https://github.com/sarthakrastogi/quality-prompts)
- [prompt-optimizer](https://github.com/linshenkx/prompt-optimizer)
- [SalesforceAIResearch / promptomatix](https://github.com/SalesforceAIResearch/promptomatix)

##### P-T-C-F

- **Persona (人物/角色)**：設定 AI 應扮演的角色、職位或身分。例如：你是一位 \[產業\] 的專案經理。
- **Task (任務)**：明確指出您希望 AI 執行的具體工作。這是提示詞中最重要的部分，請務必包含明確的動詞或指令（例如：撰寫、總結、改變語氣等）。
- **Context (背景)**：提供相關的背景細節、參考資料或情境，讓 AI 根據這些資訊生成內容。例如：根據 \[相關專案文件的細節\]。
- **Format (輸出格式)**：指定輸出的形式或呈現方式。例如：「限制使用列點方式呈現」 或「整理成表格格式」。

> 範例：\[角色\] 你是一位 \[某產業\] 的專案經理。 \[任務\] 請草擬一封給 \[某對象\] 的執行摘要郵件， \[情境\] 內容根據 \[相關專案文件的細節\]。 \[格式\] 請以條列方式呈現。

##### P-A-R-T-S

Write an effective promt using P-A-R-T-S

**Persona: Identify your role**

Examples:

- I am a Math Department Lead analyzing resource gaps.
- I am a Spanish educator designing activities on cultural immersion.

**Aim: State your objective**

Examples:

- Brainstorm ideas for \[enter context\].
- Create an assessment on \[enter context\].

**Recipients: Specify the audience**

Examples:

- School budget committee
- Sophomores with at least four years of Spanish
- 9th grade life skills educators

**Theme: Describe the style, tone, and any related parameters**

Examples:

- Use a formal voice.
- Write no more than 50 words.
- Include pop culture references.
- Be enthusiastic.

**Structure: Note the desired format of the output**

Examples: Ask the AI tool to

- Use bullet points.
- Include metaphors or analogies.
- Create a quiz or game.
- Write code.

##### CoT - Chain of Thought

- YT: [Cursor编程实战演示——用思维链方法让AI写AI提示词 - YouTube](https://www.youtube.com/watch?v=qfRjKCJ70HY)

`我要AI幫我{XXXX}，請幫我用Chain-of-Thought來寫AI提示詞。`

```
我要AI幫我從英文翻譯成中文(先直譯，再反思，再意譯)，請幫我用Chain-of-Thought來寫AI提示詞。
```

```
我希望翻譯的英文句子如下，請使用上面的提示詞翻譯。
```

##### Cheat Sheet

- [the\_prompt\_engineering\_cheat\_sheet.pdf](https://osslab.tw/attachments/89)

[![chatgpt_prompt.jpg](https://osslab.tw/uploads/images/gallery/2024-07/scaled-1680-/chatgpt-prompt.jpg)](https://osslab.tw/uploads/images/gallery/2024-07/chatgpt-prompt.jpg)