プロンプトエンジニアリング手法の実装

Objective

After completing this lesson, you will be able to 単純なベースラインからプロンプトエンジニアリングを開発および評価するための体系的なアプローチを設計します。

このレッスンでは、高度なプロンプトエンジニアリング技術を使用して LLM 回答のインテリジェンスと精度を向上させる方法について説明します。以前に確立されたベースライン評価に基づいて、SAP Cloud SDK for AI を使用して Few-shot Prompting や Meta-prompting などの強力な戦略を実装し、生成 AI アプリケーションの品質と精度の向上に対する影響を観察する方法を学習します。

Few-Shot プロンプト

推進技術を実装し、結果を評価して速報結果の改善を確認しよう。

以下のコードを使用します。

Python
123456789101112131415161718192021222324252627282930313233343536373839
prompt_10 = Template( messages=[ SystemMessage( """You are an intelligent assistant. Your task is to extract and categorize messages. Here are some example: {{?few_shot_examples}} Use the examples when extract and categorize the following message: Extract and return a json with the follwoing keys and values: - "urgency" as one of {{?urgency}} - "sentiment" as one of {{?sentiment}} - "categories" list of the best matching support category tags from: {{?categories}} Your complete message should be a valid json string that can be read directly and only contain the keys mentioned in the list above. Never enclose it in ```json...```, no newlines, no unnessacary whitespaces."""), UserMessage("{{?input}}") ] ) import random random.seed(42) k = 3 examples = random.sample(dev_set, k) example_template = """<example> {example_input} ## Output {example_output} </example>""" examples = '\n---\n'.join([example_template.format(example_input=example["message"], example_output=json.dumps(example["ground_truth"])) for example in examples]) f_10 = partial(send_request, prompt=prompt_10, few_shot_examples=examples, **option_lists) response = f_10(input=mail["message"]) overall_result["few_shot--llama3.1-70b"] = evalulation_full_dataset(test_set_small, f_10) pretty_print_table(overall_result)

このコードは、緊急度、センチメント、およびサポートカテゴリタグに従ってメッセージを抽出および分類するためのプロンプトテンプレートを作成することを目的としています。開発セットからランダムに選択された例を使用することで、書式設定されたfew-shot 学習プロンプトが生成されます。プロンプトは、特定の入力メッセージを処理および分類するために言語モデルに送信され、モデルの全体的なパフォーマンスが評価され、テーブル形式で表示されます。

以下に、コードの一部の拡張された説明を示します。

  1. ランダムシードの設定: "random.seed(42)" を使用してランダムシードを設定し、例のランダムサンプリングを再現できるようにします。これは、実験および評価における整合性の維持に役立ちます。
  2. サンプリング例: 変数 "k" が 3 に設定され、"dev_set" データセットからのサンプル数を示します。関数 "random.sample(dev_set, k)" では、開発セットから 3 つのランダムな例が選択されます。
  3. 書式設定の例: 選択した例は、テンプレート "example_template" に書式設定されます。各例には、入力メッセージおよび予想される出力が JSON 形式で含まれています。この書式設定された文字列は、"\n---\n" を使用して結合され、一連のまとまった例が作成されます。
  4. 部分関数アプリケーション: "部分" 関数を使用して、生成されたプロンプトと例を "send_request" 関数にバインドし、入力メッセージのみで呼び出すことができる関数 "f_10" を作成します。これにより、必要なコンテキストでモデルに依頼を送信するプロセスが合理化されます。
  5. 要求の送信および評価: スクリプトは、"mail["message"]" からの入力メッセージとともに、"f_10(input=mail["message"])" を使用して要求を送信します。結果は、小さなテストデータセット "test_set_small" に対して保存および評価されます。評価結果は、"overall_result["few_shot--llama3-70b"]" に保存されます。
  6. 出力表示: 最後に、"pretty_print_table(overall_result)" 関数を使用して、書式設定されたテーブルで評価結果を表示することで、結果を解釈しやすくなります。

応答の例:

Code Snippet
12345
0%| | 0/20 [00:00<?, ?it/s] is_valid_json correct_categories correct_sentiment correct_urgency ========================================================================================= basic--llama3.1-70b 100.0% 83.5% 30.0% 70.0% few_shot--llama3.1-70b 100.0% 84.0% 50.0% 90.0%

これは、few-shot プロンプトを実装した後の評価の出力です。

センチメントおよび緊急度の割当の改善を確認することができます。

以前はベースラインを確立しており、テストデータを使用して、絞り込まれたプロンプトの結果とベースラインを評価および比較できるようになりました。

メタプロンプト

ここでは、緊急度やセンチメントなどのさまざまなタグに対するプロンプトの詳細なガイドを作成するためのメタプロンプトを実装します。

以下のコードを使用します。

