Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/mattpocock/evalite into mat…
Browse files Browse the repository at this point in the history
…t/add-historical-view
  • Loading branch information
mattpocock committed Dec 10, 2024
2 parents c001d31 + babe875 commit 24afd0d
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 46 deletions.
10 changes: 1 addition & 9 deletions apps/evalite-ui/app/components/page-layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ import { SidebarTrigger } from "./ui/sidebar";

export const InnerPageLayout = ({
children,
title,
filepath,
vscodeUrl,
}: {
title: string;
vscodeUrl: string;
filepath: string;
children: React.ReactNode;
Expand All @@ -27,12 +25,6 @@ export const InnerPageLayout = ({
<Separator orientation="vertical" className="mr-2 h-4" />
<Breadcrumb>
<BreadcrumbList>
<BreadcrumbItem>
<BreadcrumbPage className="line-clamp-1">
{title}
</BreadcrumbPage>
</BreadcrumbItem>
<Separator orientation="vertical" className="mx-1 h-4" />
<BreadcrumbItem>
<BreadcrumbLink className="line-clamp-1" asChild>
<a href={vscodeUrl}>{filepath}</a>
Expand All @@ -42,7 +34,7 @@ export const InnerPageLayout = ({
</Breadcrumb>
</div>
</header>
<div className="flex flex-1 flex-col gap-4 p-4">{children}</div>
<div className="flex-1 p-4">{children}</div>
</div>
);
};
4 changes: 3 additions & 1 deletion apps/evalite-ui/app/components/score.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ export const Score = (props: {
}) => {
return (
<span className="flex items-center space-x-2">
<span>{Math.round(props.score * 100)}%</span>
<span>
{Math.round((Number.isNaN(props.score) ? 0 : props.score) * 100)}%
</span>
{(() => {
switch (true) {
case props.isRunning:
Expand Down
4 changes: 3 additions & 1 deletion apps/evalite-ui/app/components/ui/live-date.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { formatDistance } from "date-fns";
import { useEffect, useState } from "react";

const ONE_MINUTE = 60_000;

export const LiveDate = (props: { date: string }) => {
const [, setNow] = useState(new Date());
useEffect(() => {
const interval = setInterval(() => {
setNow(new Date());
}, 1000);
}, ONE_MINUTE);
return () => clearInterval(interval);
}, []);
return (
Expand Down
44 changes: 37 additions & 7 deletions apps/evalite-ui/app/routes/eval.$name.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getEvalByName } from "@evalite/core/sdk";
import { average, sum } from "@evalite/core/utils";
import type { MetaFunction } from "@remix-run/node";
import {
NavLink,
Expand All @@ -12,6 +13,7 @@ import { DisplayInput } from "~/components/display-input";
import { InnerPageLayout } from "~/components/page-layout";
import { getScoreState, Score } from "~/components/score";
import { MyLineChart } from "~/components/ui/line-chart";
import { LiveDate } from "~/components/ui/live-date";
import { Separator } from "~/components/ui/separator";
import {
Table,
Expand All @@ -22,6 +24,7 @@ import {
} from "~/components/ui/table";
import { cn } from "~/lib/utils";
import { TestServerStateContext } from "~/use-subscribe-to-socket";
import { formatTime } from "~/utils";

export const meta: MetaFunction<typeof clientLoader> = (args) => {
return [
Expand Down Expand Up @@ -53,13 +56,43 @@ export default function Page() {

const isTraceRoute = location.pathname.includes("trace");

const score = average(evaluation.results, (r) =>
average(r.scores, (s) => s.score)
);

const prevScore = prevEvaluation
? average(prevEvaluation.results, (r) => average(r.scores, (s) => s.score))
: undefined;

return (
<>
<InnerPageLayout
title={name}
vscodeUrl={`vscode://file${evaluation.filepath}`}
filepath={evaluation.filepath.split(/(\/|\\)/).slice(-1)[0]!}
>
<div className="text-gray-600 mb-10 text-sm">
<h1 className="tracking-tight text-2xl mb-2 font-medium text-gray-700">
{name}
</h1>
<div className="flex items-center">
<Score
evalStatus={evaluation.status}
isRunning={
serverState.state.type === "running" &&
serverState.state.filepaths.has(evaluation.filepath)
}
score={score}
state={getScoreState(score, prevScore)}
></Score>
<Separator orientation="vertical" className="h-4 mx-4" />
<span>{formatTime(evaluation.duration)}</span>
<Separator orientation="vertical" className="h-4 mx-4" />
<span>
<LiveDate date={evaluation.created_at} />
</span>
</div>
</div>

{evaluation.status === "fail" && (
<div className="flex gap-4 px-4">
<div className="flex-shrink-0">
Expand All @@ -77,17 +110,14 @@ export default function Page() {
{evaluation.status === "success" && (
<div className="">
{history.length > 1 && (
<>
<div className="mb-10">
<h2 className="mb-4 font-medium text-lg text-gray-600">
History
</h2>
{history.length > 1 && <MyLineChart data={history} />}
<Separator orientation="horizontal" className="my-8" />
<h2 className="mb-4 font-medium text-lg text-gray-600">
Results
</h2>
</>
</div>
)}
<h2 className="mb-4 font-medium text-lg text-gray-600">Results</h2>
<Table>
<TableHeader>
<TableRow>
Expand Down
1 change: 0 additions & 1 deletion packages/evalite-core/src/db/tests/db.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ describe("getEvalsAverageScores", () => {
meta: {
evalite: {
duration: 100,
sourceCodeHash: "abc",
results: [
{
input: "input",
Expand Down
1 change: 0 additions & 1 deletion packages/evalite-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ export declare namespace Evalite {
export type TaskMeta = {
results: Result[];
duration: number | undefined;
sourceCodeHash: string;
};

export type Task<TInput, TExpected> = (
Expand Down
7 changes: 0 additions & 7 deletions packages/evalite/src/command.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import { Command } from "commander";
import { runVitest } from "./run-vitest.js";
import { createDatabase } from "@evalite/core/db";

declare module "vitest" {
export interface ProvidedContext {
evaliteInputHash: string;
}
}

export const program = new Command();

Expand Down
3 changes: 0 additions & 3 deletions packages/evalite/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ export const evalite = <TInput, TExpected = TInput>(
opts: Evalite.RunnerOpts<TInput, TExpected>
) => {
return it(testName, async ({ task }) => {
const sourceCodeHash = inject("evaliteInputHash");

const data = await opts.data();
const start = performance.now();
const results = await Promise.all(
Expand All @@ -107,7 +105,6 @@ export const evalite = <TInput, TExpected = TInput>(
task.meta.evalite = {
results,
duration: Math.round(performance.now() - start),
sourceCodeHash,
};
});
};
Expand Down
16 changes: 0 additions & 16 deletions packages/evalite/src/run-vitest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,6 @@ export const runVitest = async (opts: {
}
);

await vitest.collect(filters);

const allFileResults = Array.from(vitest.vitenode.fetchCache);

const sourceFileResults = allFileResults.filter(([path, item]) => {
return !(path.endsWith(".eval.ts") || path.endsWith(".eval.js"));
});

const codeFromSourceFiles = sourceFileResults.reduce((acc, [path, item]) => {
return acc + (item.result.code ?? "");
}, "");

const hash = createHash("sha256").update(codeFromSourceFiles).digest("hex");

vitest.provide("evaliteInputHash", hash);

await vitest.start(filters);

const dispose = registerConsoleShortcuts(
Expand Down

0 comments on commit 24afd0d

Please sign in to comment.