diff --git a/tests/trace/test_client_trace.py b/tests/trace/test_client_trace.py index 005c79f5cb0..08c274255b7 100644 --- a/tests/trace/test_client_trace.py +++ b/tests/trace/test_client_trace.py @@ -2,6 +2,7 @@ import datetime import json import platform +import random import sys import time from collections import defaultdict, namedtuple @@ -3005,6 +3006,8 @@ def test_op_sampling(client): always_traced_calls = 0 sometimes_traced_calls = 0 + random.seed(0) + @weave.op(tracing_sample_rate=0.0) def never_traced(x: int) -> int: nonlocal never_traced_calls @@ -3044,7 +3047,7 @@ def sometimes_traced(x: int) -> int: sometimes_traced(i) assert sometimes_traced_calls == num_runs # Function was called every time num_traces = len(list(sometimes_traced.calls())) - assert 35 < num_traces < 65 # But only traced ~50% of the time + assert num_traces == 38 def test_op_sampling_async(client): @@ -3052,6 +3055,8 @@ def test_op_sampling_async(client): always_traced_calls = 0 sometimes_traced_calls = 0 + random.seed(0) + @weave.op(tracing_sample_rate=0.0) async def never_traced(x: int) -> int: nonlocal never_traced_calls @@ -3092,7 +3097,7 @@ async def sometimes_traced(x: int) -> int: asyncio.run(sometimes_traced(i)) assert sometimes_traced_calls == num_runs # Function was called every time num_traces = len(list(sometimes_traced.calls())) - assert 35 < num_traces < 65 # But only traced ~50% of the time + assert num_traces == 38 def test_op_sampling_inheritance(client): diff --git a/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/PlaygroundPage/PlaygroundChat/PlaygroundCallStats.tsx b/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/PlaygroundPage/PlaygroundChat/PlaygroundCallStats.tsx index 9888ea88681..d969a91136e 100644 --- a/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/PlaygroundPage/PlaygroundChat/PlaygroundCallStats.tsx +++ b/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/PlaygroundPage/PlaygroundChat/PlaygroundCallStats.tsx @@ -1,31 +1,19 @@ import {Button} from '@wandb/weave/components/Button'; +import {Pill} from '@wandb/weave/components/Tag'; import {Tailwind} from '@wandb/weave/components/Tailwind'; +import {Tooltip} from '@wandb/weave/components/Tooltip'; import {makeRefCall} from '@wandb/weave/util/refs'; import React from 'react'; import {useHistory} from 'react-router-dom'; import {useWeaveflowRouteContext} from '../../../context'; import {Reactions} from '../../../feedback/Reactions'; +import {TraceCostStats} from '../../CallPage/cost'; import {TraceCallSchema} from '../../wfReactInterface/traceServerClientTypes'; export const PlaygroundCallStats = ({call}: {call: TraceCallSchema}) => { - let totalTokens = 0; - if (call?.summary?.usage) { - for (const key of Object.keys(call.summary.usage)) { - totalTokens += - call.summary.usage[key].prompt_tokens || - call.summary.usage[key].input_tokens || - 0; - totalTokens += - call.summary.usage[key].completion_tokens || - call.summary.usage[key].output_tokens || - 0; - } - } - const [entityName, projectName] = call?.project_id?.split('/') || []; const callId = call?.id || ''; - const latency = call?.summary?.weave?.latency_ms; const {peekingRouter} = useWeaveflowRouteContext(); const history = useHistory(); @@ -43,21 +31,35 @@ export const PlaygroundCallStats = ({call}: {call: TraceCallSchema}) => { false ); + const latency = call?.summary?.weave?.latency_ms ?? 0; + const usageData = call?.summary?.usage; + const costData = call?.summary?.weave?.costs; + return ( -
- Latency: {latency}ms - +
+ {(call.output as any)?.choices?.[0]?.finish_reason && ( - <> - - Finish reason: {(call.output as any).choices[0].finish_reason} - - - + + + + } + /> )} - {totalTokens} tokens - {callLink && (