Python
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
example_template_metaprompt = """<example> {example_input} ## Output {key}={example_output} </example>""" prompt_get_guide = Template( messages=[ SystemMessage( """Here are some example: --- {{?examples}} --- Use the examples above to come up with a guide on how to distinguish between {{?options}} {{?key}}. Use the following format: ``` ### **<category 1>** - <instruction 1> - <instruction 2> - <instruction 3> ### **<category 2>** - <instruction 1> - <instruction 2> - <instruction 3> ... ``` When creating the guide: - make it step-by-step instructions - Consider than some labels in the examples might be in correct - Avoid including explicit information from the examples in the guide The guide has to cover: {{?options}} """ ), UserMessage("{{?input}}") ] ) guides = {} for i, key in enumerate(["categories", "urgency", "sentiment"]): options = option_lists[key] selected_examples_txt_metaprompt = '\n---\n'.join([example_template_metaprompt.format(example_input=example["message"], key=key, example_output=example["ground_truth"][key]) for example in dev_set]) guides[f"guide_{key}"] = send_request(prompt=prompt_get_guide, examples=selected_examples_txt_metaprompt,input=selected_examples_txt_metaprompt, key=key, options=options, _print=False, _model='gpt-4o') print(guides['guide_urgency'])

このコードでは、データセット内のラベル付きの例から、"カテゴリ"、"緊急度"、"センチメント" などのさまざまなカテゴリのステップバイステップガイドが生成されます。

これにより、テキストデータのカテゴリ、緊急度、およびセンチメントを区別するために調整されたガイドが作成されます。特定のテンプレートを使用して例が書式設定され、ステップバイステップの指示を生成するためにこれらの例がモデルに送信されます。ガイドは、提供されている例のパターンに基づいてこれらのカテゴリを区別するのに役立ちます。

詳細な説明:

  1. テンプレート定義:

    • "example_template_metaprompt": サンプルの書式を設定するテンプレートを定義し、例内で入力と出力を構造化する方法を指定します。
    • "prompt_get_guide": プロンプト形式の概要を示し、書式設定された例に基づいてガイドの生成を要求します。また、ガイドの書式および要件も指定されており、ステップバイステップの指示、不適切なラベルの可能性、および例の明示的な複製の回避が含まれます。
  2. ガイド準備:

    • このスクリプトでは、"カテゴリ"、"緊急度"、"センチメント" の 3 つのキーが繰り返されます。
    • キーごとに、"option_lists" から関連オプションが取得されます。
  3. 選択および書式設定の例: キーごとに事前定義されたテンプレートを使用して "dev_set" からの例を書式設定し、入力メッセージおよび対応するグラウンドトゥルースを埋め込みます。

  4. ガイド生成:

    • 書式化されたプロンプトが例とともにモデル (gpt-4o) に送信され、キーごとに指定されたオプションを区別するためのガイドの生成が要求されます。
    • 生成されたガイドはディクショナリ (ガイド) に保存され、各ガイドはそれぞれのキー ("guide_categories"、"guide_emergency"、"guide_sentiment" など) に関連付けられています。

このプロセスにより、さまざまな分類タスクに対して包括的かつ正確な指示ガイドが生成され、テキストデータの正しい分類が容易になります。

コードの最終行には、緊急性に関するガイドが表示されます。

プロンプトで使用できる各緊急カテゴリのルールについて説明するガイドが表示されます。

以下のコードを使用して、これらのガイドをプロンプトで利用します。

Python
12345678910111213141516171819202122232425262728293031
prompt_12 = Template( messages=[ SystemMessage( """You are an intelligent assistant. Your task is to classify messages. This is an explanation of `urgency` labels: --- {{?guide_urgency}} --- This is an explanation of `sentiment` labels: --- {{?guide_sentiment}} --- This is an explanation of `support` categories: --- {{?guide_categories}} --- Giving the following message: Extract and return a json with the following keys and values: - "urgency" as one of {{?urgency}} - "sentiment" as one of {{?sentiment}} - "categories" list of the best matching support category tags from: {{?categories}} Your complete message should be a valid json string that can be read directly and only contain the keys mentioned in the list above. Never enclose it in ```json...```, no newlines, no unnessacary whitespaces. """ ), UserMessage("{{?input}}") ] ) f_12 = partial(send_request, prompt=prompt_12, **option_lists, **guides) response = f_12(input=mail["message"])

コードにより、メタプロンプトコードによって生成された事前定義済ガイドを使用して、緊急度、センチメント、およびサポートカテゴリに基づいてメッセージを分類するためのプロンプトのシステムロールが更新されます。その後、部分関数を使用して、このプロンプトを特定のオプションおよびガイドを含む要求として送信します。最後に、これらの分類を JSON 形式で抽出して返すための電子メールメッセージが処理されます。

以下のコードを使用して、このプロンプトとその応答を評価します。

Python
1234
overall_result["metaprompting--llama3.1-70b"] = evalulation_full_dataset(test_set_small, f_12) pretty_print_table(overall_result)

以下の出力を取得できます。

Code Snippet
123456
0%| | 0/20 [00:00<?, ?it/s] is_valid_json correct_categories correct_sentiment correct_urgency ============================================================================================== basic--llama3.1-70b 100.0% 83.5% 30.0% 70.0% few_shot--llama3.1-70b 100.0% 84.0% 50.0% 90.0% metaprompting--llama3.1-70b 100.0% 90.0% 30.0% 95.0%

