forked from openlit/openlit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feat]: adding playground to compare your evaluations from different …
…providers (openlit#266) Co-authored-by: patcher9 <[email protected]>
- Loading branch information
1 parent
aa27a46
commit 5d2d205
Showing
48 changed files
with
5,925 additions
and
941 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
12 changes: 12 additions & 0 deletions
12
src/client/prisma/migrations/20240607203423_create_open_ground/migration.sql
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,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 | ||
); |
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
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.
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.
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.
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.
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,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
64
src/client/src/app/(playground)/openground/[id]/request-info.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 |
---|---|---|
@@ -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> | ||
); | ||
} |
Oops, something went wrong.