共通クエリの基本プロンプトの開発

Objective

After completing this lesson, you will be able to SAP AI Launchpad で生成 AI ハブを使用して基本プロンプトを構築します。

生成 AI ハブにアクセスし、オーケストレーションサービスをデプロイすると、生成 AI ハブを使用して具体的なビジネス上の問題を解決できるようになります。このインタラクションの主なスキルは、LLM に対する明確で効果的な指示の作成を含むプロンプトの開発です。

このレッスンでは、ビジネス上の課題に対処するために、SAP AI Launchpad 内で基本プロンプトを開発する反復プロセスについて説明します。システムロールおよびユーザロールを利用して明確な指示とコンテキストを提供し、最終的に構造化された機械可読の出力を生成することに焦点を当てます。このレッスンを終了すると、エンタープライズアプリケーションへの統合が可能な、正確で実用的な結果をもたらすプロンプトを構築および改良できるようになります。

ビジネスシナリオの特定

施設管理

この Learning Journey の焦点は、施設ソリューション企業です。施設ソリューション会社は、住宅施設と商業施設の両方に対する包括的な施設管理、保守、清掃サービスの主要プロバイダーです。その使命は、環境の安全性、効率性、および不十分な保守を確保することです。対象市場には、高級住宅団地、アパート、個人住宅、オフィスビル、小売スペース、産業施設、教育機関などがあります。

ビジネス上の問題:

Facility Solutions 社は、依頼、クレーム、およびその他の問い合わせに関して、顧客から毎日数千件の電子メールを受信します。これらの顧客とのコミュニケーションに対応するための内部アプリケーションを維持し、タイムリーかつ正確な対応を確保するために効率的な処理と優先順位付けを必要としています。

ただし、現在、これらの電子メールの分類には、マニュアルプロセス (電子メールから内部アプリケーションへのデータ転送、各タスクのマニュアル分類、および優先順位付け) が含まれます。このプロセスは時間がかかり、エラーが発生しやすく、顧客サービスでボトルネックが発生します。

同社は今、この重要なプロセスを自動化および合理化するために、SAP の生成 AI ハブに注目しています。この Learning Journey を通じて、この問題に対する段階的なソリューションを提供します。

SAP AI Launchpad でのプロンプトの開発

ビジネス上の問題を解決するための迅速な開発は、反復的な概念化プロセスです。基本的なアイデアから開始し、それをテストし、LLM の応答を確認してから、出力が特定のビジネスニーズを満たすまで指示を絞り込みます。

最新のプロンプトエンジニアリングのベストプラクティスは、個別の対話型ロール (システムおよびユーザ) を使用することです。これらのロールにより、受信する各テキストの性質が LLM に明確に示されます。

  • システムロールは、LLM の包括的なルール、ペルソナ、および制約を設定するために使用されます。これにより、LLM が誰であるか、どのように動作するか、およびインタラクション全体で従う必要がある一般的なガイドラインが定義されます。
  • ユーザロールは、その特定のターンに対する特定のクエリまたは入力を提供します。ここで、LLM で処理する必要がある動的コンテンツを配置します。

受信した顧客メールから緊急度やセンチメントを抽出する速報の開発を始めましょう。Gemini モデルや、Generative AI Hub からアクセスできる Mistral AI などのオープンソース LLM などの任意のモデルから開始できます。オープンソースの LLM は、コスト削減、透明性、カスタマイズなどの利点を提供し、開発に優れた選択肢を提供します。

ステップ 1:緊急度と感情の基本プロンプトを作成する

まず、LLM に緊急性とセンチメントを簡単に抽出するよう依頼します。この段階では、厳密な書式設定や値の制約は課されません。

プロンプトの構造:

