The LDAIConfigTracker is used to track various details about AI operations.

interface LDAIConfigTracker {
    trackBedrockConverse<TRes>(res: TRes): TRes;
    trackDuration(durationMs: number): void;
    trackDurationOf(func: (() => Promise<any>)): Promise<any>;
    trackFeedback(feedback: {
        kind: LDFeedbackKind;
    }): void;
    trackOpenAI<TRes>(func: (() => Promise<TRes>)): Promise<TRes>;
    trackSuccess(): void;
    trackTokens(tokens: LDTokenUsage): void;
}

Methods

  • Track an operation which uses Bedrock.

    Type Parameters

    • TRes extends {
          $metadata: {
              httpStatusCode?: number;
          };
          metrics?: {
              latencyMs?: number;
          };
          usage?: {
              inputTokens?: number;
              outputTokens?: number;
              totalTokens?: number;
          };
      }

    Parameters

    • res: TRes

      The result of the Bedrock operation.

    Returns TRes

    The input operation.

  • Track the duration of generation.

    Ideally this would not include overhead time such as network communication.

    Parameters

    • durationMs: number

      The duration in milliseconds.

    Returns void

  • Track the duration of execution of the provided function.

    Parameters

    • func: (() => Promise<any>)

      The function to track the duration of.

        • (): Promise<any>
        • Returns Promise<any>

    Returns Promise<any>

    The result of the function.

  • Track an OpenAI operation.

    Type Parameters

    • TRes extends {
          usage?: {
              completion_tokens?: number;
              prompt_tokens?: number;
              total_tokens?: number;
          };
      }

    Parameters

    • func: (() => Promise<TRes>)

      Function which executes the operation.

    Returns Promise<TRes>

    The result of the operation.