ホームページ >テクノロジー周辺機器 >AI >GPTモデルを使用したCHATGPT応答をモデレートするための包括的なガイド
人工知能革命は、アプリケーション開発の分野を一掃し、人間コンピューターの相互作用の新しい時代を開きました。企業はAIを活用してユーザーエクスペリエンスを強化しますが、大規模な言語モデル(LLM)に基づくソリューションも、コンテンツの整合性、精度、倫理基準を維持する上で課題を提示します。
責任あるAI監査の必要性は、アプリケーションが制御された環境を超えて拡大するにつれてますます明白になります。これらの環境では、ユーザーに対する合理的で正確な対応を確保することは容易ではありませんが、それは重要です。
たとえば、カスタマーサービスのやり取りでは、誤った情報や不適切なコンテンツは、顧客の不満につながり、会社の評判を損なうことさえあります。しかし、開発者として、AIベースのアプリケーションがユーザーに合理的で正確な応答を提供できるようにするにはどうすればよいですか? これがAI監査が登場する場所です!
この記事では、GPTモデルを使用してGPTベースのアプリケーションを監査する詳細なテクノロジーについて説明します。GPTベースの品質監査エージェントを構築します
AI品質レビューには、大規模な言語モデル(LLM)を使用する場合、偏りのない適切な応答が生成されることも含まれます。 Openaiは、このような監査要件向けに設計されたAPIを開始しました。モデルによって生成されたバイアスまたは不適切な応答を検出したい場合、またはユーザーの不正行為に対処することに熱心である場合、ChatGpt Audit API:入力/出力コントロールというタイトルの記事に貴重な洞察が見つかります。GPTモデルを使用して、ユーザー要求のためにモデル自体によって生成された出力を評価できます。このテスト方法は、曖昧さと誤った応答を防ぐのに役立ち、ユーザーの要求を効果的に満たすモデルの能力を高めます。
スコープとターゲット
この記事では、アプリケーションの範囲内でGPTモデルを使用して、GPTベースのアプリケーションの品質と正確性を確認する方法について説明します。
たとえば、GPTモデルを使用してエンタープライズチャットボットの動力を供給する場合、チャットボットがカタログアイテムや機能以外の情報を提供しないことを確認することに非常に興味がある必要があります。
主な目標は、単純なLLMベースのアプリケーションを生成し、LLMベースの品質検査官を使用して出力を監査することです。この例では、サンプルカスタマーサービスエージェントであるQAエージェント(QAエージェントと呼ばれる)を作成し、さらに重要なことに、2つの間の相互作用を定義する必要があります。 次の画像は、上記のワークフローをよく示しています:
自家製の写真。監査ワークフロー図:1。ユーザーは、LLMベースのアプリケーション(この場合はカスタマーサービスチャットボット)にリクエストを送信します。 2.チャットボットは答えを生成しますが、最初にQAエージェントに送信します。 3。QAエージェントが答えが適切かどうかをチェックした後、答えをユーザーに送り返します。
ステップバイステップに行こう!
店のカスタマーサービスの会話エージェントを構築することから始めましょう。
既に実行可能なLLM駆動型アプリケーションを既に持っている場合、またはお好みの例を実装したい場合は、最初の部分を自由にスキップしてください!あなたのビジネスがLLMベースのアプリケーションの恩恵を受けることができるかどうかを知りたい場合は、興味深いポッドキャストのディスカッションに従う必要があります!
私たちが店のカスタマーサービスエージェントを構築していると仮定しましょう。このクライアントエージェントの背後にあるChatGptなどのモデルを使用して、自然言語機能を活用してユーザークエリを理解し、自然な方法で応答することに興味があります。
カスタマーサービスチャットボットを定義するには、2つの重要な要素が必要です。
その背後にあるアイデアは、各モデルインスタンスの個別のメッセージ履歴(システムメッセージを含む)を初期化し、モデルとの今後の相互作用を使用して継続的に更新することです。
<code>import openai import os # 从环境中获取 OpenAI 密钥 openai_api_key = os.environ["OPENAI_API_KEY"] # 使用过去交互记忆的简单 OpenAI API 调用 def gpt_call(prompt, message_history, model="gpt-3.5-turbo"): message_history.append({'role': 'user', 'content': prompt}) response = openai.ChatCompletion.create( model=model, messages=message_history ) response_text = response.choices[0].message["content"] message_history.append({'role': 'assistant', 'content': response_text}) return response_text</code>
インタラクションを処理するためのより最適化された方法を探している場合は、Langchainフレームワークを使用することを強くお勧めします。
Openai APIに慣れていない場合は、OpenAI APIとChatGPTを開始する際にウェビナーをチェックすることを検討してください。
必要なビルディングブロックを特定したので、それらをまとめてみましょう:
サンプルディレクトリ(Product_information)(jsonl形式)とシステムメッセージ(customer_agent_sysmessage)を3つの要件で定義していることがわかります。
<code># 定义我们的示例产品目录 product_information = """ { "name": "UltraView QLED TV", "category": "Televisions and Home Theater Systems", "brand": "UltraView", "model_number": "UV-QLED65", "warranty": "3 years", "rating": 4.9, "features": [ "65-inch QLED display", "8K resolution", "Quantum HDR", "Dolby Vision", "Smart TV" ], "description": "Experience lifelike colors and incredible clarity with this high-end QLED TV.", "price": 2499.99 } { "name": "ViewTech Android TV", "category": "Televisions and Home Theater Systems", "brand": "ViewTech", "model_number": "VT-ATV55", "warranty": "2 years", "rating": 4.7, "features": [ "55-inch 4K display", "Android TV OS", "Voice remote", "Chromecast built-in" ], "description": "Access your favorite apps and content on this smart Android TV.", "price": 799.99 } { "name": "SlimView OLED TV", "category": "Televisions and Home Theater Systems", "brand": "SlimView", "model_number": "SL-OLED75", "warranty": "2 years", "rating": 4.8, "features": [ "75-inch OLED display", "4K resolution", "HDR10+", "Dolby Atmos", "Smart TV" ], "description": "Immerse yourself in a theater-like experience with this ultra-thin OLED TV.", "price": 3499.99 } { "name": "TechGen X Pro", "category": "Smartphones and Accessories", "brand": "TechGen", "model_number": "TG-XP20", "warranty": "1 year", "rating": 4.5, "features": [ "6.4-inch AMOLED display", "128GB storage", "48MP triple camera", "5G", "Fast charging" ], "description": "A feature-packed smartphone designed for power users and mobile enthusiasts.", "price": 899.99 } { "name": "GigaPhone 12X", "category": "Smartphones and Accessories", "brand": "GigaPhone", "model_number": "GP-12X", "warranty": "2 years", "rating": 4.6, "features": [ "6.7-inch IPS display", "256GB storage", "108MP quad camera", "5G", "Wireless charging" ], "description": "Unleash the power of 5G and high-resolution photography with the GigaPhone 12X.", "price": 1199.99 } { "name": "Zephyr Z1", "category": "Smartphones and Accessories", "brand": "Zephyr", "model_number": "ZP-Z1", "warranty": "1 year", "rating": 4.4, "features": [ "6.2-inch LCD display", "64GB storage", "16MP dual camera", "4G LTE", "Long battery life" ], "description": "A budget-friendly smartphone with reliable performance for everyday use.", "price": 349.99 } { "name": "PixelMaster Pro DSLR", "category": "Cameras and Camcorders", "brand": "PixelMaster", "model_number": "PM-DSLR500", "warranty": "2 years", "rating": 4.8, "features": [ "30.4MP full-frame sensor", "4K video", "Dual Pixel AF", "3.2-inch touchscreen" ], "description": "Unleash your creativity with this professional-grade DSLR camera.", "price": 1999.99 } { "name": "ActionX Waterproof Camera", "category": "Cameras and Camcorders", "brand": "ActionX", "model_number": "AX-WPC100", "warranty": "1 year", "rating": 4.6, "features": [ "20MP sensor", "4K video", "Waterproof up to 50m", "Wi-Fi connectivity" ], "description": "Capture your adventures with this rugged and versatile action camera.", "price": 299.99 } { "name": "SonicBlast Wireless Headphones", "category": "Audio and Headphones", "brand": "SonicBlast", "model_number": "SB-WH200", "warranty": "1 year", "rating": 4.7, "features": [ "Active noise cancellation", "50mm drivers", "30-hour battery life", "Comfortable earpads" ], "description": "Immerse yourself in superior sound quality with these wireless headphones.", "price": 149.99 } """ # 为我们的用例定义一个合适的系统消息 customer_agent_sysmessage = f""" 您是一位客户服务代理,负责回答客户关于产品目录中产品的疑问。 产品目录将用三个反引号分隔,即 ```。 以友好和人性化的语气回复,并提供产品目录中可用的详细信息。 产品目录: ```{product_information}``` """ # 初始化模型的记忆 customer_agent_history = [{'role': 'system', 'content': customer_agent_sysmessage}]</code>
カスタマーサービスエージェントの役割を果たします。
システムメッセージと追加情報を作成するときに機能スタイルを使用することは注目に値します(例:3つのバックテック)。これは、チップエンジニアリングのベストプラクティスの1つです!より多くのベストプラクティスに興味があるなら、ChatGptのヒントエンジニアリングは、ガイドウェビナーのためのものです!
この時点で、次のようにサンプルの顧客チャットボットの使用を開始できます。
<code>import openai import os # 从环境中获取 OpenAI 密钥 openai_api_key = os.environ["OPENAI_API_KEY"] # 使用过去交互记忆的简单 OpenAI API 调用 def gpt_call(prompt, message_history, model="gpt-3.5-turbo"): message_history.append({'role': 'user', 'content': prompt}) response = openai.ChatCompletion.create( model=model, messages=message_history ) response_text = response.choices[0].message["content"] message_history.append({'role': 'assistant', 'content': response_text}) return response_text</code>自然な答えのように見えますよね?フォローアップの相互作用を持ちましょう:
<code># 定义我们的示例产品目录 product_information = """ { "name": "UltraView QLED TV", "category": "Televisions and Home Theater Systems", "brand": "UltraView", "model_number": "UV-QLED65", "warranty": "3 years", "rating": 4.9, "features": [ "65-inch QLED display", "8K resolution", "Quantum HDR", "Dolby Vision", "Smart TV" ], "description": "Experience lifelike colors and incredible clarity with this high-end QLED TV.", "price": 2499.99 } { "name": "ViewTech Android TV", "category": "Televisions and Home Theater Systems", "brand": "ViewTech", "model_number": "VT-ATV55", "warranty": "2 years", "rating": 4.7, "features": [ "55-inch 4K display", "Android TV OS", "Voice remote", "Chromecast built-in" ], "description": "Access your favorite apps and content on this smart Android TV.", "price": 799.99 } { "name": "SlimView OLED TV", "category": "Televisions and Home Theater Systems", "brand": "SlimView", "model_number": "SL-OLED75", "warranty": "2 years", "rating": 4.8, "features": [ "75-inch OLED display", "4K resolution", "HDR10+", "Dolby Atmos", "Smart TV" ], "description": "Immerse yourself in a theater-like experience with this ultra-thin OLED TV.", "price": 3499.99 } { "name": "TechGen X Pro", "category": "Smartphones and Accessories", "brand": "TechGen", "model_number": "TG-XP20", "warranty": "1 year", "rating": 4.5, "features": [ "6.4-inch AMOLED display", "128GB storage", "48MP triple camera", "5G", "Fast charging" ], "description": "A feature-packed smartphone designed for power users and mobile enthusiasts.", "price": 899.99 } { "name": "GigaPhone 12X", "category": "Smartphones and Accessories", "brand": "GigaPhone", "model_number": "GP-12X", "warranty": "2 years", "rating": 4.6, "features": [ "6.7-inch IPS display", "256GB storage", "108MP quad camera", "5G", "Wireless charging" ], "description": "Unleash the power of 5G and high-resolution photography with the GigaPhone 12X.", "price": 1199.99 } { "name": "Zephyr Z1", "category": "Smartphones and Accessories", "brand": "Zephyr", "model_number": "ZP-Z1", "warranty": "1 year", "rating": 4.4, "features": [ "6.2-inch LCD display", "64GB storage", "16MP dual camera", "4G LTE", "Long battery life" ], "description": "A budget-friendly smartphone with reliable performance for everyday use.", "price": 349.99 } { "name": "PixelMaster Pro DSLR", "category": "Cameras and Camcorders", "brand": "PixelMaster", "model_number": "PM-DSLR500", "warranty": "2 years", "rating": 4.8, "features": [ "30.4MP full-frame sensor", "4K video", "Dual Pixel AF", "3.2-inch touchscreen" ], "description": "Unleash your creativity with this professional-grade DSLR camera.", "price": 1999.99 } { "name": "ActionX Waterproof Camera", "category": "Cameras and Camcorders", "brand": "ActionX", "model_number": "AX-WPC100", "warranty": "1 year", "rating": 4.6, "features": [ "20MP sensor", "4K video", "Waterproof up to 50m", "Wi-Fi connectivity" ], "description": "Capture your adventures with this rugged and versatile action camera.", "price": 299.99 } { "name": "SonicBlast Wireless Headphones", "category": "Audio and Headphones", "brand": "SonicBlast", "model_number": "SB-WH200", "warranty": "1 year", "rating": 4.7, "features": [ "Active noise cancellation", "50mm drivers", "30-hour battery life", "Comfortable earpads" ], "description": "Immerse yourself in superior sound quality with these wireless headphones.", "price": 149.99 } """ # 为我们的用例定义一个合适的系统消息 customer_agent_sysmessage = f""" 您是一位客户服务代理,负责回答客户关于产品目录中产品的疑问。 产品目录将用三个反引号分隔,即 ```。 以友好和人性化的语气回复,并提供产品目录中可用的详细信息。 产品目录: ```{product_information}``` """ # 初始化模型的记忆 customer_agent_history = [{'role': 'system', 'content': customer_agent_sysmessage}]</code>
それは公平です! エージェントは、製品カタログにiPhoneがないことを認識し、それに応じてユーザーに返信します。ユーザーが店に連絡することを奨励しています!
別のリクエストを試してみましょう:
<code>user_prompt = "你们商店里最好的电视是什么?" customer_agent_response = gpt_call(user_prompt, customer_agent_history) print(customer_agent_response) # 输出:在我们商店里,UltraView QLED 电视被认为是最好的电视。它的评分为 4.9,并提供 65 英寸 QLED 显示屏和 8K 分辨率。它还具有 Quantum HDR、Dolby Vision 和智能电视功能。凭借其逼真的色彩和令人难以置信的清晰度,这款高端 QLED 电视可提供身临其境的观看体验。UltraView QLED 电视的价格为 2499.99 美元,并提供 3 年保修。</code>
正しく、場合によっては、プロキシがディレクトリの情報をスキップする可能性があるようです。これらの場合、QAプロキシは不要な応答をフィルタリングするのに役立ちます。
カスタムQAエージェント顧客エージェントの場合、ユーザーのプロンプトは、ユーザーのニーズとライティングスタイルに依存するため、予測不可能です。 QAエージェントの場合、ユーザーリクエスト、顧客エージェントの応答、製品カタログをモデルに合格する責任があります。したがって、プロンプトには常に同じ構造がありますが、ユーザークエリ(user_prompt)とモデルの応答(customer_agent_response)は異なります。
<code>user_prompt = "我想买最新的 iPhone。你能帮我吗?" customer_agent_response = gpt_call(user_prompt, customer_agent_history) print(customer_agent_response) # 输出:当然!我很乐意帮助您找到最新的 iPhone。但是,由于它似乎缺失于产品目录中,我目前无法提供有关最新 iPhone 型号的具体详细信息。我建议您查看我们的网站或直接联系我们的商店,以获取有关最新 iPhone 型号的最新信息。我们知识渊博的工作人员将能够帮助您选择最符合您的需求和偏好的 iPhone。</code>
システムメッセージとQAプロンプトが定義されたら、次のように最新のカスタマーサービス応答でQAエージェントをテストできます。
<code>user_prompt = "你能帮我买一台三星电视吗?" customer_agent_response = gpt_call(user_prompt, customer_agent_history) print(customer_agent_response) # 输出:当然!我很乐意协助您购买三星电视。您能否提供您的一些具体要求或偏好?这样,我可以推荐最适合您需求的三星电视型号。</code>QAエージェントの応答を評価するには、分析する相互作用を分解しましょう。
ユーザーが要求しました:「サムスンのテレビを買ってもらえますか?」
<code>qa_sysmessage = f""" 您是一位质量助理,负责评估客户服务代理是否正确地回答了客户的问题。 您还必须验证客户服务代理是否仅提供我们商店产品目录中的信息,并温和地拒绝目录之外的任何其他产品。 客户消息、客户服务代理的回复和产品目录将用三个反引号分隔,即 ```。 请说明您的答案原因。 """</code>
顧客エージェントの返信:「もちろん!サムスンのテレビの購入を手伝ってくれてうれしいです。特定の要件や好みのいくつかを提供できますか?このようにして、あなたのニーズに最適なサムスンのテレビモデルをお勧めします。」
QAエージェント:「品質チェック:誤った返信フィードバック:顧客はSamsung TVの購入の助けを要求しましたが、エージェントはリクエストを処理しませんでした。エージェントは、ストアの製品カタログにのみアクセスでき、そのディレクトリに基づいて情報とアドバイスを提供できることに言及する必要があります。
自家製の写真。各エージェントの3つのビルディングブロック図:システムメッセージ(青)、モデル入力(緑)、およびモデル出力(黄色)。
次は何ですか? 次に、2つのモデル間の相互作用を実装する必要があります!
以下は、不正確な応答をフィルタリングするための提案です。
最初に、顧客エージェントにユーザークエリに基づいて応答を生成させます。次に、QAエージェントが顧客エージェントの応答がユーザークエリと製品カタログに十分であると考えている場合、ユーザーに回答を返信するだけです。対照的に、
QAエージェントが、回答がユーザーの要求を満たしていないか、ディレクトリに関する真実の情報を含んでいると判断した場合、ユーザーに送信する前に顧客エージェントに答えを改善するように依頼することができます。このアイデアを考慮して、元のチャートの最後の部分を次のように改善できます。
自家製の写真。拡張監査ワークフロー図。 QAプロキシ判断を使用して、LLMベースのアプリケーションにフィードバックを提供できます。
順序付けエージェントインタラクション
QAプロキシをフィルターとして使用するには、各反復で一貫した応答を出力することを確認する必要があります。したがって、最新の顧客エージェントの反応を再度評価すると、ブール出力のみが取得されます。
このブール値をさらに使用して、ユーザーに応答を送信するか(QAプロキシがTrueに評価される場合)、モデルに新しい応答を生成する2回目のチャンスを与えます(QAプロキシがfalseに評価された場合)。デモエージェントインタラクション
<code>import openai import os # 从环境中获取 OpenAI 密钥 openai_api_key = os.environ["OPENAI_API_KEY"] # 使用过去交互记忆的简单 OpenAI API 调用 def gpt_call(prompt, message_history, model="gpt-3.5-turbo"): message_history.append({'role': 'user', 'content': prompt}) response = openai.ChatCompletion.create( model=model, messages=message_history ) response_text = response.choices[0].message["content"] message_history.append({'role': 'assistant', 'content': response_text}) return response_text</code>すべてをまとめましょう!
<code># 定义我们的示例产品目录 product_information = """ { "name": "UltraView QLED TV", "category": "Televisions and Home Theater Systems", "brand": "UltraView", "model_number": "UV-QLED65", "warranty": "3 years", "rating": 4.9, "features": [ "65-inch QLED display", "8K resolution", "Quantum HDR", "Dolby Vision", "Smart TV" ], "description": "Experience lifelike colors and incredible clarity with this high-end QLED TV.", "price": 2499.99 } { "name": "ViewTech Android TV", "category": "Televisions and Home Theater Systems", "brand": "ViewTech", "model_number": "VT-ATV55", "warranty": "2 years", "rating": 4.7, "features": [ "55-inch 4K display", "Android TV OS", "Voice remote", "Chromecast built-in" ], "description": "Access your favorite apps and content on this smart Android TV.", "price": 799.99 } { "name": "SlimView OLED TV", "category": "Televisions and Home Theater Systems", "brand": "SlimView", "model_number": "SL-OLED75", "warranty": "2 years", "rating": 4.8, "features": [ "75-inch OLED display", "4K resolution", "HDR10+", "Dolby Atmos", "Smart TV" ], "description": "Immerse yourself in a theater-like experience with this ultra-thin OLED TV.", "price": 3499.99 } { "name": "TechGen X Pro", "category": "Smartphones and Accessories", "brand": "TechGen", "model_number": "TG-XP20", "warranty": "1 year", "rating": 4.5, "features": [ "6.4-inch AMOLED display", "128GB storage", "48MP triple camera", "5G", "Fast charging" ], "description": "A feature-packed smartphone designed for power users and mobile enthusiasts.", "price": 899.99 } { "name": "GigaPhone 12X", "category": "Smartphones and Accessories", "brand": "GigaPhone", "model_number": "GP-12X", "warranty": "2 years", "rating": 4.6, "features": [ "6.7-inch IPS display", "256GB storage", "108MP quad camera", "5G", "Wireless charging" ], "description": "Unleash the power of 5G and high-resolution photography with the GigaPhone 12X.", "price": 1199.99 } { "name": "Zephyr Z1", "category": "Smartphones and Accessories", "brand": "Zephyr", "model_number": "ZP-Z1", "warranty": "1 year", "rating": 4.4, "features": [ "6.2-inch LCD display", "64GB storage", "16MP dual camera", "4G LTE", "Long battery life" ], "description": "A budget-friendly smartphone with reliable performance for everyday use.", "price": 349.99 } { "name": "PixelMaster Pro DSLR", "category": "Cameras and Camcorders", "brand": "PixelMaster", "model_number": "PM-DSLR500", "warranty": "2 years", "rating": 4.8, "features": [ "30.4MP full-frame sensor", "4K video", "Dual Pixel AF", "3.2-inch touchscreen" ], "description": "Unleash your creativity with this professional-grade DSLR camera.", "price": 1999.99 } { "name": "ActionX Waterproof Camera", "category": "Cameras and Camcorders", "brand": "ActionX", "model_number": "AX-WPC100", "warranty": "1 year", "rating": 4.6, "features": [ "20MP sensor", "4K video", "Waterproof up to 50m", "Wi-Fi connectivity" ], "description": "Capture your adventures with this rugged and versatile action camera.", "price": 299.99 } { "name": "SonicBlast Wireless Headphones", "category": "Audio and Headphones", "brand": "SonicBlast", "model_number": "SB-WH200", "warranty": "1 year", "rating": 4.7, "features": [ "Active noise cancellation", "50mm drivers", "30-hour battery life", "Comfortable earpads" ], "description": "Immerse yourself in superior sound quality with these wireless headphones.", "price": 149.99 } """ # 为我们的用例定义一个合适的系统消息 customer_agent_sysmessage = f""" 您是一位客户服务代理,负责回答客户关于产品目录中产品的疑问。 产品目录将用三个反引号分隔,即 ```。 以友好和人性化的语气回复,并提供产品目录中可用的详细信息。 产品目录: ```{product_information}``` """ # 初始化模型的记忆 customer_agent_history = [{'role': 'system', 'content': customer_agent_sysmessage}]</code>
2つのメモリを初期化したため(それぞれシステムメッセージと追加情報を使用して)、各クライアントリクエストは次のように処理できます。
結論 この記事では、GPTモデルを他の同様のモデルインスタンスの監査人として使用する可能性を調査します。アプリケーションでLLMモデルを使用するように導くのと同じ強力な機能が、アプリケーションがユーザーインタラクションの精度と完全性を改善するのに役立つことを示しました。
誤解に反して、監査レベルを実装することは必ずしもアプリケーションの複雑さを増やすことを意味するわけではありません。また、示されているように、いくつかの慎重に設計されたコードで実装でき、アプリケーションの機能を大幅にアップグレードすることがあります。
責任あるLLM監査は、今日のAI主導の世界で不可欠です。これは単なる選択肢ではなく、道徳的義務です。統合されたAI監査を通じて、当社のアプリケーションが強力であるだけでなく、信頼性が高く倫理的であることを保証します。正確性を維持しながらAIの恩恵を続けることができるように、責任を持って開発を進めましょう。
お読みいただきありがとうございます! AIレビューのトピックが気に入ったら、フォローアップとしてChatGPTの責任あるAI:コンテンツレビューを宣伝し続けることをお勧めします!
以上がGPTモデルを使用したCHATGPT応答をモデレートするための包括的なガイドの詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。