JSON
123456789101112131415161718192021222324252627282930
[ { "role": "system", "content": "You are a helpful assistant. Your task is to analyze customer messages. Extract the urgency and sentiment from the provided message." }, { "role": "user" "content": " Analyze the following message: --- Subject: Urgent HVAC System Repair Needed Dear Support Team, I hope this message finds you well. My name is [Sender], and I am reaching out to you from [Residential Complex Name], where I have been residing for the past few years. I have always appreciated the meticulous care and attention your team provides in maintaining our facilities. However, I am currently facing a pressing issue with the HVAC system in my apartment. Over the past few days, the system has been malfunctioning, resulting in inconsistent temperatures and, at times, complete shutdowns. Given the current weather conditions, this has become quite unbearable and is affecting my daily routine significantly. I have attempted to troubleshoot the problem by resetting the system and checking the thermostat settings, but these efforts have not yielded any improvement. The situation seems to be beyond my control and requires professional intervention. I kindly request that a repair team be dispatched immediately to address this urgent issue. The urgency of the matter cannot be overstated, as it is impacting not only my comfort but also my ability to carry out daily activities effectively. Thank you for your prompt attention to this matter. I look forward to your swift response and resolution. Best regards, [Sender] --- " } ]

SAP AI Launchpad でこのプロンプトを実行すると、長時間の対話型の応答を受信する可能性があります。たとえば、「このメッセージの緊急度は高いです。HVACシステムの不具合によって顧客が大きな不快感を抱いているため、伝えられる感情は否定的です」

LLM によって緊急度およびセンチメントが適切に識別されますが、この詳細出力は、これらの値を自動的に処理する必要があるアプリケーションには直接有用ではありません。より構造化されたデータを生成するには、プロンプトを絞り込む必要があります。

ステップ 2: 緊急度およびセンチメントへの事前定義値の割当

前の回答は長すぎました。この目的は、内部アプリケーションの入力として使用できる特定の緊急度およびセンチメントの値を割り当てることです。このステップでは、LLM が事前定義されたラベルのみを使用するように制限します。

プロンプトの構造:

JSON
123456789101112131415161718192021222324252627282930
[ { "role": "system", "content": "You are an expert customer service analyst. Your task is to analyze customer messages and extract urgency and sentiment. For 'urgency', classify the message as one of: `low`, `medium`, `high`. For 'sentiment', classify the message as one of: `positive`, `neutral`, `negative`." }, { "role": "user", "content": "Analyze the following message: --- Subject: Urgent HVAC System Repair Needed Dear Support Team, I hope this message finds you well. My name is [Sender], and I am reaching out to you from [Residential Complex Name], where I have been residing for the past few years. I have always appreciated the meticulous care and attention your team provides in maintaining our facilities. However, I am currently facing a pressing issue with the HVAC system in my apartment. Over the past few days, the system has been malfunctioning, resulting in inconsistent temperatures and, at times, complete shutdowns. Given the current weather conditions, this has become quite unbearable and is affecting my daily routine significantly. I have attempted to troubleshoot the problem by resetting the system and checking the thermostat settings, but these efforts have not yielded any improvement. The situation seems to be beyond my control and requires professional intervention. I kindly request that a repair team be dispatched immediately to address this urgent issue. The urgency of the matter cannot be overstated, as it is impacting not only my comfort but also my ability to carry out daily activities effectively. Thank you for your prompt attention to this matter. I look forward to your swift response and resolution. Best regards, [Sender] --- " } ]

LLM の回答は、「緊急度:高、感情:ネガティブ」など、より制約を受けます。これは良いですが、自然言語文字列からの解析が必要です。

ステップ 3: 緊急度およびセンチメントの JSON 出力の生成

内部アプリケーションで出力機械が読みやすく、直接使用できるように、LLM がその応答を JSON 形式で提供するように指示します。JSON は、API および Web サービスで広く採用された、効率的なデータ交換のためのシンプルで言語非依存の軽量なソリューションを提供します。

プロンプトの構造:

JSON
1234567891011121314151617181920212223242526272829303132
[ { "role": "system", "content": "You are an expert customer service analyst. Your task is to analyze customer messages and extract specific attributes. For 'urgency', classify the message as one of: `low`, `medium`, `high`. For 'sentiment', classify the message as one of: `positive`, `neutral`, `negative`. Your response MUST be a valid JSON string containing ONLY the keys 'urgency' and 'sentiment'." }, { "role": "user", "content": "Analyze the following message: --- Subject: Urgent HVAC System Repair Needed Dear Support Team, I hope this message finds you well. My name is [Sender], and I am reaching out to you from [Residential Complex Name], where I have been residing for the past few years. I have always appreciated the meticulous care and attention your team provides in maintaining our facilities. However, I am currently facing a pressing issue with the HVAC system in my apartment. Over the past few days, the system has been malfunctioning, resulting in inconsistent temperatures and, at times, complete shutdowns. Given the current weather conditions, this has become quite unbearable and is affecting my daily routine significantly. I have attempted to troubleshoot the problem by resetting the system and checking the thermostat settings, but these efforts have not yielded any improvement. The situation seems to be beyond my control and requires professional intervention. I kindly request that a repair team be dispatched immediately to address this urgent issue. The urgency of the matter cannot be overstated, as it is impacting not only my comfort but also my ability to carry out daily activities effectively. Thank you for your prompt attention to this matter. I look forward to your swift response and resolution. Best regards, [Sender] --- " } ]