現在は、緊急度およびカテゴリの精度が向上していますが、センチメントの場合は精度が低下します。

Meta-prompt と Few-shot プロンプトの組み合わせ

以下のコードを使用して、メタプロンプトとfew-shot プロンプトを組み合わせることができます。

Python
1234567891011121314151617181920212223242526272829303132333435363738
prompt_13 = Template( messages=[ SystemMessage( """You are an intelligent assistant. Your task is to classify messages. Here are some examples: --- {{?few_shot_examples}} --- This is an explanation of `urgency` labels: --- {{?guide_urgency}} --- This is an explanation of `sentiment` labels: --- {{?guide_sentiment}} --- This is an explanation of `support` categories: --- {{?guide_categories}} --- Giving the following message: extract and return a json with the follwoing keys and values: - "urgency" as one of {{?urgency}} - "sentiment" as one of {{?sentiment}} - "categories" list of the best matching support category tags from: {{?categories}} Your complete message should be a valid json string that can be read directly and only contain the keys mentioned in the list above. Never enclose it in ```json...```, no newlines, no unnessacary whitespaces. """ ), UserMessage("{{?input}}") ] ) f_13 = partial(send_request, prompt=prompt_13, **option_lists, few_shot_examples=examples, **guides) response = f_13(input=mail["message"])

このコードにより、緊急度、センチメント、およびサポートカテゴリに基づいてメッセージを分類するインテリジェントアシスタントのテンプレートが定義されます。部分アプリケーションを使用して特定の例およびガイドラインで要求処理をカスタマイズし、入力メッセージを処理して構造化された JSON 応答を返します。これにより、正確で効率的なメッセージ分類が可能になります。

いくつかの例をガイドと組み合わせて、メタプロンプトで生成します。

以下のコードを使用して、このプロンプトとその応答を評価します。

Python
1234
overall_result["metaprompting_and_few_shot--llama3.1-70b"] = evalulation_full_dataset(test_set_small, f_13) pretty_print_table(overall_result)

以下の出力が表示されます。

Code Snippet
1234567
0%| | 0/20 [00:00<?, ?it/s] is_valid_json correct_categories correct_sentiment correct_urgency =========================================================================================================== basic--llama3.1-70b 100.0% 83.5% 30.0% 70.0% few_shot--llama3.1-70b 100.0% 84.0% 50.0% 90.0% metaprompting--llama3.1-70b 100.0% 90.0% 30.0% 95.0% metaprompting_and_few_shot--llama3.1-70b 100.0% 88.5% 50.0% 90.0%

これで、ほぼすべてのカテゴリの精度が類似しているか、低下していることがわかります。さらに、より多くのリソースを必要とする、より高価なプロンプトです。

注記

ここに表示される応答と、この Learning Journey に表示されるモデルの残りのすべての応答に対して、若干異なる応答が表示される場合があります。

マシンで同じプロンプトを実行すると、LLM はその確率的性質、温度設定、および非決定的アーキテクチャによりさまざまな出力を生成するため、わずかな設定変更や内部状態変化でも応答が異なります。

評価サマリー

モデルの全体的な精度と品質、およびそのコストとスケールを考慮する必要があります。

場合によっては、より小さなモデルや単純な手法の方が良い結果をもたらすことがあります。

前述の出力では、few-shot により低コストのプロンプトで最適なパフォーマンスが得られるのがわかります。

これまでのビジネス上の問題を解決するために何を行ったかをまとめましょう。

  1. オープンソースモデルを使用して、SAP AI Launchpad で基本プロンプトを作成しました。
  2. AI 向け SAP Cloud SDK (Python) を使用してプロンプトを再作成し、ソリューションをスケーリングしました。
  3. 簡易プロンプトのベースライン評価方法を作成しました。
  4. 最後に、少数のショットやメタプロンプトなどの手法を使用して、プロンプトをさらに拡張しました。
  5. 結果は、高度な技術を実装した後の速報応答の質の向上を示している。

レッスンのまとめ

Few-shot LLM にコンテキストリッチな例を提供するためのプロンプトと、一貫した動作のための明示的な指示とガイドを生成するためのメタプロンプトなど、主要なプロンプトエンジニアリング手法の実装と評価が完了しました。また、これらの方法の組み合わせについても考察しました。反復的な評価を通じて、AI 向け SAP Cloud SDK で使用されるこれらの手法が LLM 回答の精度と品質を大幅に向上させ、ソリューションをビジネス対応アプリケーションにより近づけると同時に、複雑さとコストに関するトレードオフを理解している様子をご覧いただきました。

プロンプトテンプレートを使用したプロンプトテクニックの実装

演習問題

この演習では、SAP AI Launchpad のプロンプトテンプレート内で Few-shot Learning などの高度な手法を実装することで、速やかな効果とコンテキスト理解を大幅に強化する方法を学習します。

