Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

2.1 KB
Raw Blame
import { useValues } from 'kea'

import { LemonTag, Tooltip } from '@posthog/lemon-ui'

import { aiObservabilitySessionEvaluationsLogic } from './aiObservabilitySessionEvaluationsLogic'
import { EvalTooltipContent, getEvalBadgeProps, getEvalSummaries } from './components/EvalResultBadges'
import { llmEvaluationsLogic } from './evaluations/llmEvaluationsLogic'

interface LLMASessionEvaluationsDisplayProps {
    sessionId: string
}

export function LLMASessionEvaluationsDisplay({ sessionId }: LLMASessionEvaluationsDisplayProps): JSX.Element | null {
    const { sessionEvaluations } = useValues(aiObservabilitySessionEvaluationsLogic({ sessionId }))
    const { detectorEvaluationIds, evaluations } = useValues(llmEvaluationsLogic)

    // A session that resumes after being evaluated can be graded again; collapse to the newest
    // verdict per evaluation so a stale tag never sits beside a fresh one. Same helper the trace
    // and generation surfaces use, so the tooltip and badge read identically everywhere.
    const summaries = getEvalSummaries(sessionEvaluations)

    if (summaries.length === 0) {
        return null
    }

    return (
        <>
            {summaries.map((summary) => {
                const evaluation = evaluations?.find(({ id }) => id === summary.latestRun.evaluation_id)
                const { type, icon, label } = getEvalBadgeProps(summary.latestRun, {
                    trueIsFailure: detectorEvaluationIds.includes(summary.latestRun.evaluation_id),
                    categoryOptions: evaluation?.output_config.options,
                    passingRule: evaluation?.output_config.passing_rule,
                })
                return (
                    <Tooltip key={summary.latestRun.evaluation_id} title={<EvalTooltipContent {...summary} />}>
                        <span>
                            <LemonTag type={type} icon={icon} size="medium">
                                {label}
                            </LemonTag>
                        </span>
                    </Tooltip>
                )
            })}
        </>
    )
}