Skip to content

Same agent Smaller bill. The tools and infrastructure to get more work from your AI. Fewer tokens. Less compute. Lower cost.

feat: integrate apis to show on dashboard (#23)

Aman Agarwal0f42f7b978bc
diff --git a/src/client/next.config.js b/src/client/next.config.js
index 54ac4a33..3ac3cb32 100644
--- a/src/client/next.config.js
+++ b/src/client/next.config.js
@@ -8,6 +8,7 @@ const nextConfig = {
},
],
},
+ reactStrictMode: false,
};
module.exports = nextConfig;
diff --git a/src/client/src/app/(auth)/auth-form.tsx b/src/client/src/app/(auth)/auth-form.tsx
index cc1d0190..67b00d96 100644
--- a/src/client/src/app/(auth)/auth-form.tsx
+++ b/src/client/src/app/(auth)/auth-form.tsx
@@ -1,5 +1,4 @@
import asaw from "@/utils/asaw";
-import { Flex } from "@tremor/react";
import { signIn } from "next-auth/react";
import Link from "next/link";
import { useState } from "react";
@@ -65,12 +64,12 @@ export function AuthForm({ type }: { type: "login" | "register" }) {
return (
<div className="flex h-screen w-screen items-center justify-center">
- <div className="z-10 w-full max-w-md overflow-hidden rounded-2xl dark:text-gray-200 shadow-xl bg-gray-900">
+ <div className="z-10 w-full max-w-md overflow-hidden rounded-2xl shadow-xl">
<div className="flex flex-col items-center justify-center space-y-3 px-4 py-6 pt-8 text-center sm:px-16">
<h3 className="text-xl font-semibold">
{type === "login" ? "Sign In" : "Sign Up"}
</h3>
- <p className="text-sm text-gray-500">
+ <p className="text-sm">
{type === "login"
? "Use your email and password to sign in"
: "Create an account to enter"}
@@ -81,11 +80,8 @@ export function AuthForm({ type }: { type: "login" | "register" }) {
action={type === "login" ? login : register}
className="flex flex-col space-y-4 px-4 py-8 sm:px-16 text-gray-900"
>
- <Flex flexDirection="col" className="w-full" alignItems="start">
- <label
- htmlFor="email"
- className="block text-xs dark:text-gray-200 uppercase"
- >
+ <div className="flex flex-col w-full items-start">
+ <label htmlFor="email" className="block text-xs uppercase">
Email Address
</label>
<input
@@ -97,8 +93,8 @@ export function AuthForm({ type }: { type: "login" | "register" }) {
required
className="mt-1 block w-full appearance-none border border-gray-300 px-3 py-2 placeholder-gray-400 shadow-sm focus:border-black focus:outline-none focus:ring-black sm:text-sm"
/>
- </Flex>
- <Flex flexDirection="col" className="w-full" alignItems="start">
+ </div>
+ <div className="flex flex-col w-full items-start">
<label
htmlFor="password"
className="block text-xs dark:text-gray-200 uppercase"
@@ -113,19 +109,13 @@ export function AuthForm({ type }: { type: "login" | "register" }) {
required
className="mt-1 block w-full appearance-none border border-gray-300 px-3 py-2 placeholder-gray-400 shadow-sm focus:border-black focus:outline-none focus:ring-black sm:text-sm"
/>
- </Flex>
+ </div>
{type === "login" ? (
- <button
- type="submit"
- className="dark:text-gray-200 bg-gray-600 p-3"
- >
+ <button type="submit" className="p-3">
Sign in
</button>
) : (
- <button
- type="submit"
- className="dark:text-gray-200 bg-gray-600 p-3"
- >
+ <button type="submit" className="p-3">
Sign Up
</button>
)}
diff --git a/src/client/src/app/(playground)/dashboard/chart.tsx b/src/client/src/app/(playground)/dashboard/chart.tsx
deleted file mode 100644
index 35c1b2d7..00000000
--- a/src/client/src/app/(playground)/dashboard/chart.tsx
+++ /dev/null
@@ -1,41 +0,0 @@
-'use client';
-
-import { Card, AreaChart, Title, Text } from '@tremor/react';
-
-const data = [
- {
- Month: 'Jan 21',
- Sales: 2890,
- Profit: 2400
- },
- {
- Month: 'Feb 21',
- Sales: 1890,
- Profit: 1398
- },
- {
- Month: 'Jan 22',
- Sales: 3890,
- Profit: 2980
- }
-];
-
-export default function Example() {
- return (
- <Card className="mt-8">
- <Title>Performance</Title>
- <Text>Comparison between Sales and Profit</Text>
- <AreaChart
- className="mt-4 h-80"
- data={data}
- categories={['Sales', 'Profit']}
- index="Month"
- colors={['indigo', 'fuchsia']}
- valueFormatter={(number: number) =>
- `$ ${Intl.NumberFormat('us').format(number).toString()}`
- }
- yAxisWidth={60}
- />
- </Card>
- );
-}
diff --git a/src/client/src/app/(playground)/dashboard/filter.tsx b/src/client/src/app/(playground)/dashboard/filter.tsx
new file mode 100644
index 00000000..3bd2c254
--- /dev/null
+++ b/src/client/src/app/(playground)/dashboard/filter.tsx
@@ -0,0 +1,44 @@
+import { Tab, TabGroup, TabList } from "@tremor/react";
+import {
+ DEFAULT_TIME_RANGE,
+ TIME_RANGE_TYPE,
+ useFilter,
+} from "../filter-context";
+
+const TIME_RANGE_TABS: { key: string; label: string }[] = Object.keys(
+ TIME_RANGE_TYPE
+).map((k: string) => ({
+ key: k,
+ label: TIME_RANGE_TYPE[k as keyof typeof TIME_RANGE_TYPE],
+}));
+
+const DEFAULT_CHECKED_INDEX = TIME_RANGE_TABS.findIndex(
+ ({ key }) => key === DEFAULT_TIME_RANGE
+);
+
+const Filter = () => {
+ const [, updateFilter] = useFilter();
+ const handleChange = (index: number) => {
+ const selectedTab = TIME_RANGE_TABS[index].key;
+ updateFilter("timeLimit.type", selectedTab);
+ };
+
+ return (
+ <div className="flex mb-2 p-2">
+ <TabGroup
+ onIndexChange={handleChange}
+ defaultIndex={DEFAULT_CHECKED_INDEX}
+ >
+ <TabList variant="solid">
+ {TIME_RANGE_TABS.map(({ label, key }) => (
+ <Tab key={key} value={key}>
+ {label}
+ </Tab>
+ ))}
+ </TabList>
+ </TabGroup>
+ </div>
+ );
+};
+
+export default Filter;
diff --git a/src/client/src/app/(playground)/dashboard/models-categories.tsx b/src/client/src/app/(playground)/dashboard/models-categories.tsx
new file mode 100644
index 00000000..6520e79e
--- /dev/null
+++ b/src/client/src/app/(playground)/dashboard/models-categories.tsx
@@ -0,0 +1,85 @@
+import { memo, useCallback, useEffect, useState } from "react";
+import { useFilter } from "../filter-context";
+import Card from "@/components/common/card";
+import { DonutChart } from "@tremor/react";
+import { getData } from "@/utils/api";
+import Legend from "@/components/common/legend";
+
+const COLORS = ["blue-900", "blue-700", "blue-500", "blue-300", "blue-100"];
+
+type PieChartCardProps = {
+ categoryKey: string;
+ containerClass?: string;
+ heading: string;
+ indexKey: string;
+ url: string;
+};
+
+const PieChartCard = memo(
+ ({
+ categoryKey,
+ containerClass = "",
+ heading,
+ indexKey,
+ url,
+ }: PieChartCardProps) => {
+ const [filter] = useFilter();
+ const [data, setData] = useState<any[]>([]);
+
+ const fetchData = useCallback(async () => {
+ const res = await getData({
+ body: JSON.stringify({
+ timeLimit: filter.timeLimit,
+ }),
+ method: "POST",
+ url,
+ });
+
+ setData(res?.data || []);
+ }, [filter, url]);
+
+ useEffect(() => {
+ if (filter.timeLimit.start && filter.timeLimit.end) fetchData();
+ }, [filter, fetchData]);
+
+ return (
+ <Card containerClass={containerClass} heading={heading}>
+ <DonutChart
+ className="mt-6"
+ data={data}
+ category={categoryKey}
+ index={indexKey}
+ colors={COLORS.slice(0, data.length)}
+ />
+ <Legend
+ className="mt-3 flex-col"
+ categories={data.map((item: any) => item[indexKey])}
+ colors={COLORS.slice(0, data.length)}
+ />
+ </Card>
+ );
+ }
+);
+
+PieChartCard.displayName = "PieChartCard";
+
+export default function ModelsCategories() {
+ return (
+ <div className="flex w-full gap-6">
+ <PieChartCard
+ categoryKey="model_count"
+ containerClass="rounded-lg w-full"
+ heading="Top Models"
+ indexKey="model"
+ url="/api/metrics/model/top"
+ />
+ <PieChartCard
+ categoryKey="count"
+ containerClass="rounded-lg w-full"
+ heading="Generation by categories"
+ indexKey="category"
+ url="/api/metrics/category"
+ />
+ </div>
+ );
+}
diff --git a/src/client/src/app/(playground)/dashboard/number-stats.tsx b/src/client/src/app/(playground)/dashboard/number-stats.tsx
new file mode 100644
index 00000000..20841eee
--- /dev/null
+++ b/src/client/src/app/(playground)/dashboard/number-stats.tsx
@@ -0,0 +1,78 @@
+import { getData } from "@/utils/api";
+import { useFilter } from "../filter-context";
+import { memo, useCallback, useEffect, useState } from "react";
+import { round } from "lodash";
+import Card from "@/components/common/card";
+
+type StatCardProps = {
+ containerClass?: string;
+ dataKey: string;
+ heading: string;
+ url: string;
+};
+
+const StatCard = memo(
+ ({ containerClass = "", dataKey, heading, url }: StatCardProps) => {
+ const [filter] = useFilter();
+ const [data, setData] = useState<Record<any, any>>();
+
+ const fetchData = useCallback(async () => {
+ const res = await getData({
+ body: JSON.stringify({
+ timeLimit: filter.timeLimit,
+ }),
+ method: "POST",
+ url,
+ });
+
+ setData(res?.data?.[0] || {});
+ }, [filter, url]);
+
+ useEffect(() => {
+ if (filter.timeLimit.start && filter.timeLimit.end) fetchData();
+ }, [filter, fetchData]);
+
+ return (
+ <Card
+ containerClass={containerClass}
+ heading={heading}
+ text={`${round(data?.[dataKey] || 0, 2)}`}
+ />
+ );
+ }
+);
+
+StatCard.displayName = "StatCard";
+
+function NumberStats (){
+ return (
+ <div className="flex mb-4">
+ <StatCard
+ containerClass="border-r-0 rounded-l-lg w-full"
+ dataKey="total_requests"
+ heading="Total requests"
+ url="/api/metrics/request/total"
+ />
+ <StatCard
+ containerClass="border-r-0 w-full"
+ dataKey="average_duration"
+ heading="Avg Request Duration"
+ url="/api/metrics/request/duration/average"
+ />
+ <StatCard
+ containerClass="border-r-0 w-full"
+ dataKey="total_usage_cost"
+ heading="Total costs"
+ url="/api/metrics/cost/total"
+ />
+ <StatCard
+ containerClass="rounded-r-lg w-full"
+ dataKey="average_usage_cost"
+ heading="Average cost per request"
+ url="/api/metrics/cost/request/average"
+ />
+ </div>
+ );
+};
+
+export default NumberStats;
diff --git a/src/client/src/app/(playground)/dashboard/page.tsx b/src/client/src/app/(playground)/dashboard/page.tsx
index a36c8d9e..77e1ae1f 100644
--- a/src/client/src/app/(playground)/dashboard/page.tsx
+++ b/src/client/src/app/(playground)/dashboard/page.tsx
@@ -1,79 +1,20 @@
-'use client';
-
-import { Card, Metric, Text, Title, BarList, Flex, Grid } from '@tremor/react';
-import Chart from './chart';
-
-const website = [
- { name: '/home', value: 1230 },
- { name: '/contact', value: 751 },
- { name: '/gallery', value: 471 },
- { name: '/august-discount-offer', value: 280 },
- { name: '/case-studies', value: 78 }
-];
-
-const shop = [
- { name: '/home', value: 453 },
- { name: '/imprint', value: 351 },
- { name: '/shop', value: 271 },
- { name: '/pricing', value: 191 }
-];
-
-const app = [
- { name: '/shop', value: 789 },
- { name: '/product-features', value: 676 },
- { name: '/about', value: 564 },
- { name: '/login', value: 234 },
- { name: '/downloads', value: 191 }
-];
-
-const data = [
- {
- category: 'Website',
- stat: '10,234',
- data: website
- },
- {
- category: 'Online Shop',
- stat: '12,543',
- data: shop
- },
- {
- category: 'Mobile App',
- stat: '2,543',
- data: app
- }
-];
+"use client";
+import Filter from "./filter";
+import ModelsCategories from "./models-categories";
+import NumberStats from "./number-stats";
+import RequestsPerTime from "./requests-per-time";
export default function PlaygroundPage() {
- return (
- <>
- <Grid numItemsSm={2} numItemsLg={3} className="gap-6">
- {data.map((item) => (
- <Card key={item.category}>
- <Title>{item.category}</Title>
- <Flex
- justifyContent="start"
- alignItems="baseline"
- className="space-x-2"
- >
- <Metric>{item.stat}</Metric>
- <Text>Total views</Text>
- </Flex>
- <Flex className="mt-6">
- <Text>Pages</Text>
- <Text className="text-right">Views</Text>
- </Flex>
- <BarList
- data={item.data}
- valueFormatter={(number: number) =>
- Intl.NumberFormat('us').format(number).toString()
- }
- className="mt-2"
- />
- </Card>
- ))}
- </Grid>
- <Chart />
- </>
- );
+ return (
+ <div className="flex flex-col grow w-full h-full rounded overflow-hidden">
+ <Filter />
+ <div className="flex flex-col p-2 grow w-full h-full rounded overflow-y-auto">
+ <NumberStats />
+ <div className="flex flex-col gap-6">
+ <RequestsPerTime />
+ <ModelsCategories />
+ </div>
+ </div>
+ </div>
+ );
}
diff --git a/src/client/src/app/(playground)/dashboard/requests-per-time.tsx b/src/client/src/app/(playground)/dashboard/requests-per-time.tsx
new file mode 100644
index 00000000..6f4bea82
--- /dev/null
+++ b/src/client/src/app/(playground)/dashboard/requests-per-time.tsx
@@ -0,0 +1,39 @@
+import { useCallback, useEffect, useState } from "react";
+import { useFilter } from "../filter-context";
+import Card from "@/components/common/card";
+import { getData } from "@/utils/api";
+import { LineChart } from "@tremor/react";
+
+export default function RequestsPerTime () {
+ const [filter] = useFilter();
+
+ const [data, setData] = useState<Array<any>>([]);
+ const fetchData = useCallback(async () => {
+ const res = await getData({
+ body: JSON.stringify({
+ timeLimit: filter.timeLimit,
+ }),
+ method: "POST",
+ url: "/api/metrics/request/time",
+ });
+
+ setData(res?.data || []);
+ }, [filter]);
+
+ useEffect(() => {
+ if (filter.timeLimit.start && filter.timeLimit.end) fetchData();
+ }, [filter, fetchData]);
+
+ return (
+ <Card heading="Requests per time" containerClass="rounded-lg">
+ <LineChart
+ className="mt-6"
+ data={data}
+ index="request_time"
+ categories={["total"]}
+ colors={["emerald"]}
+ yAxisWidth={40}
+ />
+ </Card>
+ );
+}
diff --git a/src/client/src/app/(playground)/filter-context.tsx b/src/client/src/app/(playground)/filter-context.tsx
new file mode 100644
index 00000000..82af6488
--- /dev/null
+++ b/src/client/src/app/(playground)/filter-context.tsx
@@ -0,0 +1,88 @@
+"use client";
+
+import React, { ReactNode, createContext, useContext, useState } from "react";
+import { merge, set } from "lodash";
+import { addDays, addMonths, addWeeks } from "date-fns";
+
+export const TIME_RANGE_TYPE: Record<"24H" | "7D" | "1M" | "3M", string> = {
+ "24H": "24H",
+ "7D": "7D",
+ "1M": "1M",
+ "3M": "3M",
+};
+
+export const DEFAULT_TIME_RANGE = "7D";
+
+export interface FilterType {
+ timeLimit: {
+ start?: Date;
+ end?: Date;
+ type: keyof typeof TIME_RANGE_TYPE;
+ };
+}
+
+const FilterContext = createContext<
+ [FilterType, (key: string, value: string) => void] | undefined
+>(undefined);
+
+function getTimeLimitObject(value: string, keyPrefix: string) {
+ let object = {};
+ if (value === TIME_RANGE_TYPE["24H"]) {
+ const currentDate = new Date();
+ set(object, `${keyPrefix}start`, addDays(currentDate, -1));
+ set(object, `${keyPrefix}end`, currentDate);
+ } else if (value === TIME_RANGE_TYPE["7D"]) {
+ const currentDate = new Date();
+ set(object, `${keyPrefix}start`, addWeeks(currentDate, -1));
+ set(object, `${keyPrefix}end`, currentDate);
+ } else if (value === TIME_RANGE_TYPE["1M"]) {
+ const currentDate = new Date();
+ set(object, `${keyPrefix}start`, addMonths(currentDate, -1));
+ set(object, `${keyPrefix}end`, currentDate);
+ } else if (value === TIME_RANGE_TYPE["3M"]) {
+ console.log("valuevaluevalue");
+ const currentDate = new Date();
+ set(object, `${keyPrefix}start`, addMonths(currentDate, -3));
+ set(object, `${keyPrefix}end`, currentDate);
+ }
+ return object;
+}
+
+const INITIAL_FILTER: FilterType = {
+ timeLimit: {
+ type: DEFAULT_TIME_RANGE,
+ ...getTimeLimitObject(DEFAULT_TIME_RANGE, ""),
+ },
+};
+
+export function FilterProvider({ children }: { children: ReactNode }) {
+ const [filter, setFilter] = useState(INITIAL_FILTER);
+ const updateFilter = (key: string, value: string) => {
+ let object = {};
+ switch (key) {
+ case "timeLimit.type":
+ object = getTimeLimitObject(value, "timeLimit.");
+ set(object, key, value);
+
+ break;
+ default:
+ break;
+ }
+
+ setFilter((e) => merge({}, e, object));
+ };
+
+ return (
+ <FilterContext.Provider value={[filter, updateFilter]}>
+ {children}
+ </FilterContext.Provider>
+ );
+}
+
+export function useFilter() {
+ const context = useContext(FilterContext);
+ if (context === undefined) {
+ throw new Error("useFilter must be used within a FilterProvider");
+ }
+ return context;
+}
diff --git a/src/client/src/app/(playground)/layout.tsx b/src/client/src/app/(playground)/layout.tsx
index 5f1dc332..fc7979d0 100644
--- a/src/client/src/app/(playground)/layout.tsx
+++ b/src/client/src/app/(playground)/layout.tsx
@@ -1,4 +1,6 @@
-import PlaygroundSidebar from "@/components/common/playground-sidebar";
+import Sidebar from "@/components/(playground)/sidebar";
+import { FilterProvider } from "./filter-context";
+import Header from "@/components/(playground)/header";
export default function PlaygroundLayout({
children, // will be a page or nested layout
@@ -7,12 +9,13 @@ export default function PlaygroundLayout({
}) {
return (
<div className="h-screen w-screen overflow-hidden flex">
- <PlaygroundSidebar />
- <main className="p-2 w-full h-full">
- <div className="p-4 w-full h-full rounded dark:bg-gray-700 overflow-auto">
+ <Sidebar />
+ <FilterProvider>
+ <main className="flex flex-col p-3 w-full h-full">
+ <Header />
{children}
- </div>
- </main>
+ </main>
+ </FilterProvider>
</div>
);
}
diff --git a/src/client/src/app/(playground)/template.tsx b/src/client/src/app/(playground)/template.tsx
deleted file mode 100644
index 30173a4e..00000000
--- a/src/client/src/app/(playground)/template.tsx
+++ /dev/null
@@ -1,3 +0,0 @@
-export default function Template({ children }: { children: React.ReactNode }) {
- return <div className="template">{children}</div>
-}
\ No newline at end of file
diff --git a/src/client/src/app/api/metrics/generation/route.ts b/src/client/src/app/api/metrics/category/route.ts
similarity index 90%
rename from src/client/src/app/api/metrics/generation/route.ts
rename to src/client/src/app/api/metrics/category/route.ts
index 61abe3e7..6935e20a 100644
--- a/src/client/src/app/api/metrics/generation/route.ts
+++ b/src/client/src/app/api/metrics/category/route.ts
@@ -1,5 +1,5 @@
import { DokuParams } from "@/lib/doku/common";
-import { getResultGenerationByCategories } from "@/lib/doku/generation";
+import { getResultGenerationByCategories } from "@/lib/doku/category";
import {
validateMetricsRequest,
validateMetricsRequestType,
diff --git a/src/client/src/app/api/metrics/model/route.ts b/src/client/src/app/api/metrics/model/top/route.ts
similarity index 100%
rename from src/client/src/app/api/metrics/model/route.ts
rename to src/client/src/app/api/metrics/model/top/route.ts
diff --git a/src/client/src/app/globals.css b/src/client/src/app/globals.css
index fd81e885..b5c61c95 100644
--- a/src/client/src/app/globals.css
+++ b/src/client/src/app/globals.css
@@ -1,27 +1,3 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
-
-:root {
- --foreground-rgb: 0, 0, 0;
- --background-start-rgb: 214, 219, 220;
- --background-end-rgb: 255, 255, 255;
-}
-
-@media (prefers-color-scheme: dark) {
- :root {
- --foreground-rgb: 255, 255, 255;
- --background-start-rgb: 0, 0, 0;
- --background-end-rgb: 0, 0, 0;
- }
-}
-
-body {
- color: rgb(var(--foreground-rgb));
- background: linear-gradient(
- to bottom,
- transparent,
- rgb(var(--background-end-rgb))
- )
- rgb(var(--background-start-rgb));
-}
diff --git a/src/client/src/app/signin/page.tsx b/src/client/src/app/signin/page.tsx
deleted file mode 100644
index 9ec2b387..00000000
--- a/src/client/src/app/signin/page.tsx
+++ /dev/null
@@ -1,51 +0,0 @@
-"use client";
-
-import { Flex } from "@tremor/react";
-import { signIn } from "next-auth/react";
-
-export default function Signin() {
- return (
- <Flex alignItems="center" justifyContent="center" className="h-screen">
- <div className="flex flex-col items-center justify-center px-6 pt-8 w-1/3 pt:mt-0 dark:bg-gray-900 rounded">
- <a
- href="/"
- className="flex items-center justify-center text-2xl font-semibold dark:text-white"
- >
- <span>Doku</span>
- </a>
- <div className="w-full max-w-xl px-5 py-5 space-y-8 sm:px-5 sm:py-5 rounded-lg">
- <button
- className="inline-flex gap-4 items-center p-2 w-full justify-center border-white border-2 rounded hover:bg-white hover:text-black mb-4"
- onClick={() => signIn("google", { callbackUrl: "/dashboard" })}
- >
- <svg
- className="w-6"
- version="1.1"
- xmlns="http://www.w3.org/2000/svg"
- viewBox="0 0 48 48"
- >
- <path
- fill="#EA4335"
- d="M24 9.5c3.54 0 6.71 1.22 9.21 3.6l6.85-6.85C35.9 2.38 30.47 0 24 0 14.62 0 6.51 5.38 2.56 13.22l7.98 6.19C12.43 13.72 17.74 9.5 24 9.5z"
- ></path>
- <path
- fill="#4285F4"
- d="M46.98 24.55c0-1.57-.15-3.09-.38-4.55H24v9.02h12.94c-.58 2.96-2.26 5.48-4.78 7.18l7.73 6c4.51-4.18 7.09-10.36 7.09-17.65z"
- ></path>
- <path
- fill="#FBBC05"
- d="M10.53 28.59c-.48-1.45-.76-2.99-.76-4.59s.27-3.14.76-4.59l-7.98-6.19C.92 16.46 0 20.12 0 24c0 3.88.92 7.54 2.56 10.78l7.97-6.19z"
- ></path>
- <path
- fill="#34A853"
- d="M24 48c6.48 0 11.93-2.13 15.89-5.81l-7.73-6c-2.15 1.45-4.92 2.3-8.16 2.3-6.26 0-11.57-4.22-13.47-9.91l-7.98 6.19C6.51 42.62 14.62 48 24 48z"
- ></path>
- <path fill="none" d="M0 0h48v48H0z"></path>
- </svg>
- Continue with Google
- </button>
- </div>
- </div>
- </Flex>
- );
-}
diff --git a/src/client/src/components/(playground)/header.tsx b/src/client/src/components/(playground)/header.tsx
new file mode 100644
index 00000000..5492270a
--- /dev/null
+++ b/src/client/src/components/(playground)/header.tsx
@@ -0,0 +1,13 @@
+"use client";
+import { usePathname } from "next/navigation";
+
+export default function Header() {
+ const pathname = usePathname();
+ return (
+ <div className="relative flex shrink-0 p-2 mb-2">
+ <div className="flex flex-1 overflow-y-auto capitalize text-xl">
+ {pathname.substring(1)}
+ </div>
+ </div>
+ );
+}
diff --git a/src/client/src/components/(playground)/sidebar.tsx b/src/client/src/components/(playground)/sidebar.tsx
new file mode 100644
index 00000000..4744a496
--- /dev/null
+++ b/src/client/src/components/(playground)/sidebar.tsx
@@ -0,0 +1,90 @@
+"use client";
+
+import { signOut } from "next-auth/react";
+import { ReactElement } from "react";
+import {
+ ArrowLeftEndOnRectangleIcon,
+ HomeModernIcon,
+} from "@heroicons/react/24/solid";
+import Image from "next/image";
+import { usePathname } from "next/navigation";
+
+type SidebarItem = {
+ className?: string;
+ icon: ReactElement;
+ text: string;
+ link?: string;
+ onClick?: any;
+};
+
+const ICON_CLASSES = "flex-shrink-0 w-6 h-6 transition duration-75 transition duration-75";
+
+const SIDEBAR_ITEMS = [
+ {
+ icon: <HomeModernIcon className={ICON_CLASSES} />,
+ text: "Dashboard",
+ link: "/dashboard",
+ },
+ {
+ icon: <ArrowLeftEndOnRectangleIcon className={ICON_CLASSES} />,
+ text: "Signout",
+ onClick: signOut,
+ },
+];
+
+const SidebarItem = (props: SidebarItem) => {
+ return (
+ <a
+ href={props.link}
+ className={`flex items-center p-2 text-base cursor-pointer ${
+ props.className || ""
+ }`}
+ onClick={props.onClick}
+ >
+ {props.icon}
+ <span className="ml-5 text-nowrap">{props.text}</span>
+ </a>
+ );
+};
+
+export default function Sidebar() {
+ const pathname = usePathname();
+
+ return (
+ <aside
+ className={`flex flex-col flex-shrink-0 w-48 h-full font-normal duration-75 transition-width border-r px-1`}
+ aria-label="Sidebar"
+ >
+ <div className="relative flex flex-col flex-1 min-h-0 gap-2">
+ <div className="flex shrink-0 pt-2 relative items-center">
+ <SidebarItem
+ className="w-full"
+ link="/"
+ icon={
+ <Image
+ className="flex-shrink-0 w-6 h-6 transition duration-75"
+ src="https://avatars.githubusercontent.com/u/149867240?s=48&v=4"
+ alt="Doku's Logo"
+ priority
+ width={24}
+ height={24}
+ />
+ }
+ text="Doku"
+ />
+ </div>
+ <div className="w-full border-t margin-y-2" />
+ <ul className="flex-1 pt-2 space-y-2">
+ {SIDEBAR_ITEMS.map((item, index) => (
+ <li key={`sidebar-${index}`}>
+ <SidebarItem
+ className={item.link === pathname ? "border-r-4" : ""}
+ {...item}
+ />
+ </li>
+ ))}
+ </ul>
+ </div>
+ </aside>
+ );
+}
diff --git a/src/client/src/components/common/card.tsx b/src/client/src/components/common/card.tsx
new file mode 100644
index 00000000..675f15fe
--- /dev/null
+++ b/src/client/src/components/common/card.tsx
@@ -0,0 +1,23 @@
+import { ReactNode } from "react";
+
+type CardProps = {
+ children?: ReactNode;
+ containerClass?: string;
+ heading: string;
+ text?: string;
+};
+
+export default function Card({
+ children = null,
+ containerClass = "",
+ heading,
+ text,
+}: CardProps) {
+ return (
+ <div className={`border relative text-left p-6 ${containerClass}`}>
+ <p className="text-sm mb-4">{heading}</p>
+ {text && <p className="font-semibold text-3xl">{text}</p>}
+ {children}
+ </div>
+ );
+}
diff --git a/src/client/src/components/common/legend.tsx b/src/client/src/components/common/legend.tsx
new file mode 100644
index 00000000..aa0a7930
--- /dev/null
+++ b/src/client/src/components/common/legend.tsx
@@ -0,0 +1,41 @@
+type LegendProps = {
+ categories: string[];
+ className?: string;
+ colors?: string[];
+ itemClassName?: string;
+};
+
+const DEFAULT_COLOR = "";
+
+const Legend = ({
+ categories,
+ className = "",
+ colors = [],
+ itemClassName = "",
+}: LegendProps) => {
+ return (
+ <ol className={`relative overflow-hidden mt-3 flex-col ${className}`}>
+ {categories.map((category, index) => (
+ <li
+ key={`category-${index}`}
+ className={`flex items-center px-2 py-0.5 transition whitespace-nowrap cursor-default text-xs ${
+ colors[index] || DEFAULT_COLOR
+ } ${itemClassName}`}
+ >
+ <svg
+ className={`flex-none h-2 w-2 mr-1.5 ${
+ colors[index] || DEFAULT_COLOR
+ } opacity-100`}
+ fill="currentColor"
+ viewBox="0 0 8 8"
+ >
+ <circle cx="4" cy="4" r="4"></circle>
+ </svg>
+ <p className="whitespace-nowrap truncate opacity-100">{category}</p>
+ </li>
+ ))}
+ </ol>
+ );
+};
+
+export default Legend;
diff --git a/src/client/src/components/common/playground-sidebar.tsx b/src/client/src/components/common/playground-sidebar.tsx
deleted file mode 100644
index a24fdfcd..00000000
--- a/src/client/src/components/common/playground-sidebar.tsx
+++ /dev/null
@@ -1,97 +0,0 @@
-"use client";
-
-import { signOut } from "next-auth/react";
-import { ReactElement, useState } from "react";
-import {
- ArrowLeftEndOnRectangleIcon,
- Bars3CenterLeftIcon,
- HomeModernIcon,
-} from "@heroicons/react/24/solid";
-import Image from "next/image";
-
-type SidebarItem = {
- icon: ReactElement;
- text: string;
- link?: string;
- onClick?: any;
-};
-
-const SidebarItem = (props: SidebarItem) => {
- return (
- <a
- href={props.link}
- className="flex items-center p-2 text-base text-gray-900 rounded-lg hover:bg-gray-100 group dark:text-gray-200 dark:hover:bg-gray-700 cursor-pointer"
- onClick={props.onClick}
- >
- {props.icon}
- <span className="ml-5 text-nowrap">{props.text}</span>
- </a>
- );
-};
-
-export default function PlaygroundSidebar() {
- const [collapsed, setIsCollapsed] = useState<boolean>(false);
- const onCollapseClick = () => {
- setIsCollapsed((e) => !e);
- };
-
- return (
- <aside
- className={`flex flex-col flex-shrink-0 ${
- collapsed ? "w-16" : "w-64"
- } overflow-hidden h-full font-normal duration-75 lg:flex transition-width`}
- aria-label="Sidebar"
- >
- <div className="relative flex flex-col flex-1 min-h-0 pt-0 bg-transparent dark:border-gray-700">
- <div className="flex flex-col flex-1 pt-5 pb-4 overflow-y-auto dark:divide-gray-700">
- <div className="flex shrink-0 px-3 bg-transparent pb-4">
- <SidebarItem
- link="/"
- icon={
- <Image
- className="flex-shrink-0 w-6 h-6 text-gray-500 transition duration-75 group-hover:text-gray-900 dark:text-gray-400 dark:group-hover:text-white"
- src="https://avatars.githubusercontent.com/u/149867240?s=48&v=4"
- alt="Doku's Logo"
- priority
- width={24}
- height={24}
- />
- }
- text="Doku"
- />
- </div>
- <div className="flex-1 px-3 space-y-1 bg-transparent">
- <ul className="pb-2 pt-2 space-y-2">
- <li>
- <SidebarItem
- icon={
- <HomeModernIcon className="flex-shrink-0 w-6 h-6 text-gray-500 transition duration-75 group-hover:text-gray-900 dark:text-gray-400 dark:group-hover:text-white" />
- }
- text="Dashboard"
- link="/dashboard"
- />
- </li>
- </ul>
- <div className="pt-2 space-y-2">
- <SidebarItem
- icon={
- <ArrowLeftEndOnRectangleIcon className="flex-shrink-0 w-6 h-6 text-gray-500 transition duration-75 group-hover:text-gray-900 dark:text-gray-400 dark:group-hover:text-white" />
- }
- text="Signout"
- onClick={signOut}
- />
- </div>
- </div>
- </div>
- <div className="justify-center w-full p-4 space-x-4 lg:flex bg-transparent">
- <a
- onClick={onCollapseClick}
- className="inline-flex justify-center p-2 text-gray-500 rounded cursor-pointer hover:text-gray-900 hover:bg-gray-100 dark:hover:bg-gray-700 dark:hover:text-white"
- >
- <Bars3CenterLeftIcon className="w-6 h-6" />
- </a>
- </div>
- </div>
- </aside>
- );
-}
diff --git a/src/client/src/lib/doku/generation.ts b/src/client/src/lib/doku/category.ts
similarity index 100%
rename from src/client/src/lib/doku/generation.ts
rename to src/client/src/lib/doku/category.ts
diff --git a/src/client/src/lib/doku/cost.ts b/src/client/src/lib/doku/cost.ts
index cec71459..83d971dc 100644
--- a/src/client/src/lib/doku/cost.ts
+++ b/src/client/src/lib/doku/cost.ts
@@ -4,7 +4,7 @@ export async function getTotalCost(params: DokuParams) {
const { start, end } = params.timeLimit;
const query = `SELECT
- CAST(SUM(usagecost) AS DECIMAL) AS average_usage_cost
+ CAST(SUM(usagecost) AS DECIMAL) AS total_usage_cost
FROM ${TABLE_NAME}
WHERE time >= '${start}' AND time <= '${end}'`;
diff --git a/src/client/src/lib/doku/model.ts b/src/client/src/lib/doku/model.ts
index b455265c..11190fcc 100644
--- a/src/client/src/lib/doku/model.ts
+++ b/src/client/src/lib/doku/model.ts
@@ -8,7 +8,7 @@ export async function getTopModels(params: ModelDokuParams) {
const { start, end } = params.timeLimit;
const query = `
- SELECT model, CAST(COUNT(model) AS DECIMAL) AS model_count
+ SELECT model, CAST(COUNT(model) AS INTEGER) AS model_count
FROM ${TABLE_NAME}
WHERE time >= '${start}' AND time <= '${end}'
GROUP BY model
diff --git a/src/client/src/utils/api.ts b/src/client/src/utils/api.ts
new file mode 100644
index 00000000..ba5c0f13
--- /dev/null
+++ b/src/client/src/utils/api.ts
@@ -0,0 +1,15 @@
+type GET_DATA = {
+ body: string;
+ method?: "GET" | "POST";
+ url: string;
+};
+
+export async function getData({ body, method = "POST", url }: GET_DATA) {
+ const res = await fetch(url, { body, method });
+ if (!res.ok) {
+ // This will activate the closest `error.js` Error Boundary
+ throw new Error("Failed to fetch data");
+ }
+
+ return res.json();
+}
diff --git a/src/client/src/utils/doku.ts b/src/client/src/utils/doku.ts
index 9a419c6b..4fbfe7d7 100644
--- a/src/client/src/utils/doku.ts
+++ b/src/client/src/utils/doku.ts
@@ -10,7 +10,7 @@ export const validateMetricsRequestType = {
AVERAGE_REQUEST_COST: "AVERAGE_REQUEST_COST",
// Model
TOP_MODELS: "TOP_MODELS",
- // Generation
+ // Category
GENERATION_BY_CATEGORY: "GENERATION_BY_CATEGORY",
};
@@ -19,6 +19,7 @@ export const validateMetricsRequest = (
type: ValueOf<typeof validateMetricsRequestType>
): { success: boolean; err?: string } => {
switch (type) {
+ // Request
case validateMetricsRequestType.REQUEST_PER_TIME:
case validateMetricsRequestType.TOTAL_REQUESTS:
case validateMetricsRequestType.AVERAGE_REQUEST_DURATION:
@@ -29,6 +30,7 @@ export const validateMetricsRequest = (
};
}
break;
+ // Cost
case validateMetricsRequestType.TOTAL_COST:
case validateMetricsRequestType.AVERAGE_REQUEST_COST:
if (!params.timeLimit?.start || !params.timeLimit?.end) {
@@ -38,6 +40,7 @@ export const validateMetricsRequest = (
};
}
break;
+ // Model
case validateMetricsRequestType.TOP_MODELS:
if (!params.timeLimit?.start || !params.timeLimit?.end) {
return {
@@ -52,6 +55,7 @@ export const validateMetricsRequest = (
};
}
break;
+ // Category
case validateMetricsRequestType.GENERATION_BY_CATEGORY:
if (!params.timeLimit?.start || !params.timeLimit?.end) {
return {
diff --git a/src/client/tailwind.config.ts b/src/client/tailwind.config.ts
index b185db15..815bbc35 100644
--- a/src/client/tailwind.config.ts
+++ b/src/client/tailwind.config.ts
@@ -7,91 +7,102 @@ export default {
"./node_modules/@tremor/**/*.{js,ts,jsx,tsx,mdx}",
"./src/**/*.{js,ts,jsx,tsx,mdx}",
],
+ darkMode: "class",
theme: {
- transparent: 'transparent',
- current: 'currentColor',
- extend: {
- colors: {
- // light mode
- tremor: {
- brand: {
- faint: '#eff6ff', // blue-50
- muted: '#bfdbfe', // blue-200
- subtle: '#60a5fa', // blue-400
- DEFAULT: '#3b82f6', // blue-500
- emphasis: '#1d4ed8', // blue-700
- inverted: '#ffffff' // white
- },
- background: {
- muted: '#f9fafb', // gray-50
- subtle: '#f3f4f6', // gray-100
- DEFAULT: '#ffffff', // white
- emphasis: '#374151' // gray-700
- },
- border: {
- DEFAULT: '#e5e7eb' // gray-200
- },
- ring: {
- DEFAULT: '#e5e7eb' // gray-200
- },
- content: {
- subtle: '#9ca3af', // gray-400
- DEFAULT: '#6b7280', // gray-500
- emphasis: '#374151', // gray-700
- strong: '#111827', // gray-900
- inverted: '#ffffff' // white
- }
- }
- },
- boxShadow: {
- // light
- 'tremor-input': '0 1px 2px 0 rgb(0 0 0 / 0.05)',
- 'tremor-card':
- '0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1)',
- 'tremor-dropdown':
- '0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1)'
- },
- borderRadius: {
- 'tremor-small': '0.375rem',
- 'tremor-default': '0.5rem',
- 'tremor-full': '9999px'
- },
- fontSize: {
- 'tremor-label': '0.75rem',
- 'tremor-default': ['0.875rem', { lineHeight: '1.25rem' }],
- 'tremor-title': ['1.125rem', { lineHeight: '1.75rem' }],
- 'tremor-metric': ['1.875rem', { lineHeight: '2.25rem' }]
- }
- }
+ transparent: "transparent",
+ current: "currentColor",
+ extend: {
+ colors: {
+ darkMode: {
+ primary: "#0C120C",
+ secondary: "#DE541E",
+ tertiary: "#C0C5C1",
+ blue: "#003F91",
+ },
+ primary: "#0C120C",
+ secondary: "#DE541E",
+ tertiary: "#C0C5C1",
+ blue: "#003F91",
+ // light mode
+ tremor: {
+ brand: {
+ faint: "#eff6ff", // blue-50
+ muted: "#bfdbfe", // blue-200
+ subtle: "#60a5fa", // blue-400
+ DEFAULT: "#3b82f6", // blue-500
+ emphasis: "#1d4ed8", // blue-700
+ inverted: "#ffffff", // white
+ },
+ background: {
+ muted: "#f9fafb", // gray-50
+ subtle: "#f3f4f6", // gray-100
+ DEFAULT: "#ffffff", // white
+ emphasis: "#374151", // gray-700
+ },
+ border: {
+ DEFAULT: "#e5e7eb", // gray-200
+ },
+ ring: {
+ DEFAULT: "#e5e7eb", // gray-200
+ },
+ content: {
+ subtle: "#9ca3af", // gray-400
+ DEFAULT: "#6b7280", // gray-500
+ emphasis: "#374151", // gray-700
+ strong: "#111827", // gray-900
+ inverted: "#ffffff", // white
+ },
+ },
+ },
+ boxShadow: {
+ // light
+ "tremor-input": "0 1px 2px 0 rgb(0 0 0 / 0.05)",
+ "tremor-card":
+ "0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1)",
+ "tremor-dropdown":
+ "0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1)",
+ },
+ borderRadius: {
+ "tremor-small": "0.375rem",
+ "tremor-default": "0.5rem",
+ "tremor-full": "9999px",
+ },
+ fontSize: {
+ "tremor-label": "0.75rem",
+ "tremor-default": ["0.875rem", { lineHeight: "1.25rem" }],
+ "tremor-title": ["1.125rem", { lineHeight: "1.75rem" }],
+ "tremor-metric": ["1.875rem", { lineHeight: "2.25rem" }],
+ },
+ },
},
safelist: [
- {
- pattern:
- /^(bg-(?:slate|gray|zinc|neutral|stone|red|orange|amber|yellow|lime|green|emerald|teal|cyan|sky|blue|indigo|violet|purple|fuchsia|pink|rose)-(?:50|100|200|300|400|500|600|700|800|900|950))$/,
- variants: ['hover', 'ui-selected']
- },
- {
- pattern:
- /^(text-(?:slate|gray|zinc|neutral|stone|red|orange|amber|yellow|lime|green|emerald|teal|cyan|sky|blue|indigo|violet|purple|fuchsia|pink|rose)-(?:50|100|200|300|400|500|600|700|800|900|950))$/,
- variants: ['hover', 'ui-selected']
- },
- {
- pattern:
- /^(border-(?:slate|gray|zinc|neutral|stone|red|orange|amber|yellow|lime|green|emerald|teal|cyan|sky|blue|indigo|violet|purple|fuchsia|pink|rose)-(?:50|100|200|300|400|500|600|700|800|900|950))$/,
- variants: ['hover', 'ui-selected']
- },
- {
- pattern:
- /^(ring-(?:slate|gray|zinc|neutral|stone|red|orange|amber|yellow|lime|green|emerald|teal|cyan|sky|blue|indigo|violet|purple|fuchsia|pink|rose)-(?:50|100|200|300|400|500|600|700|800|900|950))$/
- },
- {
- pattern:
- /^(stroke-(?:slate|gray|zinc|neutral|stone|red|orange|amber|yellow|lime|green|emerald|teal|cyan|sky|blue|indigo|violet|purple|fuchsia|pink|rose)-(?:50|100|200|300|400|500|600|700|800|900|950))$/
- },
- {
- pattern:
- /^(fill-(?:slate|gray|zinc|neutral|stone|red|orange|amber|yellow|lime|green|emerald|teal|cyan|sky|blue|indigo|violet|purple|fuchsia|pink|rose)-(?:50|100|200|300|400|500|600|700|800|900|950))$/
- }
+ {
+ pattern:
+ /^(bg-(?:slate|gray|zinc|neutral|stone|red|orange|amber|yellow|lime|green|emerald|teal|cyan|sky|blue|indigo|violet|purple|fuchsia|pink|rose)-(?:50|100|200|300|400|500|600|700|800|900|950))$/,
+ variants: ["hover", "ui-selected"],
+ },
+ {
+ pattern:
+ /^(text-(?:slate|gray|zinc|neutral|stone|red|orange|amber|yellow|lime|green|emerald|teal|cyan|sky|blue|indigo|violet|purple|fuchsia|pink|rose)-(?:50|100|200|300|400|500|600|700|800|900|950))$/,
+ variants: ["hover", "ui-selected"],
+ },
+ {
+ pattern:
+ /^(border-(?:slate|gray|zinc|neutral|stone|red|orange|amber|yellow|lime|green|emerald|teal|cyan|sky|blue|indigo|violet|purple|fuchsia|pink|rose)-(?:50|100|200|300|400|500|600|700|800|900|950))$/,
+ variants: ["hover", "ui-selected"],
+ },
+ {
+ pattern:
+ /^(ring-(?:slate|gray|zinc|neutral|stone|red|orange|amber|yellow|lime|green|emerald|teal|cyan|sky|blue|indigo|violet|purple|fuchsia|pink|rose)-(?:50|100|200|300|400|500|600|700|800|900|950))$/,
+ },
+ {
+ pattern:
+ /^(stroke-(?:slate|gray|zinc|neutral|stone|red|orange|amber|yellow|lime|green|emerald|teal|cyan|sky|blue|indigo|violet|purple|fuchsia|pink|rose)-(?:50|100|200|300|400|500|600|700|800|900|950))$/,
+ },
+ {
+ pattern:
+ /^(fill-(?:slate|gray|zinc|neutral|stone|red|orange|amber|yellow|lime|green|emerald|teal|cyan|sky|blue|indigo|violet|purple|fuchsia|pink|rose)-(?:50|100|200|300|400|500|600|700|800|900|950))$/,
+ },
],
plugins: [require("@headlessui/tailwindcss")],
} satisfies Config;