最後に、洗練されたプロンプトテンプレートをオーケストレーションサービスと統合して、安全で信頼性の高い AI アプリケーションを構築し、SAP AI Launchpad のワークフローにデータプライバシーおよびコンテンツフィルタリングを実装する方法を確認します。

前に説明したシナリオを継続して、緊急度、センチメント、およびカテゴリをソフトウェアで使用できるカスタマメッセージに割り当てる基本プロンプトを登録しました。

ただし、回答にはまだ適切なコンテキストがないことが判明します。より良い結果を得るには、プロンプトを絞り込む必要があります。

ワンショットプロンプトやフリーショットプロンプトなどの手法を使用して、プロンプトを改良することができます。

ワンショットプロンプトは、最も単純な手法です。LLM には、必要なすべてのコンテキストとともに、単一の直接指示を一度に提供します。

Few-shot プロンプトは、LLM にプロンプト自体内の入出力ペアの例 (通常は 1 から 5) をいくつか提供するという非常に強力な手法です。これらの例では、必要なタスク、形式、および動作を示し、LLM が実際の要求を実行する前にパターンを学習できるようにします。

タスク 1: プロンプトテンプレートを使用した Few-Shot プロンプトの実装

以前に登録したプロンプトテンプレートを Few-shot 手法で更新します。

ステップ

  1. 生成 AI ハブにログオンしていることを確認します。

  2. プロンプト管理を選択してから、テンプレートを選択します。

  3. すべてボタンを選択します。ここにテンプレートが表示されます。テンプレートを検索することもできます。

  4. テンプレートの最新バージョン (3.0.0) を選択します。テンプレートとその中の正しいタイムスタンプを選択してください。テンプレートを使用する前に、テンプレートを読んでおくことをお奨めします。

  5. プロンプトテンプレートを選択し、プロンプトエディタで開くボタンをクリックします。プロンプトを使用する準備ができました。

  6. ユーザロールで以下のプロンプトを使用します。

    Code Snippet
    12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
    "<Instructions> Analyze the provided customer email and extract the following details into a JSON object. Ensure all fields are present and correctly typed according to the specifications in <OutputFormat>. Summarize 'Problem_Description' concisely (max 100 words). If any field's value cannot be determined from the email, use 'Unknown' or 'N/A' as appropriate. </Instructions> <OutputFormat> { "Complaint_ID": "string (e.g., AUTO-GEN-001)", "Complaint_Type": "enum (Plumbing, HVAC, Electrical, Noise, Cleaning, Pest Control, General Maintenance, Other)", "Urgency": "enum (High, Medium, Low)", "Problem_Description": "string (concise summary, max 100 words)", "Affected_Location": "string (e.g., Apartment 301, Main Lobby)", "Customer_Sentiment": "enum (Very Negative, Negative, Neutral, Positive)", "Suggested_Initial_Action": "string (clear next step for agent)" } </OutputFormat> <ExampleInput> Subject: Urgent - Leaky Faucet in Kitchen, Apartment 301 Dear Facility Management, I am writing to report a serious issue in my apartment, 301. The kitchen faucet has been leaking non-stop since last night. It's not just a drip, it's a steady stream, and I'm worried about water damage. I tried to tighten it myself but it didn't help. This is incredibly frustrating, especially since I just moved in last month. Please send someone to fix it immediately. Thank you, Sarah Jenkins </ExampleInput> <ExampleOutput> { "Complaint_ID": "AUTO-GEN-001", "Complaint_Type": "Plumbing", "Urgency": "High", "Problem_Description": "Kitchen faucet in Apartment 301 is leaking continuously since last night, causing concern for water damage. Tenant attempted to fix without success.", "Affected_Location": "Apartment 301", "Customer_Sentiment": "Very Negative", "Suggested_Initial_Action": "Dispatch plumber to Apartment 301 with leaking faucet repair kit immediately." } </ExampleOutput> <ExampleInput> Subject: AC not working properly in Main Lobby Dear ProCare Support, The air conditioning in the main lobby has not been cooling effectively for the past few days. It's making the waiting area very uncomfortable for visitors and staff, especially with the weather getting warmer. It's not completely broken, but definitely struggling. Could someone please take a look at it soon? Thanks. Regards, Building Manager </ExampleInput> <ExampleOutput> { "Complaint_ID": "AUTO-GEN-002", "Complaint_Type": "HVAC", "Urgency": "Medium", "Problem_Description": "Air conditioning in the main lobby is not cooling effectively, causing discomfort for visitors and staff. The unit is struggling but not completely non-functional.", "Affected_Location": "Main Lobby", "Customer_Sentiment": "Negative", "Suggested_Initial_Action": "Schedule HVAC technician to inspect main lobby AC unit within 24-48 hours." } </ExampleOutput> <ExampleInput> Subject: Light bulb replacement - Hallway 3rd Floor Hi Team, Just a quick note that a light bulb in the hallway on the 3rd floor, near apartment 305, seems to have burned out. It's not a critical issue, but it would be great if someone could replace it when convenient. No rush. Thanks, Resident </ExampleInput> <ExampleOutput> { "Complaint_ID": "AUTO-GEN-003", "Complaint_Type": "General Maintenance", "Urgency": "Low", "Problem_Description": "A light bulb in the 3rd floor hallway, near apartment 305, has burned out and needs replacement.", "Affected_Location": "3rd Floor Hallway (near Apt 305)", "Customer_Sentiment": "Neutral", "Suggested_Initial_Action": "Add to general maintenance task list for light bulb replacement during next routine visit." } </ExampleOutput> <UserQuery> {{?user_email_placeholder}} </UserQuery> . "

    <ExampleInput> タグと <ExampleOutput> タグには、LLM で入力として想定される内容と出力として生成される内容について、明確に書式設定された具体的な例が示されています。

  7. プロンプトをコピーし、メッセージブロックテキストボックスのユーザロールにペーストします。

  8. テンプレート保存ボタンをクリックします。テンプレート保存ダイアログボックスが表示されます。

  9. バージョンを 4.0.0 に変更します。

    3.1
  10. 保存ボタンをクリックします。テンプレートが保存されます。プロンプトテンプレートを few-shot の例で更新しておきます。

