OpenAI API のモニタリング

AppDynamics Python エージェントは、OpenAI API の使用状況と関連メトリックをモニターするのに役立ちます。これは、OpenAI バックエンドへの openai-python ライブラリを使用して作成された ChatCompletionCompletion および Moderation API タイプの要求をモニターします。エージェントは、OpenAI API モデルによって使用されるプロンプトと応答もキャプチャします。

次のメトリックは、アプリケーション、階層、およびノードの各レベルで報告されます。

  • 1分あたりのコール数
  • 1分あたりのエラー数
  • トークン
  • 入力トークン = 0.5$
  • 完了トークン = 1.5$

次に、メトリックパスの例を示します。

  • モデルごとのメトリックパス - Application Infrastructure Performance|OpenAI_Tier|OpenAI|ada|Cost
  • すべてのモデル累積メトリックパス - Application Infrastructure Performance|OpenAI_Tier|OpenAI|Cost - All Models
  • ネット アプリケーション レベルのメトリックのパス - Overall Application Summary|OpenAI - Cost - ada
注: これらのメトリックは、exit コールがビジネストランザクションの外部にある場合でも報告されます。ただし、exit コールがビジネストランザクションの外部にある場合、平均応答時間(ms)メトリックは報告されません。

OpenAI モデレーション API

バージョン 24.2.0 以降、Python エージェントでは OpenAI モデレーション API がサポートされます。モデレーション API は、クエリされたステートメントがポリシーに準拠しているかどうかをユーザーに求めます。Python エージェントでは、次のメトリックがキャプチャされます。

  • モデレーション API へのコール:モデレーション API が使用された回数(1 分ごと)。(OpenAI|moderations|Calls per minute)
  • フラグ付きカテゴリメトリクス:ヘイトスピーチなど、特定のタイプのコンテンツにフラグが付けられた回数。(OpenAI|moderations|Flagged Calls by category|hate)
  • フラグ付きクエリカウント:フラグが設定されたコンテンツの合計数。(OpenAI|moderations|Flagged queries)
  • 合計クエリカウント:処理されたクエリの総数。(OpenAI|moderations|Total queries)

前提条件

AppDynamics を使用して OpenAI API exit コールをモニターするには、次の前提条件を満たしていることを確認します。

  • Python エージェント 23.8.0 以降をインストールします。Pythonエージェントのインストール を参照してください。
  • カスタムダッシュボードおよびテンプレートをインポートします。
  • Python エージェントの ファイルで enable-openai フラグを必ず /path/to/appdynamics.cfg に設定してください。[instrumentation]を参照してください。
  • スナップショット exit コールの詳細で OpenAI 要求および応答をキャプチャするには、Python エージェントの /path/to/appdynamics.cfg ファイルで enable-genai-data-capture フラグを true に設定します。「[instrumentation]」を参照してください。

