-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: improvements to evaluations results table
Fixes queue ordering as evaluations were being run after all document runts had completed which is not the best experience. Also added interval fetching of the table data to simulate real time experience. Finally, added collapsable convos in the log messages section in order to make that section more readable. To further improve this we need: 1. Decouple expensive queries from this view so that we can query table logs more freely 2. Add an independent queue dedicated to running evaluations in order to increase parallelism between document and evaluation runs
- Loading branch information
Showing
11 changed files
with
212 additions
and
38 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
apps/web/src/actions/evaluations/computeEvaluationResultsWithMetadata.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,40 @@ | ||
'use server' | ||
|
||
import { | ||
CommitsRepository, | ||
EvaluationsRepository, | ||
} from '@latitude-data/core/repositories' | ||
import { computeEvaluationResultsWithMetadata } from '@latitude-data/core/services/evaluationResults/computeEvaluationResultsWithMetadata' | ||
import { z } from 'zod' | ||
|
||
import { withProject } from '../procedures' | ||
|
||
export const computeEvaluationResultsWithMetadataAction = withProject | ||
.createServerAction() | ||
.input( | ||
z.object({ | ||
evaluationId: z.number(), | ||
documentUuid: z.string(), | ||
commitUuid: z.string(), | ||
}), | ||
) | ||
.handler(async ({ input, ctx }) => { | ||
const { documentUuid } = input | ||
const { workspace, project } = ctx | ||
const commitsScope = new CommitsRepository(workspace.id) | ||
const evaluationScope = new EvaluationsRepository(workspace.id) | ||
const evaluation = await evaluationScope | ||
.find(input.evaluationId) | ||
.then((r) => r.unwrap()) | ||
const commit = await commitsScope | ||
.getCommitByUuid({ projectId: project.id, uuid: input.commitUuid }) | ||
.then((r) => r.unwrap()) | ||
|
||
return await computeEvaluationResultsWithMetadata({ | ||
workspaceId: ctx.workspace.id, | ||
evaluation, | ||
documentUuid, | ||
draft: commit, | ||
limit: 1000, | ||
}).then((r) => r.unwrap()) | ||
}) |
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
36 changes: 33 additions & 3 deletions
36
...cuments/[documentUuid]/evaluations/[evaluationId]/_components/EvaluationResults/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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { useMemo } from 'react' | ||
|
||
import { EvaluationResultWithMetadata } from '@latitude-data/core/repositories' | ||
import { useToast } from '@latitude-data/web-ui' | ||
import { computeEvaluationResultsWithMetadataAction } from '$/actions/evaluations/computeEvaluationResultsWithMetadata' | ||
import useSWR, { SWRConfiguration } from 'swr' | ||
|
||
const EMPTY_ARRAY: [] = [] | ||
export default function useEvaluationResultsWithMetadata( | ||
{ | ||
evaluationId, | ||
documentUuid, | ||
commitUuid, | ||
projectId, | ||
}: { | ||
evaluationId: number | ||
documentUuid: string | ||
commitUuid: string | ||
projectId: number | ||
}, | ||
opts: SWRConfiguration, | ||
) { | ||
const { toast } = useToast() | ||
const { data = EMPTY_ARRAY, ...rest } = useSWR< | ||
EvaluationResultWithMetadata[] | ||
>( | ||
['evaluationResults', evaluationId, documentUuid, commitUuid, projectId], | ||
async () => { | ||
const [data, error] = await computeEvaluationResultsWithMetadataAction({ | ||
evaluationId, | ||
documentUuid, | ||
commitUuid, | ||
projectId, | ||
}) | ||
|
||
if (error) { | ||
toast({ | ||
title: 'Error fetching evaluations', | ||
description: error.formErrors?.[0] || error.message, | ||
variant: 'destructive', | ||
}) | ||
throw error | ||
} | ||
|
||
return data | ||
}, | ||
opts, | ||
) | ||
|
||
return useMemo(() => ({ data, ...rest }), [data, rest]) | ||
} |
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
75 changes: 58 additions & 17 deletions
75
packages/web-ui/src/ds/molecules/Chat/MessageList/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 |
---|---|---|
@@ -1,36 +1,77 @@ | ||
'use client' | ||
|
||
import { Fragment, useState } from 'react' | ||
|
||
import { Message as ConversationMessage } from '@latitude-data/compiler' | ||
import { Fragment } from 'react/jsx-runtime' | ||
|
||
import { Button } from '../../../atoms' | ||
import { Message, MessageProps } from '../Message' | ||
|
||
export function MessageList({ | ||
messages, | ||
variant, | ||
messageLayout, | ||
separator = false, | ||
collapsed = false, | ||
size, | ||
}: { | ||
messages: ConversationMessage[] | ||
variant?: MessageProps['variant'] | ||
messageLayout?: MessageProps['layout'] | ||
collapsed?: boolean | ||
size?: MessageProps['size'] | ||
separator?: boolean | ||
}) { | ||
return messages.map((message, index) => ( | ||
<Fragment key={index}> | ||
{separator && index > 0 && ( | ||
<div | ||
key={`${index}-separator`} | ||
className='h-px min-h-px w-full bg-border' | ||
/> | ||
const [isCollapsed, setIsCollapsed] = useState( | ||
collapsed && messages.length > 1, | ||
) | ||
|
||
const visibleMessages = isCollapsed ? messages.slice(-1) : messages | ||
const hiddenMessagesCount = messages.length - visibleMessages.length | ||
|
||
return ( | ||
<div className='flex flex-col gap-4'> | ||
{isCollapsed && messages.length > 1 && ( | ||
<div className='relative cursor-pointer h-24 overflow-hidden'> | ||
<div className='opacity-50 pointer-events-none absolute top-0 left-0 right-0 scale-90 origin-top'> | ||
<Message | ||
role={messages[messages.length - 2]!.role} | ||
content={messages[messages.length - 2]!.content} | ||
variant={variant} | ||
layout={messageLayout} | ||
size={size} | ||
/> | ||
</div> | ||
<div className='absolute inset-0 bg-gradient-to-t from-white via-white to-transparent' /> | ||
<div className='absolute bottom-0 left-0 right-0 text-center p-2 text-sm text-gray-600'> | ||
<Button variant='secondary' onClick={() => setIsCollapsed(false)}> | ||
{hiddenMessagesCount} previous{' '} | ||
{hiddenMessagesCount > 1 ? 'messages' : 'message'} | ||
</Button> | ||
</div> | ||
</div> | ||
)} | ||
{visibleMessages.map((message, index) => ( | ||
<Fragment key={index}> | ||
{separator && index > 0 && ( | ||
<div className='h-px min-h-px w-full bg-border' /> | ||
)} | ||
<Message | ||
role={message.role} | ||
content={message.content} | ||
variant={variant} | ||
layout={messageLayout} | ||
size={size} | ||
/> | ||
</Fragment> | ||
))} | ||
{!isCollapsed && messages.length > 1 && ( | ||
<div className='text-center cursor-pointer text-sm text-gray-600 hover:text-gray-800'> | ||
<Button variant='secondary' onClick={() => setIsCollapsed(true)}> | ||
Collapse conversation | ||
</Button> | ||
</div> | ||
)} | ||
<Message | ||
role={message.role} | ||
content={message.content} | ||
variant={variant} | ||
layout={messageLayout} | ||
size={size} | ||
/> | ||
</Fragment> | ||
)) | ||
</div> | ||
) | ||
} |