タスク 2: プロンプトテンプレートを使用して、ビジネス上の問題に対処します。

保存されたプロンプトテンプレートを使用して、アプリケーションで使用できる有効な応答を生成します。

ステップ

  1. 生成 AI ハブにログオンしていることを確認します。

  2. プロンプト管理を選択してから、テンプレートを選択します。

  3. すべてボタンを選択します。ここにテンプレートが表示されます。テンプレートを検索することもできます。

  4. テンプレートの最新バージョン (4.0.0) を選択します。テンプレートを選択し、テンプレート内のタイムスタンプが正しいことを確認します。テンプレートを使用する前に、テンプレートを読んでおくことをお奨めします。

  5. プロンプトテンプレートを選択し、プロンプトエディタで開くをクリックします。プロンプトを使用する準備ができました。

  6. 下にスクロールし、変数定義を選択します。

  7. この変数にカスタマメッセージを入力する必要があります。以下のメッセージを使用します。

    Code Snippet
    1234567891011121314151617181920
    Subject: Urgent: Ongoing Maintenance Issues at Our Facility Dear Support Team, I hope this message finds you well. My name is [Sender], and I am the community manager for [Community Name]. I have been overseeing our facility’s operations and maintenance for quite some time now, and I must say, the recent experiences with your maintenance services have been less than satisfactory. We have been facing several recurring issues with our electrical and plumbing systems that have not been adequately addressed despite multiple service requests. The lack of timely and effective solutions is causing significant inconvenience to our residents and staff, and it is becoming increasingly difficult to manage the situation. To give you a clearer picture, we have had technicians visit our facility on three separate occasions over the past month. Each time, the problem was either temporarily fixed or not resolved at all. This has led to a lot of frustration among our community members, and it is reflecting poorly on our management. I am reaching out to request a more permanent and effective solution to these ongoing maintenance issues. We need a thorough inspection and a comprehensive plan to address the root causes of these problems. It is crucial for us to ensure a safe and comfortable environment for everyone in our community. I trust that you understand the urgency of this matter and will prioritize our request accordingly. We have always valued the quality of service provided by Facility Solutions, and we hope to see a swift resolution to these issues. Thank you for your attention to this matter. I look forward to your prompt response. Best regards, [Sender]
  8. メッセージをコピーし、user_email_placeholder 変数の横にある現在の値テキストボックスに貼り付けます。

  9. 実行ボタンをクリックして、プロンプトを実行します。応答が生成されます。応答全体を表示するには、上にスクロールする必要がある場合があります。

    3-2

    応答が絞り込まれ、ソフトウェアアプリケーションで今後使用可能であることがわかります。

    後でこの出力を参照する必要がある場合は、アシスタントロールでこの出力をコピーして保存することができます。

    注記

    新しい応答を生成するためにアシスタントロールを追加した後に、プロンプトエディタでプロンプトテンプレートを使用する必要がある場合は、Assistant ロールを削除する必要があります。
  10. 応答テキストボックスで出力を選択し、ロールを追加します。

    3.3
  11. 下にスクロールし、アシスタントオプションを選択します。回答テキストをコピーします。テキストが表示されない場合は、テキストボックスを選択してスペースを押すと、完全なテキストが表示されます。

  12. テンプレート保存ボタンをクリックします。テンプレート保存ダイアログボックスが表示されます。

  13. バージョンを 4.1.0 に変更します。

    3.4

    更新されたプロンプトテンプレートを使用して、より適切な応答を取得し、必要に応じて出力を保持する方法を確認しておきます。

タスク 3: 変数とデフォルト値によるテンプレートの最適化

変数を使用してプロンプトテンプレートを合理化し、読みやすさと使用を改善することができます。また、テンプレートを変更することなく、変数の複数値の再利用性が確保されます。ファシリティソリューションテンプレートを続行すると、変数を使用して例を簡単に変更することができます。毎回異なるメッセージをコピーする代わりに、変数の現在の値を変更したり、デフォルト値を使用したりすることができます。

