Spaces:
Sleeping
Sleeping
File size: 2,740 Bytes
23d418f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | import { CircleAlert } from 'lucide-react'
import { seconds, usd } from '@/lib/format'
import type { RunState } from '@/lib/run'
import { Sources } from './Sources'
import { Trace } from './Trace'
/** An answer: how it was made (Trace), the text, what a broker would still need to find
* out, a version note, the numbered sources, and what it took. `recorded`: a held-out
* run shown on the Evals page (its cost line says what it cost then). */
export function AnswerBody({ run, lastEventAt, recorded = false }: { run: RunState; lastEventAt: number; recorded?: boolean }) {
const a = run.answer
return (
<div className="space-y-3">
<Trace run={run} lastEventAt={lastEventAt} />
{run.error && (
<p role="alert" className="flex items-start gap-2 rounded-lg bg-red-50 p-3 text-sm text-red-700">
<CircleAlert className="mt-0.5 size-4 shrink-0" /> {run.error}
</p>
)}
{a && (
<>
{a.abstain && (
<p className="inline-flex items-center gap-1.5 rounded-full bg-amber-50 px-3 py-1 text-xs font-medium text-amber-800">
<CircleAlert className="size-3.5" /> Can't determine this from the documents
</p>
)}
<div className="text-[15px] leading-relaxed whitespace-pre-wrap">{a.answer}</div>
{a.missing_info.length > 0 && (
<div className="rounded-xl border p-3">
<p className="text-sm font-medium">What a broker would need to find out</p>
<ul className="mt-1 list-disc space-y-1 pl-5 text-sm">
{a.missing_info.map((m, i) => (
<li key={i}>{m}</li>
))}
</ul>
</div>
)}
{a.flagged.length > 0 && (
<p className="text-xs text-amber-700">
Version note: {a.flagged.join(', ')} {a.flagged.length > 1 ? 'are' : 'is'} not in force on the policy date
by {a.flagged.length > 1 ? 'their' : 'its'} stated dates, and no version of the form is: the answer may
rest on an edition that is not the one on the policy.
</p>
)}
{a.citations.length > 0 && <Sources citations={a.citations} />}
<p className="text-[11px] tabular-nums text-muted-foreground">
Confidence {Math.round(a.confidence * 100)}% 路 {seconds(a.latency_ms)} 路{' '}
{(a.usage.tokens_in + a.usage.tokens_out).toLocaleString()} tokens 路{' '}
{recorded
? `${usd(a.usage.cost_usd)} when recorded`
: a.usage.cached
? 'repeated question, answered from memory'
: usd(a.usage.cost_usd)}
</p>
</>
)}
</div>
)
}
|