このプロンプトは、{"緊急度": "高", "センチメント": "中立"} などの JSON 出力を生成します。これは大幅な改善です。

ステップ 4: 適切な JSON 書式設定の確認

LLM には、JSON に関する指示がある場合でも、マークダウンコードブロック (json ...) や追加の空白などの無関係な文字が含まれることがあり、これにより自動解析が破損する可能性があります。このステップでは、クリーンで解析可能な JSON 文字列を確保するための明示的な指示が追加されます。

プロンプトの構造:

JSON
1234567891011121314151617181920212223242526272829303132
[ { "role": "system", "content": "You are an expert customer service analyst. Your task is to analyze customer messages and extract specific attributes. For 'urgency', classify the message as one of: `low`, `medium`, `high`. For 'sentiment', classify the message as one of: `positive`, `neutral`, `negative`. Your complete response MUST be a valid JSON string, ready to be parsed by an application. It should contain ONLY the keys 'urgency' and 'sentiment'. Do not include any other text, explanations, or formatting like markdown code blocks (e.g., ```json). Ensure there are no newlines or unnecessary whitespaces outside the JSON structure." }, { "role": "user", "content": "Analyze the following message: --- Subject: Urgent HVAC System Repair Needed Dear Support Team, I hope this message finds you well. My name is [Sender], and I am reaching out to you from [Residential Complex Name], where I have been residing for the past few years. I have always appreciated the meticulous care and attention your team provides in maintaining our facilities. However, I am currently facing a pressing issue with the HVAC system in my apartment. Over the past few days, the system has been malfunctioning, resulting in inconsistent temperatures and, at times, complete shutdowns. Given the current weather conditions, this has become quite unbearable and is affecting my daily routine significantly. I have attempted to troubleshoot the problem by resetting the system and checking the thermostat settings, but these efforts have not yielded any improvement. The situation seems to be beyond my control and requires professional intervention. I kindly request that a repair team be dispatched immediately to address this urgent issue. The urgency of the matter cannot be overstated, as it is impacting not only my comfort but also my ability to carry out daily activities effectively. Thank you for your prompt attention to this matter. I look forward to your swift response and resolution. Best regards, [Sender] --- " } ]

テンプレートメッセージブロックの画像

スクリーンショットに示されているように、このプロンプトでは、引用符や追加の空白がないクリーンな JSON 形式を提供するための明確な指示が示され、ソフトウェアの使用に対して堅牢になります。

ステップ 5: ビジネス機能に基づく単純なカテゴリ

緊急性やセンチメント以外に、ビジネスニーズに応じてメッセージを分類する必要もあります。最初に、LLM では、事前定義された一覧を提供せずに、関連するカテゴリを割り当てるだけで済みます。

プロンプトの構造:

JSON
123456789101112131415161718192021222324252627282930
[ { "role": "system", "content": "You are an expert customer service analyst. Your task is to analyze customer messages and assign a list of matching support categories to the message." }, { "role": "user", "content": "Analyze the following message: --- Subject: Urgent HVAC System Repair Needed Dear Support Team, I hope this message finds you well. My name is [Sender], and I am reaching out to you from [Residential Complex Name], where I have been residing for the past few years. I have always appreciated the meticulous care and attention your team provides in maintaining our facilities. However, I am currently facing a pressing issue with the HVAC system in my apartment. Over the past few days, the system has been malfunctioning, resulting in inconsistent temperatures and, at times, complete shutdowns. Given the current weather conditions, this has become quite unbearable and is affecting my daily routine significantly. I have attempted to troubleshoot the problem by resetting the system and checking the thermostat settings, but these efforts have not yielded any improvement. The situation seems to be beyond my control and requires professional intervention. I kindly request that a repair team be dispatched immediately to address this urgent issue. The urgency of the matter cannot be overstated, as it is impacting not only my comfort but also my ability to carry out daily activities effectively. Thank you for your prompt attention to this matter. I look forward to your swift response and resolution. Best regards, [Sender] --- " } ]