このタスクでは、いくつかの例に対して変数を登録し、デフォルト値を使用します。

ステップ

  1. 生成 AI ハブにログオンしていることを確認します。

  2. プロンプト管理を選択してから、テンプレートを選択します。ここにテンプレートが表示されます。必要に応じて、検索することもできます。

  3. すべてラジオボタンを選択します。ここにテンプレートが表示されます。テンプレートを検索することもできます。

  4. 4.1.0 の最新バージョンのテンプレートを選択します。テンプレートとその中の正しいタイムスタンプを選択してください。テンプレートを使用する前に、テンプレートを読んでおくことをお奨めします。

  5. プロンプトテンプレートを選択し、プロンプトエディタで開くボタンをクリックします。プロンプトを使用する準備ができました。

  6. ユーザロールで以下のプロンプトを使用します。

    Code Snippet
    12345678910111213141516171819202122232425262728
    "<Instructions> Analyze the provided customer email and extract the following details into a JSON object. Ensure all fields are present and correctly typed according to the specifications in <OutputFormat>. Summarize 'Problem_Description' concisely (max 100 words). If any field's value cannot be determined from the email, use 'Unknown' or 'N/A' as appropriate. </Instructions> <OutputFormat> { "Complaint_ID": "string (e.g., AUTO-GEN-001)", "Complaint_Type": "enum (Plumbing, HVAC, Electrical, Noise, Cleaning, Pest Control, General Maintenance, Other)", "Urgency": "enum (High, Medium, Low)", "Problem_Description": "string (concise summary, max 100 words)", "Affected_Location": "string (e.g., Apartment 301, Main Lobby)", "Customer_Sentiment": "enum (Very Negative, Negative, Neutral, Positive)", "Suggested_Initial_Action": "string (clear next step for agent)" } </OutputFormat> {{?few_shot_example_1}} {{?few_shot_example_2}} {{?few_shot_example_3}} <!-- Add more {{few_shot_example_N}} as needed --> <UserQuery> {{?user_email_placeholder}} </UserQuery>"

    例ごとに few_shot_example 変数を確認することができます。各変数は、最初の <ExampleInput> と <ExampleOutput> のペアに置き換えられます。

  7. プロンプトをコピーし、メッセージブロックテキストボックスのユーザロールにペーストします。

  8. 変数セクションまで下にスクロールします。

    3.5
  9. 各変数のデフォルト値に以下の値を追加します。few_shot_example_1 に以下のデフォルト値を追加します。

    Code Snippet
    1234567891011121314151617
    " <ExampleInput> Subject: Urgent - Leaky Faucet in Kitchen, Apartment 301 Dear Facility Management, I am writing to report on a serious issue in my apartment, 301. The kitchen faucet has been leaking nonstop since last night. It's not just a drip, it's a steady stream, and I'm worried about water damage. I tried to tighten it myself, but it didn't help. This is incredibly frustrating, especially since I just moved in last month. Please send someone to fix it immediately. Thank you, Sarah Jenkins </ExampleInput> <ExampleOutput> { "Complaint_ID": "AUTO-GEN-001", "Complaint_Type": "Plumbing", "Urgency": "High", "Problem_Description": "Kitchen faucet in Apartment 301 is leaking continuously since last night, causing concern for water damage. Tenant attempted to fix without success.", "Affected_Location": "Apartment 301", "Customer_Sentiment": "Very Negative", "Suggested_Initial_Action": "Dispatch plumber to Apartment 301 with leaking faucet repair kit immediately." }"
  10. few_shot_example_2 に以下のデフォルト値を追加します。

    Code Snippet
    12345678910111213141516171819202122
    "<ExampleInput> Subject: AC not working properly in Main Lobby Dear Support team, The air conditioning in the main lobby has not been cooling effectively for the past few days. It's making the waiting area very uncomfortable for visitors and staff, especially with the weather getting warmer. It's not completely broken, but definitely struggling. Could someone please take a look at it soon? Thanks. Regards, Building Manager </ExampleInput> <ExampleOutput> { "Complaint_ID": "AUTO-GEN-002", "Complaint_Type": "HVAC", "Urgency": "Medium", "Problem_Description": "Air conditioning in the main lobby is not cooling effectively, causing discomfort for visitors and staff. The unit is struggling but not completely non-functional.", "Affected_Location": "Main Lobby", "Customer_Sentiment": "Negative", "Suggested_Initial_Action": "Schedule HVAC technician to inspect main lobby AC unit within 24-48 hours." } </ExampleOutput>"
  11. few_shot_example_3 に以下のデフォルト値を追加します。

    Code Snippet
    123456789101112131415161718192021222324
    "<ExampleInput> Subject: Light bulb replacement - Hallway 3rd Floor Hi Team, Just a quick note that a light bulb in the hallway on the 3rd floor, near apartment 305, seems to have burned out. It's not a critical issue, but it would be great if someone could replace it when convenient. No rush. Thanks, Resident </ExampleInput> <ExampleOutput> { "Complaint_ID": "AUTO-GEN-003", "Complaint_Type": "General Maintenance", "Urgency": "Low", "Problem_Description": "A light bulb in the 3rd floor hallway, near apartment 305, has burned out and needs replacement.", "Affected_Location": "3rd Floor Hallway (near Apt 305)", "Customer_Sentiment": "Neutral", "Suggested_Initial_Action": "Add to general maintenance task list for light bulb replacement during next routine visit." } </ExampleOutput>"
  12. user_email_placeholder に以下のデフォルト値を追加します。

    Code Snippet
    1234567891011121314151617181920
    Subject: Urgent: Ongoing Maintenance Issues at Our Facility Dear Support Team, I hope this message finds you well. My name is [Sender], and I am the community manager for [Community Name]. I have been overseeing our facility’s operations and maintenance for quite some time now, and I must say, the recent experiences with your maintenance services have been less than satisfactory. We have been facing several recurring issues with our electrical and plumbing systems that have not been adequately addressed despite multiple service requests. The lack of timely and effective solutions is causing significant inconvenience to our residents and staff, and it is becoming increasingly difficult to manage the situation. To give you a clearer picture, we have had technicians visit our facility on three separate occasions over the past month. Each time, the problem was either temporarily fixed or left unresolved. This has led to significant frustration among our community members and reflects poorly on our management. I am reaching out to request a more permanent and effective solution to these ongoing maintenance issues. We need a thorough inspection and a comprehensive plan to address the root causes of these problems. It is crucial that we ensure a safe and comfortable environment for everyone in our community. I trust that you understand the urgency of this matter and will prioritize our request accordingly. We have always valued the quality of service provided by Facility Solutions, and we hope to see a swift resolution to these issues. Thank you for your attention to this matter. I look forward to your prompt response. Best regards, [Sender]

    すべての変数のデフォルト値を指定しました。

    3.6
  13. テンプレート保存ボタンをクリックします。テンプレート保存ダイアログボックスが表示されます。

  14. バージョンを 5.0.0 に変更します。

  15. 保存ボタンをクリックします。テンプレートが保存されます。変数とデフォルト値を使用してプロンプトテンプレートを更新しました。

