Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style(weave): add icons to trace tree #3227

Merged
merged 3 commits into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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();

Expand All @@ -43,21 +31,34 @@ 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 (
<Tailwind>
<div className="flex w-full flex-wrap items-center justify-center gap-8 py-8 text-sm text-moon-500">
<span>Latency: {latency}ms</span>
<span>•</span>
<div className="flex w-full items-center justify-center gap-8 py-8">
<TraceCostStats
usageData={usageData}
costData={costData}
latency_ms={latency}
costLoading={false}
/>
{(call.output as any)?.choices?.[0]?.finish_reason && (
<>
<span>
Finish reason: {(call.output as any).choices[0].finish_reason}
</span>
<span>•</span>
</>
<Tooltip
content="Finish Reason"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer sentence case

trigger={
<span>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a Pill renders a div, so this should probably be a block level element like div too.

<Pill
icon="checkmark-circle"
label={(call.output as any).choices[0].finish_reason}
color="moon"
className="-ml-[8px] bg-transparent text-moon-500 dark:bg-transparent dark:text-moon-500"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know you could write the negative margin that way in Tailwind, I think I've always done it ml-[-8px]. Interesting!

/>
</span>
}
/>
)}
<span>{totalTokens} tokens</span>
<span>•</span>
{callLink && (
<Button
size="small"
Expand Down
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Cool. TY!

Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,28 @@ export const PlaygroundPageInner = (props: PlaygroundPageProps) => {
callId: props.callId,
}
: null;
}, [props.entity, props.project, props.callId])
}, [props.entity, props.project, props.callId]),
{
includeCosts: true,
}
);

const {result: calls} = useCalls(props.entity, props.project, {
callIds: playgroundStates.map(state => state.traceCall.id || ''),
});
const {result: calls} = useCalls(
props.entity,
props.project,
{
callIds: playgroundStates.map(state => state.traceCall.id || ''),
},
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
{
includeCosts: true,
}
);

useEffect(() => {
if (!call.loading && call.result) {
Expand Down
Loading