テンプレートメッセージブロック - 応答提供済

これで、LLM によってカテゴリが割り当てられます。ただし、これらのカテゴリは自由形式であり、緊急度などの他の値と重複し、事前定義された内部カテゴリと一致しない可能性があります。

ステップ 6: 事前定義された一覧からのカテゴリへの値の割当

会社の内部処理との整合性および整合性を確保するには、LLM で特定の事前定義された一覧からカテゴリを選択する必要があります。出力をビジネスニーズに合わせることは、ビジネス上の問題に効果的に対処するための重要なステップです。

プロンプトの構造:

JSON
12345678910111213141516171819202122232425262728293031
[ { "role": "system", "content": "You are an expert customer service analyst. Your task is to analyze customer messages and assign a list of the best matching support category tags from the following predefined list: `facility_management_issues`, `cleaning_services_scheduling`, `general_inquiries`, `specialized_cleaning_services`, `routine_maintenance_requests`, `emergency_repair_services`, `sustainability_and_environmental_practices`, `training_and_support_requests`, `quality_and_safety_concerns`, `customer_feedback_and_complaints`." }, { "role": "user", "content": "Analyze the following message: --- Subject: Urgent HVAC System Repair Needed Dear Support Team, I hope this message finds you well. My name is [Sender], and I am reaching out to you from [Residential Complex Name], where I have been residing for the past few years. I have always appreciated the meticulous care and attention your team provides in maintaining our facilities. However, I am currently facing a pressing issue with the HVAC system in my apartment. Over the past few days, the system has been malfunctioning, resulting in inconsistent temperatures and, at times, complete shutdowns. Given the current weather conditions, this has become quite unbearable and is affecting my daily routine significantly. I have attempted to troubleshoot the problem by resetting the system and checking the thermostat settings, but these efforts have not yielded any improvement. The situation seems to be beyond my control and requires professional intervention. I kindly request that a repair team be dispatched immediately to address this urgent issue. The urgency of the matter cannot be overstated, as it is impacting not only my comfort but also my ability to carry out daily activities effectively. Thank you for your prompt attention to this matter. I look forward to your swift response and resolution. Best regards, [Sender] --- " } ]

メールカテゴリ

スクリーンショットに示されているように、バージョン 6 では、LLM によって提供された一覧からカテゴリが厳密に割り当てられるようになり、ビジネスプロセスが合理化されます。

ステップ 7: カテゴリ値の JSON 出力の生成

ステップ 3 と同様に、プログラムによる処理には JSON 出力にカテゴリ値が必要です。また、JSON 形式をクリーンにすることの重要性についても改めて説明します。

プロンプトの構造:

JSON
123456789101112131415161718192021222324252627282930313233
[ { "role": "system", "content": "You are an expert customer service analyst. Your task is to analyze customer messages and extract specific attributes. For 'categories', assign a list of the best matching support tags from the following predefined list: `facility_management_issues`, `cleaning_services_scheduling`, `general_inquiries`, `specialized_cleaning_services`, `routine_maintenance_requests`, `emergency_repair_services`, `sustainability_and_environmental_practices`, `training_and_support_requests`, `quality_and_safety_concerns`, `customer_feedback_and_complaints`. Your complete response MUST be a valid JSON string, ready to be parsed by an application. It should contain ONLY the key 'categories'. Do not include any other text, explanations, or formatting like markdown code blocks. Ensure there are no newlines or unnecessary whitespaces outside the JSON structure." }, { "role": "user", "content": "Analyze the following message: --- Subject: Urgent HVAC System Repair Needed Dear Support Team, I hope this message finds you well. My name is [Sender], and I am reaching out to you from [Residential Complex Name], where I have been residing for the past few years. I have always appreciated the meticulous care and attention your team provides in maintaining our facilities. However, I am currently facing a pressing issue with the HVAC system in my apartment. Over the past few days, the system has been malfunctioning, resulting in inconsistent temperatures and, at times, complete shutdowns. Given the current weather conditions, this has become quite unbearable and is affecting my daily routine significantly. I have attempted to troubleshoot the problem by resetting the system and checking the thermostat settings, but these efforts have not yielded any improvement. The situation seems to be beyond my control and requires professional intervention. I kindly request that a repair team be dispatched immediately to address this urgent issue. The urgency of the matter cannot be overstated, as it is impacting not only my comfort but also my ability to carry out daily activities effectively. Thank you for your prompt attention to this matter. I look forward to your swift response and resolution. Best regards, [Sender] --- " } ]