Create a Custom Dashboard

  1. Download Custom_dashboard_script.zip.
    It contains:
    DirectoryDescription
    templatesContains json templates to create the dashboard files.
    dashboardDashboard json files are created here. It contains the sample json files.
    main.pyPython script to create the dashboards.
    readme.mdDescription of the solution.
  2. Run the following command:
    cd Custom_dashboard_script
    python3 main.py
    The preceding command prompts you to specify the dashboard type (application or tier) that you want to create.
  3. Based on your selected dashboard type, you will be prompted to specify the following dashboard details.
    Application Level Dashboard Details
    VariableDescriptionDefaultPossible ValuesRequired
    Dashboard NameThe dashboard name to be displayed on Dashboard & Reports in the Controller UI.OpenAI_App_dashboardapp_dashboardOptional
    Application NameName of the Application with OpenAI backend calls.noneopenai_app_1Yes
    OpenAI Endpoints Host NameThe hostname of the OpenAI endpoint.api.openai.comapi.openai.comOptional
    OpenAI Endpoints PortThe port of the OpenAI endpoint.443443Optional
    Tier Level Dashboard Details
    VariableDescriptionDefaultPossible ValuesRequired
    Dashboard NameThe dashboard name to be displayed on Dashboard & Reports in the Controller UI.tier_dashboardtier_dashboardOptional
    Application NameName of the Application with OpenAI backend calls.noneopenai_app_1Yes
    Tier NameName of the Tier exposed to OpenAI backend calls.noneopenai_tier_1Yes
    Business Transaction NameThe name of the business transaction reported to the host. This is to capture API Response time metric.noneopenai_btYes
    OpenAI Endpoints Host NameThe hostname of the OpenAI endpoint.api.openai.comapi.openai.comOptional
    OpenAI Endpoints PortThe port of the OpenAI endpoint.443443Optional
    Application Level Moderation API Dashboard Details
    VariableDescriptionDefaultPossible ValuesRequired
    Dashboard NameThe dashboard name to be displayed on Dashboard & Reports in the Controller UI.OpenAI_Moderation_Appmoderation_app_dashboardOptional
    Application NameName of the Application with OpenAI backend calls.noneopenai_app_1Yes
    Tier Level Moderation API Dashboard Details
    VariableDescriptionDefaultPossible ValuesRequired
    Dashboard NameThe dashboard name to be displayed on Dashboard & Reports in the Controller UI.OpenAI_Moderation_Tiermoderation_tier_dashboardOptional
    Application NameName of the Application with OpenAI backend calls.noneopenai_app_1Yes
    Tier NameName of the Tier exposed to OpenAI backend calls.noneopenai_tier_1Yes
  4. Import the dashboard in the Controller UI.

Example Dashboard

Example Dashboard
注: Navigate to Tiers & Nodes > My Dashboards and create a dashboard for the selected application by copying and pasting widgets from the existing dashboard for easier navigation.

カスタムコストメトリック式の作成

入力トークンメトリックと完了トークンメトリックにそれぞれのコストを乗算することで、カスタムコストメトリック式を作成できます。

たとえば、gpt-3.5-turbo-0125 の 100 万トークンあたりのコストは次のとおりです。

  • 入力トークン = 0.5$
  • 完了トークン = 1.5$
このシナリオでは、 gpt-3.5-turbo-0125 のカスタム式を作成して、次のようにコストを計算できます。
({input Tokens}*0.5 + {Completion Tokens}*1.5)/1000000

このカスタム式を使用して、さまざまなモデル間のコスト分散の円グラフ、またはすべてのモデルのコスト関数を含む総コストウィジェットを作成します。次の手順を実行して、既存の OpenAI ダッシュボードにモデルごとのコストウィジェットを作成します。

  1. 円グラフウィジェットを既存の OpenAI ダッシュボードに追加します。「メトリック式」を参照してください。
  2. input_token および complete_token コストを指定してトークン数で乗算します。
    1. Data Source:アプリケーション名を選択します。
    2. Metric Category:階層/ノードの正常性 - ハードウェア、JVM、CLR(CPU、ヒープ、ディスク I/O など)を選択します。
    3. Metric:メトリック式を選択します。
    4. メトリック式を編集します。
    メトリック式の編集
  3. [Metric Expression] で、2 つの変数を追加して名前を割り当てます。
  4. [Metric Selection] で、入力トークンと完了トークンの相対メトリックパスを指定します。メトリック選択の相対パスの指定
    • Input TokensAgent|OpenAl|gpt-3.5-turbo|Input Tokens
    • Completion TokensAgent|OpenAI|gpt-3.5-turbo|Completion Tokens
  5. [Metric Expression] で、次のようにメトリック式を定義します。
    ({input_token_gpt3.5)*0.5 + {completion_token_gpt3.5)*1.5)/1000000
メトリック式

このメトリック式には、両方のタイプに対する 100 万トークンあたりのコスト乗数が含まれます。