-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c087a2b
commit fdd20c2
Showing
29 changed files
with
2,237 additions
and
1,633 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
apps/web/src/actions/evaluationResults/computeEvaluationResultsCountersAction.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
'use server' | ||
|
||
import { EvaluationsRepository } from '@latitude-data/core/repositories' | ||
import { getEvaluationTotalsQuery } from '@latitude-data/core/services/evaluationResults/index' | ||
import { findCommitCached } from '$/app/(private)/_data-access' | ||
import { z } from 'zod' | ||
|
||
import { withDocument } from '../procedures' | ||
|
||
export const computeEvaluationResultsCountersAction = withDocument | ||
.createServerAction() | ||
.input( | ||
z.object({ | ||
commitUuid: z.string(), | ||
documentUuid: z.string(), | ||
evaluationId: z.number(), | ||
}), | ||
) | ||
.handler(async ({ input, ctx }) => { | ||
const { evaluationId, documentUuid } = input | ||
const { workspace } = ctx | ||
const evaluationScope = new EvaluationsRepository(workspace.id) | ||
const commit = await findCommitCached({ | ||
projectId: ctx.project.id, | ||
uuid: input.commitUuid, | ||
}) | ||
const evaluation = await evaluationScope | ||
.find(evaluationId) | ||
.then((r) => r.unwrap()) | ||
return getEvaluationTotalsQuery({ | ||
workspaceId: workspace.id, | ||
commit, | ||
evaluation, | ||
documentUuid, | ||
}) | ||
}) |
36 changes: 36 additions & 0 deletions
36
apps/web/src/actions/evaluationResults/computeEvaluationResultsMeanValueAction.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
'use server' | ||
|
||
import { EvaluationsRepository } from '@latitude-data/core/repositories' | ||
import { getEvaluationMeanValueQuery } from '@latitude-data/core/services/evaluationResults/index' | ||
import { findCommitCached } from '$/app/(private)/_data-access' | ||
import { z } from 'zod' | ||
|
||
import { withDocument } from '../procedures' | ||
|
||
export const computeEvaluationResultsMeanValueAction = withDocument | ||
.createServerAction() | ||
.input( | ||
z.object({ | ||
commitUuid: z.string(), | ||
documentUuid: z.string(), | ||
evaluationId: z.number(), | ||
}), | ||
) | ||
.handler(async ({ input, ctx }) => { | ||
const { evaluationId, documentUuid } = input | ||
const { workspace } = ctx | ||
const evaluationScope = new EvaluationsRepository(workspace.id) | ||
const commit = await findCommitCached({ | ||
projectId: ctx.project.id, | ||
uuid: input.commitUuid, | ||
}) | ||
const evaluation = await evaluationScope | ||
.find(evaluationId) | ||
.then((r) => r.unwrap()) | ||
return getEvaluationMeanValueQuery({ | ||
workspaceId: workspace.id, | ||
commit, | ||
evaluation, | ||
documentUuid, | ||
}) | ||
}) |
36 changes: 36 additions & 0 deletions
36
apps/web/src/actions/evaluationResults/computeEvaluationResultsModalValueAction.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
'use server' | ||
|
||
import { EvaluationsRepository } from '@latitude-data/core/repositories' | ||
import { getEvaluationModalValueQuery } from '@latitude-data/core/services/evaluationResults/index' | ||
import { findCommitCached } from '$/app/(private)/_data-access' | ||
import { z } from 'zod' | ||
|
||
import { withDocument } from '../procedures' | ||
|
||
export const computeEvaluationResultsModalValueAction = withDocument | ||
.createServerAction() | ||
.input( | ||
z.object({ | ||
commitUuid: z.string(), | ||
documentUuid: z.string(), | ||
evaluationId: z.number(), | ||
}), | ||
) | ||
.handler(async ({ input, ctx }) => { | ||
const { evaluationId, documentUuid } = input | ||
const { workspace } = ctx | ||
const evaluationScope = new EvaluationsRepository(workspace.id) | ||
const commit = await findCommitCached({ | ||
projectId: ctx.project.id, | ||
uuid: input.commitUuid, | ||
}) | ||
const evaluation = await evaluationScope | ||
.find(evaluationId) | ||
.then((r) => r.unwrap()) | ||
return getEvaluationModalValueQuery({ | ||
workspaceId: workspace.id, | ||
commit, | ||
evaluation, | ||
documentUuid, | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...ations/[evaluationId]/_components/MetricsSummary/BigNumberPanels/MeanValuePanel/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
'use client' | ||
|
||
import { Evaluation, EvaluationMeanValue } from '@latitude-data/core/browser' | ||
import { RangeBadge } from '@latitude-data/web-ui' | ||
import useEvaluationResultsMeanValue from '$/stores/evaluationResultCharts/evaluationResultsMeanValue' | ||
|
||
import Panel from '../Panel' | ||
|
||
export default function MeanValuePanel({ | ||
mean, | ||
commitUuid, | ||
documentUuid, | ||
evaluation, | ||
}: { | ||
commitUuid: string | ||
documentUuid: string | ||
evaluation: Evaluation | ||
mean: EvaluationMeanValue | ||
}) { | ||
const { data } = useEvaluationResultsMeanValue( | ||
{ | ||
commitUuid, | ||
documentUuid, | ||
evaluationId: evaluation.id, | ||
}, | ||
{ | ||
revalidateOnFocus: true, | ||
revalidateOnMount: false, | ||
revalidateOnReconnect: false, | ||
refreshWhenOffline: false, | ||
refreshWhenHidden: false, | ||
refreshInterval: 0, | ||
fallbackData: mean, | ||
}, | ||
) | ||
const config = evaluation.configuration.detail! | ||
const defaultMinValue = config.range.from | ||
const defaultMaxValue = config.range.to | ||
return ( | ||
<Panel | ||
label='Current average' | ||
additionalInfo='The mean value of all the evaluated results from the current version.' | ||
> | ||
<div className='w-fit'> | ||
<RangeBadge | ||
minValue={data?.minValue ?? defaultMinValue} | ||
maxValue={data?.maxValue ?? defaultMaxValue} | ||
value={data?.meanValue ?? 0} | ||
/> | ||
</div> | ||
</Panel> | ||
) | ||
} |
48 changes: 48 additions & 0 deletions
48
...tions/[evaluationId]/_components/MetricsSummary/BigNumberPanels/ModalValuePanel/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
'use client' | ||
|
||
import { EvaluationModalValue } from '@latitude-data/core/browser' | ||
import { Text } from '@latitude-data/web-ui' | ||
import useEvaluationResultsModalValue from '$/stores/evaluationResultCharts/evaluationResultsModalValue' | ||
|
||
import Panel from '../Panel' | ||
|
||
export default function ModalValuePanel({ | ||
modal, | ||
commitUuid, | ||
documentUuid, | ||
evaluationId, | ||
}: { | ||
commitUuid: string | ||
documentUuid: string | ||
evaluationId: number | ||
modal: EvaluationModalValue | ||
}) { | ||
const { data } = useEvaluationResultsModalValue( | ||
{ | ||
commitUuid, | ||
documentUuid, | ||
evaluationId, | ||
}, | ||
{ | ||
revalidateOnFocus: true, | ||
revalidateOnMount: false, | ||
revalidateOnReconnect: false, | ||
refreshWhenOffline: false, | ||
refreshWhenHidden: false, | ||
refreshInterval: 0, | ||
fallbackData: modal, | ||
}, | ||
) | ||
return ( | ||
<Panel | ||
label='Value more repeated' | ||
additionalInfo='Value more repeated in the evaluation results.' | ||
> | ||
<Text.H3B>{data?.mostCommon ?? '-'}</Text.H3B> | ||
<Text.H3 color='foregroundMuted'> | ||
{' '} | ||
It appeared ({data?.percentage ?? '0'}%) | ||
</Text.H3> | ||
</Panel> | ||
) | ||
} |
52 changes: 52 additions & 0 deletions
52
...id]/evaluations/[evaluationId]/_components/MetricsSummary/BigNumberPanels/Panel/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
'use client' | ||
|
||
import { ReactNode, useCallback, useState } from 'react' | ||
|
||
import { Icon, Text, Tooltip } from '@latitude-data/web-ui' | ||
|
||
export default function Panel({ | ||
label, | ||
value, | ||
additionalInfo, | ||
children, | ||
}: { | ||
label: string | ||
value?: string | ||
additionalInfo?: string | ||
children?: ReactNode | ||
}) { | ||
const [open, setOpen] = useState(false) | ||
// On hover panel show tooltip with additional info | ||
const onMouseEnter = useCallback(() => { | ||
if (!additionalInfo) return | ||
|
||
setOpen(true) | ||
}, [additionalInfo]) | ||
const onMouseLeave = useCallback(() => { | ||
setOpen(false) | ||
}, []) | ||
return ( | ||
<Tooltip | ||
open={open} | ||
align='end' | ||
trigger={ | ||
<div | ||
className='min-w-44 flex-1 flex flex-col gap-1 p-4 rounded-lg border border-border' | ||
onMouseEnter={onMouseEnter} | ||
onMouseLeave={onMouseLeave} | ||
> | ||
<div className='flex flex-row justify-between items-center gap-1'> | ||
<Text.H5 color='foregroundMuted'>{label}</Text.H5> | ||
{additionalInfo && ( | ||
<Icon name='info' className='text-muted-foreground' /> | ||
)} | ||
</div> | ||
{value && <Text.H3B>{value}</Text.H3B>} | ||
{children} | ||
</div> | ||
} | ||
> | ||
<Text.H5 color='white'>{additionalInfo}</Text.H5> | ||
</Tooltip> | ||
) | ||
} |
47 changes: 47 additions & 0 deletions
47
...luations/[evaluationId]/_components/MetricsSummary/BigNumberPanels/TotalsPanels/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
'use client' | ||
|
||
import { EvaluationAggregationTotals } from '@latitude-data/core/browser' | ||
import { formatCostInMillicents } from '$/app/_lib/formatUtils' | ||
import useEvaluationResultsCounters from '$/stores/evaluationResultCharts/evaluationResultsCounters' | ||
|
||
import Panel from '../Panel' | ||
|
||
export default function TotalsPanels({ | ||
aggregation, | ||
commitUuid, | ||
documentUuid, | ||
evaluationId, | ||
}: { | ||
commitUuid: string | ||
documentUuid: string | ||
evaluationId: number | ||
aggregation: EvaluationAggregationTotals | ||
}) { | ||
const { data } = useEvaluationResultsCounters( | ||
{ | ||
commitUuid, | ||
documentUuid, | ||
evaluationId, | ||
}, | ||
{ | ||
revalidateOnFocus: true, | ||
revalidateOnMount: false, | ||
revalidateOnReconnect: false, | ||
refreshWhenOffline: false, | ||
refreshWhenHidden: false, | ||
refreshInterval: 0, | ||
fallbackData: aggregation, | ||
}, | ||
) | ||
const cost = | ||
typeof data.costInMillicents === 'string' | ||
? '-' | ||
: formatCostInMillicents(data.costInMillicents) | ||
return ( | ||
<> | ||
<Panel label='Total logs' value={String(data.totalCount)} /> | ||
<Panel label='Total cost' value={cost} /> | ||
<Panel label='Total tokens' value={String(data.tokens)} /> | ||
</> | ||
) | ||
} |
Oops, something went wrong.