Skip to content

Commit

Permalink
Merge branch 'development' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
karthikscale3 committed Apr 19, 2024
2 parents 71ad0d5 + 42f1128 commit 0be2143
Show file tree
Hide file tree
Showing 28 changed files with 2,204 additions and 267 deletions.
561 changes: 561 additions & 0 deletions app/(protected)/project/[project_id]/evaluations/[test_id]/page.tsx

Large diffs are not rendered by default.

202 changes: 127 additions & 75 deletions app/(protected)/project/[project_id]/evaluations/page-client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@

import { EvalChart } from "@/components/charts/eval-chart";
import LargeChartSkeleton from "@/components/charts/large-chart-skeleton";
import { CreateTest } from "@/components/evaluations/create-test";
import { EditTest } from "@/components/evaluations/edit-test";
import EvaluationTable, {
EvaluationTableSkeleton,
} from "@/components/evaluations/evaluation-table";
import { AddtoDataset } from "@/components/shared/add-to-dataset";
import { Button } from "@/components/ui/button";
import { Separator } from "@/components/ui/separator";
import { Skeleton } from "@/components/ui/skeleton";
import { cn, getChartColor } from "@/lib/utils";
import { Test } from "@prisma/client";
import { ProgressCircle } from "@tremor/react";
import { RabbitIcon } from "lucide-react";
import { ChevronsRight, RabbitIcon } from "lucide-react";
import Link from "next/link";
import { useParams } from "next/navigation";
import { useState } from "react";
import { useQuery } from "react-query";
Expand Down Expand Up @@ -46,6 +50,7 @@ export default function PageClient({ email }: { email: string }) {
return result;
},
refetchOnWindowFocus: false,
refetchOnMount: true,
});

const {
Expand All @@ -61,9 +66,17 @@ export default function PageClient({ email }: { email: string }) {
throw new Error(error?.message || "Failed to fetch tests");
}
const result = await response.json();

// sort tests by created date
result.tests.sort(
(a: Test, b: Test) =>
new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime()
);

if (result?.tests?.length > 0) {
setSelectedTest(result?.tests?.[0]);
}

return result;
},
refetchOnWindowFocus: false,
Expand Down Expand Up @@ -94,88 +107,120 @@ export default function PageClient({ email }: { email: string }) {
<div className="w-full flex flex-col">
<div className="md:px-24 px-12 py-12 flex justify-between bg-muted">
<h1 className="text-3xl font-semibold">Evaluations</h1>
<AddtoDataset projectId={projectId} selectedData={selectedData} />
<div className="flex gap-2">
{selectedTest && (
<Link
href={`/project/${projectId}/evaluations/${selectedTest?.id}?page=1`}
>
<Button
className="bg-gradient-to-r from-pink-500 via-red-500 to-yellow-500 background-animate"
variant="default"
>
Start Testing <ChevronsRight className="ml-2" />{" "}
</Button>
</Link>
)}
<CreateTest projectId={projectId} variant={"outline"} />
{selectedTest && (
<EditTest projectId={projectId} test={selectedTest as Test} />
)}
</div>
</div>
{testAveragesLoading || testsLoading || !tests ? (
<PageSkeleton />
) : (
tests?.tests?.length > 0 && (
<div className="flex flex-row gap-4 absolute top-[14rem] w-full md:px-24 px-12">
<div className="bg-primary-foreground flex flex-col gap-0 border rounded-md w-[12rem] h-fit">
{tests?.tests?.map((test: Test, i: number) => {
const average =
testAverages?.averages?.find(
(avg: any) => avg.testId === test?.id
)?.average || 0;
return (
<div className="flex flex-col" key={i}>
<div
onClick={() => {
setSelectedTest(test);
setCurrentData([]);
setPage(1);
setTotalPages(1);
}}
) : tests?.tests?.length > 0 ? (
<div className="flex flex-row gap-4 absolute top-[14rem] w-full md:px-24 px-12">
<div className="bg-primary-foreground flex flex-col gap-0 border rounded-md w-[12rem] h-fit">
{tests?.tests?.map((test: Test, i: number) => {
const average =
testAverages?.averages?.find(
(avg: any) => avg.testId === test?.id
)?.average || 0;
return (
<div className="flex flex-col" key={i}>
<div
onClick={() => {
setSelectedTest(test);
setCurrentData([]);
setPage(1);
setTotalPages(1);
}}
className={cn(
"flex flex-col gap-4 p-4 items-start cursor-pointer",
i === 0 ? "rounded-t-md" : "",
i === tests?.tests?.length - 1 ? "rounded-b-md" : "",
selectedTest?.id === test.id
? "dark:bg-black bg-white border-l-2 border-primary"
: ""
)}
>
<p
className={cn(
"flex flex-col gap-4 p-4 items-start cursor-pointer",
i === 0 ? "rounded-t-md" : "",
i === tests?.tests?.length - 1 ? "rounded-b-md" : "",
selectedTest?.id === test.id
? "dark:bg-black bg-white border-l-2 border-primary"
: ""
"text-sm text-muted-foreground font-semibold capitalize",
selectedTest?.id === test.id ? "text-primary" : ""
)}
>
<p
className={cn(
"text-sm text-muted-foreground font-semibold capitalize",
selectedTest?.id === test.id ? "text-primary" : ""
)}
>
{test.name}
</p>
<ProgressCircle
color={getChartColor(average)}
value={average}
size="sm"
>
<span className="text-[0.6rem] text-primary font-bold">
{Math.round(average)}%
</span>
</ProgressCircle>
</div>
<Separator />
</div>
);
})}
</div>
<div className="bg-primary-foreground flex flex-col gap-12 border rounded-md w-full p-4 mb-24">
<div className="flex flex-row">
<div className="flex flex-col gap-3 items-start w-[25rem]">
<div className="flex flex-col gap-1">
<h1 className="text-xl font-semibold capitalize">
{selectedTest?.name} Evaluation
</h1>
<span className="text-xs font-semibold text-muted-foreground">
Test ID: {selectedTest?.id}
</span>
{test.name}
</p>
<ProgressCircle
color={getChartColor(average)}
value={average}
size="sm"
>
<span className="text-[0.6rem] text-primary font-bold">
{Math.round(average)}%
</span>
</ProgressCircle>
</div>
<ProgressCircle
color={getChartColor(testAverage)}
value={testAverage}
size="md"
>
<span className="text-sm text-primary font-bold">
{Math.round(testAverage)}%
</span>
</ProgressCircle>
<p className="text-sm text-muted-foreground">
{selectedTest?.description}
</p>
<Separator />
</div>
);
})}
</div>
<div className="bg-primary-foreground flex flex-col gap-12 border rounded-md w-full p-4 mb-24">
<div className="flex flex-row gap-2">
<div className="flex flex-col gap-4 items-start w-[25rem]">
<div className="flex flex-col gap-1">
<h1 className="text-xl font-semibold capitalize break-normal">
{selectedTest?.name} Evaluation
</h1>
<span className="text-xs font-semibold text-muted-foreground">
Test ID: {selectedTest?.id}
</span>
</div>
{selectedTest && (
<EvalChart projectId={projectId} test={selectedTest} />
)}
<div className="flex flex-col gap-1">
<span className="text-xs text-muted-foreground font-semibold">
Evaluation Scale
</span>
<span className="text-sm text-primary">
{selectedTest?.min} to {selectedTest?.max} in steps of +
{selectedTest?.step}
</span>
</div>
<ProgressCircle
color={getChartColor(testAverage)}
value={testAverage}
size="md"
>
<span className="text-sm text-primary font-bold">
{Math.round(testAverage)}%
</span>
</ProgressCircle>
<p className="text-sm text-muted-foreground">
{selectedTest?.description}
</p>
</div>
{selectedTest && (
<EvalChart projectId={projectId} test={selectedTest} />
)}
</div>
<div className="flex flex-col gap-2">
<AddtoDataset
projectId={projectId}
selectedData={selectedData}
className="w-fit self-end"
/>

{selectedTest && (
<EvaluationTable
projectId={projectId}
Expand All @@ -192,7 +237,14 @@ export default function PageClient({ email }: { email: string }) {
)}
</div>
</div>
)
</div>
) : (
<div className="md:px-52 px-12 py-12 flex flex-col gap-2 items-center justify-center">
<p className="text-sm text-muted-foreground font-semibold">
Create a test to get started.
</p>
<CreateTest projectId={projectId} />
</div>
)}
</div>
);
Expand Down
6 changes: 3 additions & 3 deletions app/(protected)/project/[project_id]/prompts/page-client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Checkbox } from "@/components/ui/checkbox";
import { Separator } from "@/components/ui/separator";
import { Skeleton } from "@/components/ui/skeleton";
import { PAGE_SIZE } from "@/lib/constants";
import { extractPromptFromLlmInputs } from "@/lib/utils";
import { extractSystemPromptFromLlmInputs } from "@/lib/utils";
import { CheckCircledIcon } from "@radix-ui/react-icons";
import { ChevronDown, ChevronRight, RabbitIcon } from "lucide-react";
import { useParams } from "next/navigation";
Expand Down Expand Up @@ -115,7 +115,7 @@ export default function PageClient({ email }: { email: string }) {
const dedupedPrompts = prompts.filter((prompt: any) => {
const attributes = prompt.attributes ? JSON.parse(prompt.attributes) : {};
const prompts: any[] = JSON.parse(attributes["llm.prompts"]) || "[]";
const promptContent = extractPromptFromLlmInputs(prompts);
const promptContent = extractSystemPromptFromLlmInputs(prompts);
if (promptContent.length === 0) {
return false;
}
Expand Down Expand Up @@ -211,7 +211,7 @@ const PromptRow = ({
// Get the evaluation for this prompt's content
const attributes = prompt.attributes ? JSON.parse(prompt.attributes) : {};
const prompts: any[] = JSON.parse(attributes["llm.prompts"]) || "[]";
const promptContent = extractPromptFromLlmInputs(prompts);
const promptContent = extractSystemPromptFromLlmInputs(prompts);

const fetchEvaluation = useQuery({
queryKey: [`fetch-evaluation-query-${prompt.span_id}`],
Expand Down
5 changes: 5 additions & 0 deletions app/(protected)/projects/page-client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ export default function PageClient({ email }: { email: string }) {
);
}

// sort projects by created date
projects?.projects?.sort((a: Project, b: Project) => {
return new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime();
});

return (
<div className="w-full flex flex-col">
<div className="md:px-52 px-12 py-12 flex justify-between bg-muted">
Expand Down
18 changes: 18 additions & 0 deletions app/api/project/route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { authOptions } from "@/lib/auth/options";
import { DEFAULT_TESTS } from "@/lib/constants";
import prisma from "@/lib/prisma";
import { getServerSession } from "next-auth";
import { redirect } from "next/navigation";
Expand Down Expand Up @@ -48,6 +49,10 @@ export async function POST(req: NextRequest) {

const data = await req.json();
const { name, description, teamId } = data;
let createDefaultTests = data.createDefaultTests;
if (!createDefaultTests) {
createDefaultTests = true; // default to true
}

const project = await prisma.project.create({
data: {
Expand All @@ -57,6 +62,19 @@ export async function POST(req: NextRequest) {
},
});

if (createDefaultTests) {
// create default tests
for (const test of DEFAULT_TESTS) {
await prisma.test.create({
data: {
name: test.name?.toLowerCase() ?? "",
description: test.description ?? "",
projectId: project.id,
},
});
}
}

return NextResponse.json({
data: project,
});
Expand Down
1 change: 0 additions & 1 deletion app/api/stats/account/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ export async function GET(req: NextRequest) {
totalSpans,
});
} catch (error) {
console.log(error);
return NextResponse.json(JSON.stringify({ error }), {
status: 400,
});
Expand Down
Loading

0 comments on commit 0be2143

Please sign in to comment.