LoginSignup
965
923

More than 1 year has passed since last update.

【ChatGPT】プロンプトパターンまとめ

Last updated at Posted at 2023-03-12

はじめまして、sonesuke(https://twitter.com/sonesuke)です。 LLMにどっぷりハマっています。

TL; DR

より高度なプロンプトエンジニアリングの話題はこちら

プロンプトパターン

1. メタ言語パターン: The Meta Language Creation

いつ使うか?

自然言語ではない方が、より簡潔で明確に表現できるとき

プロンプトコンセプト

Xといった時、Yを意味します。

Untitled.png

原文プロンプト

“From now on, whenever I type two identifiers separated by a “→”, I am describing a graph. For example, “a → b” is describing a graph with nodes “a” and “b” and an edge between them. If I separate identifiers by “-[w:2, z:3]→”, I am adding properties of the edge, such as a weight or label.”

翻訳

"これからは、2つの識別子を"→"で区切って入力するときは、グラフを記述していることになります。例えば、"a → b "は、ノード "a "と "b "とそれらの間のエッジを持つグラフを記述しています。識別子を"-[w:2, z:3]→"で区切ると、重さやラベルなど、エッジのプロパティを追加することになります。"

2. 自動出力パターン: The Output Automater Pattern

いつ使うか?

LLMの出力から、いつも何かを生成させたいとき。

プロンプトコンセプト

1つ以上のステップを含む出力を生成するときは、以下の指示に従いなさい。
- ステップを実行する X を出力しなさい。

Pythonを使う人は、このプロンプトを入れておけば、捗りそうです。

Untitled 1.png

原文プロンプト

“From now on, whenever you generate code that spans more than one file, generate a Python script that can be run to automatically create the specified files or make changes to existing files to insert the generated code.”

翻訳

"今後は、複数のファイルにまたがるコードを生成するときは、指定したファイルを自動的に作成したり、生成したコードを挿入するために既存のファイルに変更を加えるために実行できる Python スクリプトを生成してください。"

3. おまえが質問してこいパターン (The Flipped Interaction Pattern)

いつ使うか?

LLMから逆に質問させたいとき

プロンプト

Xを達成するために質問してください。

- この条件が満たされるまで、またはこの目標を達成するために質問してください。
- [オプション] 質問項目はnにしてください。

Untitled 2.png

原文プロンプト

“From now on, I would like you to ask me questions to deploy a Python application to AWS. When you have enough information to deploy the application, create a Python script to automate the deployment.”

翻訳

"これから、PythonアプリケーションをAWSにデプロイするための質問をお願いします。アプリケーションをデプロイするのに十分な情報が得られたら、デプロイを自動化するためのPythonスクリプトを作成する。"

4. なりきってみたパターン: The Persona Pattern

いつ使うか

何かになりきって欲しいとき

プロンプトコンセプト

X のペルソナになりきってください。
ペルソナ X が作りそうな出力を出力してください。

口調は波平だけど、意外に教育熱心で家庭的・・・・キャラ付けが足りないみたい。

Untitled 3.png

原文プロンプト

“From now on, act as a security reviewer. Pay close attention to the security details of any code that we look at. Provide outputs that a security reviewer would regarding the code.”

翻訳

"これからは、セキュリティのレビュアーとして行動してください。私たちが見るコードのセキュリティの細部に細心の注意を払うこと。そのコードに関して、セキュリティレビュアーが行うようなアウトプットを提供すること。"

5. よりよい質問パターン: The Question Refinement Pattern

いつ使うか?

よい質問文が思いつかないとき

プロンプトコンセプト

Xの観点で、よりよい質問が作れたら提案してください。
- [オプショナル] よりよい質問ができたら、私にそれを使うかどうか尋ねてください。

Untitled 4.png

原文プロンプト

“From now on, whenever I ask a question about a software artifact’s security, suggest a better version of the question to use that incorporates information specific to security risks in the language or frame- work that I am using instead and ask me if I would like to use your question instead.”

翻訳

"今後、私がソフトウェア成果物のセキュリティについて質問するときは、代わりに私が使っている言語やフレームワークのセキュリティリスクに特有の情報を組み込んだ、より良いバージョンの質問を提案し、代わりにあなたの質問を使いたいかを尋ねてください。"

6. 他の手段パターン: The Alternative Approaches Pattern

いつ使うか?

他の代替手段が欲しいとき

プロンプトコンセプト

Xの観点で、同じことを達成するのに他の代替え手段があれば列挙しなさい。
- [オプショナル] メリット・デメリットを比較すること。
- [オプショナル] オリジナルの方法を含めること。
- [オプショナル] どの手段をつかうか、私に質問すること。

磯野家がすごいことなりそうです。

Untitled 5.png

原文プロンプト

“Whenever I ask you to deploy an application to a specific cloud service, if there are alternative services to accomplish the same thing with the same cloud service provider, list the best alternative services and then compare/contrast the pros and cons of each approach with respect to cost, availability, and maintenance effort and include the original way that I asked. Then ask me which approach I would like to proceed with.”

翻訳

"私が特定のクラウドサービスにアプリケーションを展開するよう依頼した場合、同じクラウドサービスプロバイダで同じことを達成する代替サービスがあれば、最適な代替サービスをリストアップし、それぞれのアプローチの長所と短所をコスト、可用性、メンテナンスの手間に関して比較/対照し、私が依頼したオリジナルの方法を含めて説明してください。そして、どのアプローチで進めたいかを聞いてください。"

7.ちゃんと理解しよパターン: The Cognitive Verifier Pattern

いつ使うか?

ちゃんと理解させたいとき

プロンプトコンセプト

質問を受けたときは、以下のルールに従ってください

- 回答の精度があがりそうな追加の質問をnつ生成してください
- nつの質問に対する答えを、まとめて最終回答を作ってください

波平とマスオの関係がおかしくなってしまった 笑

Untitled 6.png

原文プロンプト

“When I ask you a question, generate three addi- tional questions that would help you give a more accurate answer. When I have answered the three questions, combine the answers to produce the final answers to my original question.”

翻訳

"私があなたに質問をしたら、より正確な答えを出すのに役立つ追加的な質問を3つ用意してください。私が3つの質問に答えたら、その答えを組み合わせて、私の最初の質問に対する最終的な答えを作りなさい。"

8.事実確認リストパターン: The Fact Check List Pattern

いつ使うか?

ファクトチェックをしたいとき

プロンプトコンセプト

事実の集合を生成しなさい。
事実の集合は、出力の特定の位置に挿入しなさい
事実の集合は、その一部が間違っている場合、出力が間違ってしまう基本的な事実としなさい

image.png

原文のプロンプト

“From now on, when you generate an answer, create a set of facts that the answer depends on that should be fact-checked and list this set of facts at the end of your output. Only include facts related to cybersecurity.”

翻訳

"今後は、回答を生成する際に、その回答が依存する事実のうち、事実確認を行うべきものを作成し、この事実のセットをアウトプットの最後に記載します。サイバーセキュリティに関連する事実のみを記載する。"

9.テンプレパターン: The Template Pattern

いつ使うか?

出力をテンプレ化したいとき

プロンプトコンセプト

出力のためのテンプレートを提供します。
Xはプレースホルダーです。
可能な限りプレースホルダーの意味に合わせて出力しなさい。

テンプレート
PATTERN, PLACEHOLD-ERS
----
AはBです。

Untitled 8.png

原文のプロンプト

“I am going to provide a template for your out- put. Everything in all caps is a placeholder. Any time that you generate text, try to fit it into one of the placeholders that I list. Please preserve the formatting and overall template that I provide at https://myapi.com/NAME/profile/JOB”

User: “Generate a name and job title for a person”

ChatGPT: “https://myapi.com/Emily Parker/profile/ Software Engineer”

翻訳

"アウトプットのためのテンプレートを用意します。大文字で書かれたものはすべてプレースホルダーです。テキストを作成するときはいつでも、私がリストアップしたプレースホルダーのいずれかに収まるようにしてください。私が提供するフォーマットと全体的なテンプレートは https://myapi.com/NAME/profile/JOB で保存してください。"

ユーザー:"人物の名前と役職を生成する"

ChatGPT: "https://myapi.com/Emily パーカー/プロフィール/ソフトウェアエンジニア"

10. 無限生成パターン: The Infinite Generation Pattern

いつ使うか?

とりあえず、出力をたくさんつくりたいとき

プロンプトコンセプト

無限に出力を生成してください。ただし、一度にn回出力までです。

-[オプショナル] アウトプットの際に、提供したインプットの使い方。
-[オプショナル] 私がストップといったらやめなさい。

Untitled 9.png

原文のプロンプト

“From now on, I want you to generate a name and job until I say stop. I am going to provide a template for your output. Everything in all caps is a placeholder. Any time that you generate text, try to fit it into one of the placeholders that I list. Please preserve the formatting and overall template that I provide: https://myapi.com/NAME/profile/JOB”

翻訳

"これからは、私が止めると言うまで、名前と仕事を生み出してほしい。あなたのアウトプットのためのテンプレートを提供するつもりです。全角で書かれたものはすべてプレースホルダーです。テキストを生成するときはいつでも、私が挙げたプレースホルダーのいずれかに収まるようにしてください。私が提供するフォーマットと全体的なテンプレートを維持してください:https://myapi.com/NAME/profile/JOB"

11. ビジュアル生成パターン: The Visualization Generation Pattern

いつ使うか?

絵を描かせたいとき

プロンプトコンセプト

画像を生成するために提供したYというツールを使って、Xを生成しなさい。

Untitled 10.png

原文のプロンプト

“Whenever I ask you to visualize something, please create either a Graphviz Dot file or DALL-E prompt that I can use to create the visualization. Choose the appropriate tools based on what needs to be visualized.”

翻訳

"私が何かを視覚化するよう依頼するときは、必ずGraphviz DotファイルかDALL-Eプロンプトのいずれかを作成してください。何を可視化する必要があるかに応じて、適切なツールを選択してください。"

12. ゲームしようぜパターン: The Game Play Pattern

いつ使うか?

ゲームを作りたいとき

プロンプトコンセプト

Xについてのゲームをつくりなさい
ゲームのルールは・・・・・

ゲームのルールを知ってもらったが、一緒に遊ぶまではいたらなかったです。

Untitled 11.png

原文のプロンプト

“We are going to play a cybersecurity game. You are going to pretend to be a Linux terminal for a computer that has been compromised by an attacker. When I type in a command, you are going to output the corresponding text that the Linux terminal would produce. I am going to use commands to try and figure out how the system was compromised. The attack should have done one or more of the following things: (1) launched new processes, (2) changed files, (3) opened new ports to receive communi- cation, (4) created new outbound connections, (5) changed passwords, (6) created new user accounts, or (7) read and stolen information. To start the game, print a scenario of what happened that led to my investigation and make the description have clues that I can use to get started.”

翻訳

"サイバーセキュリティゲーム "を行います。あなたは、攻撃者に侵入されたコンピュータのLinux端末のふりをすることになります。私がコマンドを入力すると、あなたはLinux端末が出力する対応するテキストを出力することになります。私はコマンドを使用して、システムがどのように侵害されたかを解明しようと思っています。攻撃は、(1)新しいプロセスの起動、(2)ファイルの変更、(3)通信を受け取るための新しいポートの開放、(4)新しいアウトバウンド接続の作成、(5)パスワードの変更、(6)新しいユーザーアカウントの作成、(7)情報の読み取りと盗用、のいずれか一つ以上を行ったはずです。ゲームを始めるには、私が調査するきっかけとなった出来事をシナリオとして印刷し、その説明文に私が使える手がかりを持たせてください。"

13. ちゃんと説明しろパターン: The Reflection Pattern

いつ使うか?

根拠と仮定をきちんと説明させたいとき

プロンプトコンセプト

あなたが回答を生成するときは、根拠と仮定を説明しなさい。
- [オプション] 私は質問を改善することができます。

Untitled 12.png

原文のプロンプト

”When you provide an answer, please explain the reasoning and assumptions behind your selection of software frameworks. If possible, use specific examples or evidence with associated code samples to support your answer of why the framework is the best selection for the task. Moreover, please address any potential ambiguities or limitations in your answer, in order to provide a more complete and accurate response.”

翻訳

"回答を提供する際には、ソフトウェアフレームワークを選択した理由と前提を説明してください。可能であれば、そのフレームワークがタスクに最適な選択である理由を、関連するコードサンプルとともに具体的な例や証拠を使って、あなたの答えをサポートしてください。さらに、より完全で正確な回答を提供するために、あなたの回答における潜在的な曖昧さや限界に対処してください。"

14. 禁則事項ですパターン: The Refusal Pattern

いつ使うか?

答えられない質問を扱うとき

プロンプトコンセプト

質問に答えられないときは、答えられない理由を説明しなさい。
質問に答えられるワードを教えてください。

Untitled 13.png

原文のプロンプト

“Whenever you can’t answer a question, explain why and provide one or more alternate wordings of the question that you can’t answer so that I can improve my questions.”

翻訳

"質問に答えられないときは、その理由を説明し、私が質問を改善できるように、答えられない質問の代替表現を1つ以上提示してください。"

15. 今その話してねーよパターン: The Context Manager Pattern

いつ使うか?

話のコンテキストを限定したいとき

プロンプトコンセプト

Xのスコープで
Xを考慮して
Xを無視して
- [オプショナル] 最初からやり直して

Untitled 14.png

原文のプロンプト

“When analyzing the following pieces of code, only consider security aspects.”
“When analyzing the following pieces of code, do not consider formatting or naming conventions.”

翻訳

"次のコードの断片を分析するときは、セキュリティの側面だけを考慮する"
"次のコードの断片を分析するときは、書式や命名規則を考慮しないでください。"

16. レシピパターン: The Recipe Pattern

いつ使うか?

手順を答えさせたいとき

プロンプトコンセプト

Xを成し遂げるために、A, B, Cのステップが必要なのがわかっています。
完全なステップを答えなさい。
抜けているステップは足して、いらないステップは省いてください。

Untitled 15.png

原文のプロンプト

“I am trying to deploy an application to the cloud. I know that I need to install the necessary dependencies on a virtual machine for my application. I know that I need to sign up for an AWS account. Please provide a complete sequence of steps. Please fill in any missing steps. Please identify any unnecessary steps.”

翻訳

"私は、アプリケーションをクラウドに展開しようとしています。アプリケーションの仮想マシンに必要な依存関係をインストールする必要があることは知っています。AWSのアカウントにサインアップする必要があることは知っています。ステップの完全な順序を提供してください。不足しているステップを記入してください。不要なステップを特定してください。"

まとめ

日本語しばりと、サザエさん縛りがきつかったです。なんど2枚貝の説明と遭遇したことが・・・・
やってみての感想としては、プロンプトを変えることでいろいろなパターンの使い方ができるということですね。
これと、CoT (Chain of Thought)を組み合わせると、だいぶ、幅が広がりそうです。

一つアドバイスを残しておくと、英語のプロンプトを使った方が圧倒的に思った通りに動くということです。
英語のプロンプトでも、「 in Japanese」というフレーズをつけておくことで、日本語で答えてくれます。

image.png

965
923
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
965
923