Skip to content

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

fix: token per time chart fixed, added posthog events (#517)

Aman Agarwal05210ffb8cbd
diff --git a/docs/.DS_Store b/docs/.DS_Store
index c31a2e81..ba3944d1 100644
Binary files a/docs/.DS_Store and b/docs/.DS_Store differ
diff --git a/sdk/typescript/package-lock.json b/sdk/typescript/package-lock.json
index 2229ca7c..dd000f77 100644
--- a/sdk/typescript/package-lock.json
+++ b/sdk/typescript/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "openlit",
- "version": "1.3.0",
+ "version": "1.3.1",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "openlit",
- "version": "1.3.0",
+ "version": "1.3.1",
"license": "ISC",
"dependencies": {
"@anthropic-ai/sdk": "^0.25.0",
diff --git a/src/client/Dockerfile b/src/client/Dockerfile
index 7b580a53..ce38baa0 100644
--- a/src/client/Dockerfile
+++ b/src/client/Dockerfile
@@ -17,7 +17,7 @@ RUN npm install && npm run build
# Use a smaller image for production
FROM alpine
-RUN apk add --update nodejs npm curl grep sed
+RUN apk add --update nodejs npm
# Set the working directory in the container
WORKDIR /app/client
diff --git a/src/client/package-lock.json b/src/client/package-lock.json
index 9f42733a..29fde835 100644
--- a/src/client/package-lock.json
+++ b/src/client/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "openlit",
- "version": "1.11.2",
+ "version": "1.11.3",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "openlit",
- "version": "1.11.2",
+ "version": "1.11.3",
"dependencies": {
"@anthropic-ai/sdk": "^0.21.1",
"@clickhouse/client": "^1.1.0",
diff --git a/src/client/package.json b/src/client/package.json
index a69f006e..d5ba6f87 100644
--- a/src/client/package.json
+++ b/src/client/package.json
@@ -1,6 +1,6 @@
{
"name": "openlit",
- "version": "1.11.2",
+ "version": "1.11.3",
"private": true,
"scripts": {
"dev": "next dev",
diff --git a/src/client/scripts/entrypoint.sh b/src/client/scripts/entrypoint.sh
index 85494b06..312efc41 100755
--- a/src/client/scripts/entrypoint.sh
+++ b/src/client/scripts/entrypoint.sh
@@ -23,6 +23,9 @@ echo "INIT_DB_HOST=${INIT_DB_HOST}" >> /etc/environment
echo "INIT_DB_PORT=${INIT_DB_PORT}" >> /etc/environment
echo "INIT_DB_DATABASE=${INIT_DB_DATABASE}" >> /etc/environment
+# Load the environment variables
+source /etc/environment
+
# Run Prisma migrations and generate prisma client
npm install -g prisma
prisma migrate deploy
diff --git a/src/client/src/app/(playground)/dashboard/llm/token-charts.tsx b/src/client/src/app/(playground)/dashboard/llm/token-charts.tsx
index 63cd1efe..52b3c021 100644
--- a/src/client/src/app/(playground)/dashboard/llm/token-charts.tsx
+++ b/src/client/src/app/(playground)/dashboard/llm/token-charts.tsx
@@ -233,6 +233,11 @@ function TokensPerTime() {
const updatedDataWithType = ((data || []) as any[]) || [];
+ const COLORS = {
+ promptokens: "hsl(12 76% 61%)",
+ completiontokens: "hsl(243 51.9 68.2%)",
+ };
+
return (
<Card className="w-full flex flex-col col-span-3">
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
@@ -270,26 +275,53 @@ function TokensPerTime() {
domain={[0, "dataMax + 15"]}
/>
<Tooltip labelClassName="dark:text-stone-700" />
+ <defs>
+ <linearGradient
+ id="completionTokens"
+ x1="0"
+ y1="0"
+ x2="0"
+ y2="1"
+ >
+ <stop
+ offset="5%"
+ stopColor={COLORS.completiontokens}
+ stopOpacity={0.8}
+ />
+ <stop
+ offset="95%"
+ stopColor={COLORS.completiontokens}
+ stopOpacity={0.1}
+ />
+ </linearGradient>
+ <linearGradient id="promptTokens" x1="0" y1="0" x2="0" y2="1">
+ <stop
+ offset="5%"
+ stopColor={COLORS.promptokens}
+ stopOpacity={0.8}
+ />
+ <stop
+ offset="95%"
+ stopColor={COLORS.promptokens}
+ stopOpacity={0.1}
+ />
+ </linearGradient>
+ </defs>
<Area
- type="monotone"
- dataKey="totaltokens"
- stackId="1"
- stroke="#8884d8"
- fill="#8884d8"
+ type="natural"
+ dataKey="completiontokens"
+ stackId="0"
+ stroke={COLORS.completiontokens}
+ fill="url(#completionTokens)"
+ fillOpacity={0.4}
/>
<Area
- type="monotone"
+ type="natural"
dataKey="prompttokens"
- stackId="1"
- stroke="#82ca9d"
- fill="#82ca9d"
- />
- <Area
- type="monotone"
- dataKey="completiontokens"
- stackId="1"
- stroke="#ffc658"
- fill="#ffc658"
+ stackId="0"
+ stroke={COLORS.promptokens}
+ fill="url(#promptTokens)"
+ fillOpacity={0.4}
/>
</AreaChart>
</ResponsiveContainer>
diff --git a/src/client/src/components/(playground)/filter/index.tsx b/src/client/src/components/(playground)/filter/index.tsx
index aceff568..d9af69f8 100644
--- a/src/client/src/components/(playground)/filter/index.tsx
+++ b/src/client/src/components/(playground)/filter/index.tsx
@@ -3,6 +3,8 @@ import { getFilterDetails, getUpdateFilter } from "@/selectors/filter";
import { useRootStore } from "@/store";
import { DatePickerWithRange } from "@/components/ui/date-range-picker";
import { TIME_RANGE_TYPE } from "@/store/filter";
+import { usePostHog } from "posthog-js/react";
+import { CLIENT_EVENTS } from "@/constants/events";
const TIME_RANGE_TABS: { key: string; label: string }[] = Object.keys(
TIME_RANGE_TYPE
@@ -12,15 +14,22 @@ const TIME_RANGE_TABS: { key: string; label: string }[] = Object.keys(
}));
const Filter = ({ className = "" }: { className?: string }) => {
+ const posthog = usePostHog();
const filter = useRootStore(getFilterDetails);
const updateFilter = useRootStore(getUpdateFilter);
const handleChange = (key: string) => {
updateFilter("timeLimit.type", key);
+ posthog?.capture(CLIENT_EVENTS.TIME_FILTER_CHANGE, {
+ range: key,
+ });
};
const onCustomDateChange = (start: Date, end: Date) => {
updateFilter("timeLimit.type", TIME_RANGE_TYPE.CUSTOM, { start, end });
+ posthog?.capture(CLIENT_EVENTS.TIME_FILTER_CHANGE, {
+ range: TIME_RANGE_TYPE.CUSTOM,
+ });
};
return (
diff --git a/src/client/src/components/(playground)/filter/refresh-rate.tsx b/src/client/src/components/(playground)/filter/refresh-rate.tsx
index ebc9e747..5699a815 100644
--- a/src/client/src/components/(playground)/filter/refresh-rate.tsx
+++ b/src/client/src/components/(playground)/filter/refresh-rate.tsx
@@ -16,6 +16,8 @@ import {
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
+import { usePostHog } from "posthog-js/react";
+import { CLIENT_EVENTS } from "@/constants/events";
const REFRESH_RATE_EVENT = "refresh-rate";
@@ -42,6 +44,7 @@ const REFRESH_RATE_TABS: { key: string; label: string }[] = Object.keys(
}));
const RefreshRate = () => {
+ const posthog = usePostHog();
const filter = useRootStore(getFilterDetails);
const updateFilter = useRootStore(getUpdateFilter);
const refreshRateTimer = useRef<NodeJS.Timeout>();
@@ -49,6 +52,9 @@ const RefreshRate = () => {
const handleChange = (key: string) => {
updateFilter("refreshRate", key);
+ posthog?.capture(CLIENT_EVENTS.REFRESH_RATE_CHANGE, {
+ rate: key,
+ });
};
const intervalCallback = useCallback(() => {
diff --git a/src/client/src/components/(playground)/request/request-filter.tsx b/src/client/src/components/(playground)/request/request-filter.tsx
index 1b1ff905..0fb87470 100644
--- a/src/client/src/components/(playground)/request/request-filter.tsx
+++ b/src/client/src/components/(playground)/request/request-filter.tsx
@@ -19,6 +19,8 @@ import useFetchWrapper from "@/utils/hooks/useFetchWrapper";
import { useCallback, useEffect, useState } from "react";
import { toast } from "sonner";
import { FilterConfig, FilterType } from "@/store/filter";
+import { usePostHog } from "posthog-js/react";
+import { CLIENT_EVENTS } from "@/constants/events";
const DynamicFilters = ({
isVisibleFilters,
@@ -29,6 +31,7 @@ const DynamicFilters = ({
filter: FilterType;
areFiltersApplied: boolean;
}) => {
+ const posthog = usePostHog();
const filterConfig = useRootStore(getFilterConfig);
const pingStatus = useRootStore(getPingStatus);
const filterDetails = useRootStore(getFilterDetails);
@@ -103,11 +106,13 @@ const DynamicFilters = ({
const updateFilterStore = () => {
updateFilter("selectedConfig", selectedFilterValues);
+ posthog?.capture(CLIENT_EVENTS.TRACE_FILTER_APPLIED);
};
const clearFilterStore = () => {
setSelectedFilterValues({});
updateFilter("selectedConfig", {});
+ posthog?.capture(CLIENT_EVENTS.TRACE_FILTER_CLEARED);
};
return (
diff --git a/src/client/src/constants/events.ts b/src/client/src/constants/events.ts
index be4660ed..9c3e824a 100644
--- a/src/client/src/constants/events.ts
+++ b/src/client/src/constants/events.ts
@@ -30,6 +30,11 @@ export const CLIENT_EVENTS = {
// Openground
OPENGROUND_EVALUATION_SUCCESS: "OPENGROUND_EVALUATION_SUCCESS",
OPENGROUND_EVALUATION_FAILURE: "OPENGROUND_EVALUATION_FAILURE",
+ // Custom
+ REFRESH_RATE_CHANGE: "REFRESH_RATE_CHANGE",
+ TIME_FILTER_CHANGE: "TIME_FILTER_CHANGE",
+ TRACE_FILTER_APPLIED: "TRACE_FILTER_APPLIED",
+ TRACE_FILTER_CLEARED: "TRACE_FILTER_CLEARED",
};
export const SERVER_EVENTS = {