タスク 4: 更新されたプロンプトテンプレートを使用して、ビジネス上の問題に対処します。

最新のプロンプトテンプレートを使用して、アプリケーションで使用できる有効な応答を生成します。以前のバージョンと比較して、このテンプレートを使用する方が簡単であることがわかります。

ステップ

  1. 生成 AI ハブにログオンしていることを確認します。

  2. プロンプト管理を選択してから、テンプレートを選択します。

  3. すべてボタンを選択します。ここにテンプレートが表示されます。テンプレートを検索することもできます。

  4. テンプレートの最新バージョン (5.0.0) を選択します。テンプレートとその中の正しいタイムスタンプを選択してください。テンプレートを使用する前に、テンプレートを読んでおくことをお奨めします。

  5. プロンプトテンプレートを選択し、プロンプトエディタで開くをクリックします。プロンプトを使用する準備ができました。

  6. 下にスクロールし、アシスタントロールを削除します。

    3.7
  7. 変数定義を参照してください。すべての変数がデフォルト値とともに表示されます。

  8. 実行をクリックして、プロンプトを実行します。応答が生成されます。

    3.8

    生成された応答を確認することができます。これは、ビジネス上の問題に対する最適なソリューションを反復し、作成するための迅速で信頼性の高い方法です。

    現在の値を指定することで、デフォルト値を編集できます。

  9. 下にスクロールして変数を表示し、user_email_placeholder の現在の値に以下のメッセージを追加します。

    Code Snippet
    123456
    "Subject: Minor issue with light in 2nd floor hallway Dear Facility Management, I wanted to bring to your attention a minor issue in the hallway on the 2nd floor, specifically near apartment 205. The overhead light fixture has been flickering occasionally for the past couple of days. It’s not a critical problem, and there’s still plenty of light, but I thought you should be aware. No need for an immediate visit, but it would be great if someone could look during a routine check. Thank you, A Resident "
  10. 実行をクリックして、プロンプトを実行します。応答が生成されます。

    3.9

    user_email_placeholder 変数の現在の値に対して json 出力が更新されていることを確認できます。

    複数の変数、デフォルト値、および現在の値を使用するプロンプトテンプレートを使用しました。

    生成 AI ハブを使用してプロンプトを作成し、プロンプトテンプレート、変数、プロンプト管理などの多機能な機能を使用してビジネス上の問題を解決し、スケーラブルな AI ソリューションの基盤を構築しておきます。

    これらのテンプレートの重要な用途は、オーケストレーションサービスを使用して AI ワークフローを作成することです。

プロンプトテンプレートおよびオーケストレーションサービスを使用したワークフローの登録

