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

Realtime evaluation result table update #248

Merged
merged 1 commit into from
Sep 25, 2024

Conversation

andresgutgon
Copy link
Contributor

@andresgutgon andresgutgon commented Sep 20, 2024

What?

When a evaluation is run show results in the frontend whenever they're processed

TODO

  • Fix weird jumping of table update when mutating with row from websockets
  • On finish run evaluation trigger update stats
  • Add test to check websocket is called when evaluation result is created

async decrementEnqueued() {
await this.redis.decr(this.getKey('enqueued'))
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe these 2 were not used

@andresgutgon andresgutgon added the 🚧 wip Work in progress label Sep 20, 2024
@andresgutgon andresgutgon marked this pull request as ready for review September 20, 2024 15:54
@andresgutgon andresgutgon force-pushed the feature/realtime-evaluation-result-table-update branch from 237a175 to 2c9350e Compare September 23, 2024 13:55
@andresgutgon andresgutgon removed the 🚧 wip Work in progress label Sep 23, 2024
@andresgutgon andresgutgon force-pushed the feature/realtime-evaluation-result-table-update branch 5 times, most recently from 050463f to b41280e Compare September 24, 2024 10:07
@andresgutgon andresgutgon force-pushed the feature/realtime-evaluation-result-table-update branch from b41280e to 6b6097c Compare September 25, 2024 07:09
documentUuid,
evaluationId,
})
const { refetch: refetchTotals } = useEvaluationResultsCounters({
Copy link
Collaborator

Choose a reason for hiding this comment

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

is this refetch actually the mutate function? if so i wouldn't rename it it's better to expose the real name so devs understand what they can do with this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I knew this will come out. I don't agree in this case to be honest. I think fetch express better the intention here

Copy link
Contributor

Choose a reason for hiding this comment

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

If this function just triggers a new request to update the data, I agree with @andresgutgon here ☝️

Copy link
Collaborator

Choose a reason for hiding this comment

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

but it doesn't just do that, you can also pass it data to mutate the store

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In general yes, but in this use case is a refetch. We're talking semantics here

<ProgressIndicator state='running'>
{`Running batch evaluation ${job.completed}/${job.total}`}
</ProgressIndicator>
)}
{job.errors > 0 && !isDone(job) && (
{job.errors > 0 && !isEvaluationRunDone(job) && (
Copy link
Collaborator

Choose a reason for hiding this comment

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

actually better to not remove this message even when it's done

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How they can remove the message?

Copy link
Collaborator

Choose a reason for hiding this comment

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

navigating away

documentUuid: string
commit: Commit
}): Promise<ReturnType<T>> {
const aggregationTotals = await getEvaluationTotalsQuery({
Copy link
Collaborator

Choose a reason for hiding this comment

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

are these methods cached? add the suffix if so

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not cached. Should they be cached? It's only called once here in the server

Copy link
Collaborator

Choose a reason for hiding this comment

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

i always cache by default tbh, might not be necessary

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My rule of thumb is import { cache } from 'react' is like a Rails per request singleton. Like current_user. Only useful when is used more than once during that request.

evaluationResults={evaluationResults}
evaluation={evaluation}
isNumeric={isNumeric}
Copy link
Collaborator

Choose a reason for hiding this comment

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

you are already passing the evalution to the content component you don't need this derived state prop also

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I use to type the component with a generic

) {
const { project } = useCurrentProject()
const fetcher = useCallback(async () => {
const [data, error] = await computeEvaluationResultsCountersAction({
Copy link
Collaborator

Choose a reason for hiding this comment

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

it's a pita so don't do it, but next time remember not to use server actions for fetching instead use regular api endpoints

Copy link
Contributor

Choose a reason for hiding this comment

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

Why? I feel like having to use regular api endpoints are more pita than server actions.

Copy link
Collaborator

@geclos geclos Sep 25, 2024

Choose a reason for hiding this comment

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

server actions are all post requests which doesn't allow for http caching, even react docs recommend not using server actions for fetching https://react.dev/reference/rsc/use-server#caveats

We've already implemented the first api endpoint so adding more it's trivial now

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree with pain in my heart

},
})
})
})
Copy link
Collaborator

Choose a reason for hiding this comment

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

nice!

evaluationId: evaluation.id,
documentUuid: document.documentUuid,
},
})
})
})
Copy link
Collaborator

Choose a reason for hiding this comment

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

nice!

evaluationId: evaluation.id,
evaluationResultId: evaluationResult.id,
row: evaluationResultWithMetadata,
},
Copy link
Collaborator

Choose a reason for hiding this comment

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

you are including workspaceId two times? not a big deal but weird

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The convention I have is that what is inside data is what is send to the browser. the workspaceId from outside is for the websocket server to know to what room has to send the info.
https://github.com/latitude-dev/latitude-llm/blob/main/apps/websockets/src/server.ts#L143

)
const result = await baseQuery
.where(eq(evaluationResultsScope.id, evaluationResult.id))
.limit(1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

hmm weird way of building the query why didn't u use a repository?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

baseQuery is using repositories

Copy link
Collaborator

Choose a reason for hiding this comment

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

but why not EvaluationResultsRepository(...).find(evaluationResult.id) y ya esta?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The baseQuery brings same aggregations used in the table

@andresgutgon andresgutgon force-pushed the feature/realtime-evaluation-result-table-update branch from 9ce87a4 to d5e5428 Compare September 25, 2024 09:55
@andresgutgon andresgutgon merged commit 8f944ab into main Sep 25, 2024
4 checks passed
@andresgutgon andresgutgon deleted the feature/realtime-evaluation-result-table-update branch September 25, 2024 10:24
@github-actions github-actions bot locked and limited conversation to collaborators Sep 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants