Skip to content

Commit

Permalink
[Feat]: adding playground to compare your evaluations from different …
Browse files Browse the repository at this point in the history
…providers (openlit#266)

Co-authored-by: patcher9 <[email protected]>
  • Loading branch information
AmanAgarwal041 and patcher9 authored Jun 16, 2024
1 parent aa27a46 commit 5d2d205
Show file tree
Hide file tree
Showing 48 changed files with 5,925 additions and 941 deletions.
4,592 changes: 3,707 additions & 885 deletions src/client/package-lock.json

Large diffs are not rendered by default.

43 changes: 26 additions & 17 deletions src/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@
"seed": "npx prisma db seed"
},
"dependencies": {
"@clickhouse/client": "^0.3.0",
"@anthropic-ai/sdk": "^0.21.1",
"@clickhouse/client": "^1.1.0",
"@dhmk/zustand-lens": "^4.0.0",
"@mistralai/mistralai": "^0.4.0",
"@next-auth/prisma-adapter": "^1.0.7",
"@prisma/client": "^5.11.0",
"@prisma/client": "^5.15.0",
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-dropdown-menu": "^2.0.6",
"@radix-ui/react-hover-card": "^1.0.7",
"@radix-ui/react-label": "^2.0.2",
"@radix-ui/react-popover": "^1.0.7",
"@radix-ui/react-scroll-area": "^1.0.5",
Expand All @@ -26,41 +29,47 @@
"@radix-ui/react-switch": "^1.0.3",
"@radix-ui/react-tabs": "^1.0.4",
"@radix-ui/react-tooltip": "^1.0.7",
"@tanstack/react-table": "^8.17.3",
"@textea/json-viewer": "^3.4.1",
"bcrypt-ts": "^5.0.1",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.0",
"clsx": "^2.1.1",
"cmdk": "^1.0.0",
"cohere-ai": "^7.10.5",
"copy-to-clipboard": "^3.3.3",
"date-fns": "^3.6.0",
"generic-pool": "^3.9.0",
"js-tiktoken": "^1.0.12",
"lodash": "^4.17.21",
"lucide-react": "^0.366.0",
"next": "14.0.4",
"next": "^14.2.4",
"next-auth": "^4.24.7",
"next-themes": "^0.3.0",
"react": "^18",
"openai": "^4.50.0",
"react": "^18.3.1",
"react-day-picker": "^8.10.1",
"react-dom": "^18",
"react-dom": "^18.3.1",
"react-resizable-panels": "^2.0.19",
"react-syntax-highlighter": "^15.5.0",
"recharts": "^2.12.6",
"sonner": "^1.4.41",
"recharts": "^2.12.7",
"sonner": "^1.5.0",
"tailwind-merge": "^2.2.2",
"tailwindcss-animate": "^1.0.7",
"tiny-cookie": "^2.5.1",
"zustand": "^4.5.2"
},
"devDependencies": {
"@types/lodash": "^4.14.202",
"@types/node": "^20.11.30",
"@types/react": "^18",
"@types/react-dom": "^18",
"@types/react-syntax-highlighter": "^15.5.11",
"@types/lodash": "^4.17.5",
"@types/node": "^20.14.2",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@types/react-syntax-highlighter": "^15.5.13",
"autoprefixer": "^10.0.1",
"eslint": "^8",
"eslint-config-next": "14.1.4",
"eslint": "^8.57.0",
"eslint-config-next": "^14.1.4",
"postcss": "^8",
"prisma": "^5.12.1",
"tailwindcss": "^3.3.0",
"prisma": "^5.15.0",
"tailwindcss": "^3.4.4",
"typescript": "^5.4.4"
},
"prisma": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-- CreateTable
CREATE TABLE "openground" (
"id" TEXT NOT NULL PRIMARY KEY,
"requestMeta" TEXT NOT NULL,
"responseMeta" TEXT NOT NULL,
"stats" TEXT NOT NULL,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"user_id" TEXT NOT NULL,
"database_config_id" TEXT NOT NULL,
CONSTRAINT "openground_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT "openground_database_config_id_fkey" FOREIGN KEY ("database_config_id") REFERENCES "databaseconfig" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
);
68 changes: 42 additions & 26 deletions src/client/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ model Account {
provider String
providerAccountId String @map("provider_account_id")
token_type String?
refresh_token String?
access_token String?
refresh_token String?
access_token String?
expires_at Int?
scope String?
id_token String?
id_token String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
Expand All @@ -42,18 +42,19 @@ model Session {
}

model User {
id String @id @default(uuid())
name String?
email String @unique
emailVerified DateTime? @map("email_verified")
password String?
image String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
accounts Account[]
sessions Session[]
dbConfigs DatabaseConfigUser[]
id String @id @default(uuid())
name String?
email String @unique
emailVerified DateTime? @map("email_verified")
password String?
image String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
accounts Account[]
sessions Session[]
dbConfigs DatabaseConfigUser[]
createdDBConfigs DatabaseConfig[]
OpenGround OpenGround[]
@@map("users")
}
Expand All @@ -72,20 +73,21 @@ model VerificationRequest {

// Database Config
model DatabaseConfig {
id String @id @default(cuid())
id String @id @default(cuid())
name String
environment String @default("production")
username String @default("admin")
password String?
host String @default("127.0.0.1")
port String @default("8123")
database String @default("openlit")
query String?
environment String @default("production")
username String @default("admin")
password String?
host String @default("127.0.0.1")
port String @default("8123")
database String @default("openlit")
query String?
dbUsers DatabaseConfigUser[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
createdByUserId String @map("user_id")
createdByUser User @relation(fields: [createdByUserId], references: [id])
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
createdByUserId String @map("user_id")
createdByUser User @relation(fields: [createdByUserId], references: [id])
OpenGround OpenGround[]
@@unique([name])
@@map("databaseconfig")
Expand All @@ -101,3 +103,17 @@ model DatabaseConfigUser {
@@unique([databaseConfigId, userId])
@@map("databaseconfiguser")
}

model OpenGround {
id String @id @default(cuid())
requestMeta String
responseMeta String
stats String
createdAt DateTime @default(now())
createdByUserId String @map("user_id")
createdByUser User @relation(fields: [createdByUserId], references: [id])
databaseConfigId String @map("database_config_id")
databaseConfig DatabaseConfig @relation(fields: [databaseConfigId], references: [id])
@@map("openground")
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/client/public/images/provider/anthropic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/client/public/images/provider/cohere.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/client/public/images/provider/mistral.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/client/public/images/provider/openai.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/client/src/app/(playground)/database-config/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ function DatabaseList({
</p>
{dbConfigs.length !== 0 && (
<Button
className="mt-4"
className="mt-4 item-element-card"
data-item-id={"ADD_NEW_ID"}
onClick={onClickDB}
>
Expand Down
77 changes: 77 additions & 0 deletions src/client/src/app/(playground)/openground/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
"use client";
import OpengroundHeader from "@/components/(playground)/openground/header";
import ProviderTable from "@/components/(playground)/openground/provider-table";
import { providersConfig } from "@/constants/openground";
import { Providers } from "@/store/openground";
import useFetchWrapper from "@/utils/hooks/useFetchWrapper";
import { useCallback, useEffect } from "react";
import { toast } from "sonner";
import RequestInfo from "./request-info";

export default function OpengroundRequest({
params,
}: {
params: { id: string };
}) {
const { data, fireRequest, isFetched, isLoading } = useFetchWrapper();
const fetchData = useCallback(async () => {
fireRequest({
requestType: "GET",
url: `/api/openground/${params.id}`,
failureCb: (err?: string) => {
toast.error(err || `Cannot connect to server!`, {
id: "openground",
});
},
});
}, []);

useEffect(() => {
fetchData();
}, []);

if (isLoading || !isFetched)
return (
<div className="flex w-full h-full text-stone-600 dark:text-stone-400 items-center justify-center">
Loading
</div>
);

const [error, updatedData] = (data as any[]) || [];

if (error || !updatedData)
return (
<div className="flex w-full h-full text-error items-center justify-center">
{error || "No such request present"}
</div>
);

const responseMeta = updatedData.responseMeta;
const requestMeta = updatedData.requestMeta;

return (
<div className="flex flex-col w-full h-full gap-4">
<OpengroundHeader
title={`Request id : ${updatedData.id}`}
validateResponse={false}
/>
<RequestInfo data={updatedData} />
<div className="flex w-full h-full bg-stone-100 grow dark:bg-stone-900 overflow-auto transition-all relative gap-1">
{requestMeta.selectedProviders?.map(
({ provider }: { provider: Providers }, index: number) => (
<ProviderTable
key={`provider-${index}`}
provider={providersConfig[provider]}
index={index}
selectedProviders={requestMeta.selectedProviders}
evaluatedResponse={{
isLoading: false,
data: responseMeta,
}}
/>
)
)}
</div>
</div>
);
}
64 changes: 64 additions & 0 deletions src/client/src/app/(playground)/openground/[id]/request-info.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { Separator } from "@/components/ui/separator";
import { format } from "date-fns";

const InfoPill = ({ title, value }: { title: string; value: any }) => {
return (
<Button
variant="outline"
size="default"
className="text-stone-500 dark:text-stone-400 dark:bg-stone-800 cursor-default"
>
{title}
<Separator
orientation="vertical"
className="mx-2 h-4 bg-stone-300 dark:bg-stone-600"
/>
<Badge
variant="secondary"
className="rounded-sm px-1 font-normal bg-transparent"
>
{value}
</Badge>
</Button>
);
};

export default function RequestInfo({ data }: { data: any }) {
return (
<div className="flex w-full gap-4 flex-wrap">
<InfoPill
title="Created At"
value={format(data.createdAt, "MMM do, y HH:mm:ss a")}
/>
<InfoPill title="Created By" value={data.createdByUser.email} />
<InfoPill title="Database Config" value={data.databaseConfig.name} />
<InfoPill title="Total Providers" value={data.stats.totalProviders} />
{(data.stats.errors || []).length > 0 ? (
<InfoPill
title="Errored Providers"
value={(data.stats.errors || []).length}
/>
) : null}
{data.stats.minCostProvider && (
<InfoPill
title="Min Cost"
value={`${data.stats.minCostProvider} ($${data.stats.minCost})`}
/>
)}
{data.stats.minResponseTimeProvider && (
<InfoPill
title="Min Response Time"
value={`${data.stats.minResponseTimeProvider} ($${data.stats.minResponseTime}s)`}
/>
)}
{data.stats.minCompletionTokensProvider && (
<InfoPill
title="Min Completion Tokens"
value={`${data.stats.minCompletionTokensProvider} (${data.stats.minCompletionTokens})`}
/>
)}
</div>
);
}
Loading

0 comments on commit 5d2d205

Please sign in to comment.