オーケストレーションサービスにより、さまざまなタスク (データのフィルタリングや匿名化など) を統合するワークフローの開発が容易になります。エンタープライズ環境では、これらのワークフローは高度で回復力のある AI アプリケーションを構築するために不可欠です。生成 AI ハブにより、ユーザーはオーケストレーションサービス内のプロンプトテンプレートを活用して、安全で信頼できる結果を一貫して生み出すスケーラブルなワークフローを構築することができます。

プロンプトテンプレートを使用して、安全で信頼性の高い結果を得るために、データプライバシーおよびコンテンツフィルタリングを含むワークフローを作成します。

ステップ

  1. 生成 AI ハブにログオンしていることを確認します。

  2. オーケストレーションを選択します。オーケストレーション設定が表示されます。

    4.1
  3. 作成ボタンをクリックします。Untitled_Configuration ページが表示されます。基本モジュールが表示されます。

    4.2
  4. 詳細スライドボタンをクリックすると、すべてのモジュールが表示されます。すべてのモジュールが表示されます。これらの拡張モジュールは、デフォルトでは無効化されています。

  5. マスキングおよびフィルタリングモジュールが必要です。それぞれのボタンをクリックして、データマスキング、入力フィルタリング、および出力フィルタリングの有効化を有効化します。

    4.3

    これらのモジュールは有効化済みセクションに移動します。

  6. テンプレート選択ボタンをクリックします。

    4.4
  7. テンプレート選択ダイアログボックスが表示されます。テンプレートを検索し、最新バージョン (5.0.0) を選択します。

    4.5
  8. 選択ボタンをクリックします。テンプレートが設定ページに表示されます。中央のペインには、テンプレートおよびモジュールが表示されます。右側のペインには、テンプレート変数と、オーケストレーションワークフローを実行するオプションが表示されます。

    4.6
  9. 中央にスクロールダウンしてデータマスキングを表示し、仮名化を選択します。

  10. 以下のスクリーンショットに示されているフィールドを選択します。

    4.7

    これらのフィールドは、処理のためにクエリを LLM に送信する前に仮名化されます。データを匿名化することもできます。

    仮名化は、真の匿名化とは異なり、同じアパートまたは居住者の繰り返し問題を一定期間追跡し、保全履歴をリンクして業務インサイトを得ることができるため、真の匿名化とは異なり、LLM に個人 ID を直接公開することなく、これらの重要なつながりを断ちます。

  11. 入力フィルタリングまで下にスクロールし、以下のスクリーンショットに示すように、いずれかの方法を選択します。

    4.7

    これにより、ローメッセージ内の有害なコンテンツまたは不適切なコンテンツのプロンプトがフィルタリングされます。これは、文字列性を削減し、幅広い入力を可能にするために、中または '緩和' として設定されます。

  12. 下にスクロールしてモデル設定を表示してから、任意のモデルを選択します。

  13. 4.9

    LLM は、完全に準備され、安全で、マスクされたプロンプトを受信します。

  14. 下にスクロールして出力フィルタリングを表示し、以下のスクリーンショットに示すように、いずれかの方法を選択します。

    4.10

    このフィルタリングでは、LLM で生成された回答がスキャンされ、毒性言語、バイアス、または不適切な提案が含まれていないことが確認されます。

    これにより、ローメッセージに存在する可能性がある有害なコンテンツまたは不適切なコンテンツのプロンプトがフィルタリングされます。文字列性を削減し、より広範な入力を可能にするために、中または 'リラックス' として設定されます。

  15. テンプレートのアシスタントロールをスクロールして削除します。

  16. 右側のペインには、必要に応じて変更できるすべての変数のデフォルト値が表示されます。これで、ワークフローをテストする準備ができました。実行をクリックします。しばらくすると、応答が生成されます。

    4.11

    生成された応答を確認することができます。

    プロンプトテンプレートでは、事前定義されたロール、プロンプト、変数、およびデフォルト値を提供することで、迅速なワークフロー開発およびテストが可能であることに注意してください。

  17. 上部の JSON トグルボタンを使用して、すべてのモジュールの JSON を確認できます。Trace オプションを使用して、実行全体のトレース JSON を確認することもできます。最適なビューになるようにタスクペインのサイズを変更します。

    4.12

    ワークフローのトレースは、エラーのデバッグ、ボトルネックの特定、および複雑な複数ステップのエンタープライズオペレーション内での説明責任の確保に不可欠です。

    保存ボタンを使用して、ワークフロー全体を保存することもできます。

  18. 保存ボタンをクリックします。オーケストレーションコンフィグレーションの保存ダイアログボックスが表示されます。テンプレート名を使用して、設定を保存します。設定を保存するには、オーケストレーションシナリオのみを選択してください。

    4.13

    この設定は、オーケストレーション設定ページで確認できます。検索ボタンを使用して、設定を確認します。

    4.14

    この設定により、ビジネス上の問題を解決するためのワークフローの反復処理、絞込、およびスケーリングのためのスケーラブルなアプローチが提供されます。

    この設定を開き、今後の使用のためにダウンロードすることができます。

    4.15

    プロンプトテンプレートを使用して、データプライバシー対策やコンテンツフィルタリングなどのワークフロー設定を開発しておきます。