メッセージブロック - ユーザ

スクリーンショットに示されているように、LLM ではクリーンな JSON 出力内のカテゴリが提供され、ソフトウェアを利用できます。

ステップ 8: 統合プロンプトのすべてのステップの結合

段階的なアプローチを採用して、緊急度、センチメント、およびカテゴリの適切な値を JSON 形式で取得しました。次に、これらすべての指示を 1 つの堅牢なプロンプトに統合します。この複合プロンプトは、自動メール分類システムの最終バージョンとして機能します。

プロンプトの構造:

JSON
12345678910111213141516171819202122232425262728293031323334353637
[ { "role": "system", "content": "You are an expert customer service analyst for a facility management company. Your task is to analyze incoming customer messages and extract specific attributes for automated processing. For 'urgency', classify the message as one of: `low`, `medium`, `high`. For 'sentiment', classify the message as one of: `positive`, `neutral`, `negative`. For 'categories', assign a list of the best matching support tags from the following predefined list: `facility_management_issues`, `cleaning_services_scheduling`, `general_inquiries`, `specialized_cleaning_services`, `routine_maintenance_requests`, `emergency_repair_services`, `sustainability_and_environmental_practices`, `training_and_support_requests`, `quality_and_safety_concerns`, `customer_feedback_and_complaints`. Your complete response MUST be a valid JSON string, ready to be parsed by an application. It should contain ONLY the keys 'urgency', 'sentiment', and 'categories'. Do not include any other text, explanations, or formatting like markdown code blocks (e.g., ```json). Ensure there are no newlines or unnecessary whitespaces outside the JSON structure." }, { "role": "user", "content": "Analyze the following customer message: --- Subject: Urgent HVAC System Repair Needed Dear Support Team, I hope this message finds you well. My name is [Sender], and I am reaching out to you from [Residential Complex Name], where I have been residing for the past few years. I have always appreciated the meticulous care and attention your team provides in maintaining our facilities. However, I am currently facing a pressing issue with the HVAC system in my apartment. Over the past few days, the system has been malfunctioning, resulting in inconsistent temperatures and, at times, complete shutdowns. Given the current weather conditions, this has become quite unbearable and is affecting my daily routine significantly. I have attempted to troubleshoot the problem by resetting the system and checking the thermostat settings, but these efforts have not yielded any improvement. The situation seems to be beyond my control and requires professional intervention. I kindly request that a repair team be dispatched immediately to address this urgent issue. The urgency of the matter cannot be overstated, as it is impacting not only my comfort but also my ability to carry out daily activities effectively. Thank you for your prompt attention to this matter. I look forward to your swift response and resolution. Best regards, [Sender] --- " } ]

イメージ出力 - クリーンな JSON

スクリーンショットに示されているように、この統合プロンプトでは、以下のような出力がクリーンな JSON として提供されます。

JSON
1
{"urgency": "high", "sentiment": "negative", "categories": ["emergency_repair_services", "routine_maintenance_requests", "facility_management_issues"]}

この出力により、緊急度、センチメント、およびカテゴリが、ソフトウェアによって即時に処理可能な形式でカスタマメッセージに一貫して割り当てられ、ビジネス要件を満たします。問題のソリューションに移行するプロンプトが正常に開発されました。

レッスンのまとめ

SAP AI Launchpad の Generative AI Hub 内で一般的なクエリの基本プロンプトを開発する反復的なプロセスが正常にナビゲートされました。システムロールおよびユーザロールを使用して明確な指示を定義し、特定の分類オプションを提供し、構造化された JSON 出力を明示的に要求することは、機械可読で実用的な結果を作成するために不可欠であることを確認しました。プロンプトエンジニアリングにおけるこの基礎的なスキルにより、非構造化ビジネスコミュニケーションを価値のある処理可能なデータに変換し、エンタープライズアプリケーション内での自動化と効率の向上を実現します。