From b1781058a587ea8f74a047308cbe67b6cc5117de Mon Sep 17 00:00:00 2001 From: Karthik Kalyanaraman Date: Thu, 4 Apr 2024 00:01:40 -0700 Subject: [PATCH 1/3] Pagination bug --- components/project/eval/eval.tsx | 4 ++-- components/project/eval/prompts.tsx | 4 ++-- lib/services/trace_service.ts | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/components/project/eval/eval.tsx b/components/project/eval/eval.tsx index 8441bfdc..7b139ddd 100644 --- a/components/project/eval/eval.tsx +++ b/components/project/eval/eval.tsx @@ -62,9 +62,9 @@ export default function Eval({ email }: { email: string }) { } if (result) { if (data) { - setData((prevData: any) => [...prevData, ...result.prompts.result]); + setData((prevData: any) => [...prevData, ...result?.prompts?.result || []]); } else { - setData(result.prompts.result); + setData(result?.prompts?.result || []); } } setPage((currentPage) => currentPage + 1); diff --git a/components/project/eval/prompts.tsx b/components/project/eval/prompts.tsx index bb385183..9ea37d51 100644 --- a/components/project/eval/prompts.tsx +++ b/components/project/eval/prompts.tsx @@ -52,9 +52,9 @@ export default function Prompts({ email }: { email: string }) { } if (result) { if (data) { - setData((prevData: any) => [...prevData, ...result.prompts.result]); + setData((prevData: any) => [...prevData, ...result?.prompts?.result || []]); } else { - setData(result.prompts.result); + setData(result?.prompts?.result || []); } } setPage((currentPage) => currentPage + 1); diff --git a/lib/services/trace_service.ts b/lib/services/trace_service.ts index 1761aa06..ad7c35c7 100644 --- a/lib/services/trace_service.ts +++ b/lib/services/trace_service.ts @@ -244,7 +244,7 @@ export class TraceService implements ITraceService { const md = { page, page_size: pageSize, total_pages: totalPages }; if (page! > totalPages) { - throw Error("Page number is greater than total pages"); + page = totalPages; } const query = sql.select( `* FROM ${project_id} WHERE attributes LIKE '%${attribute}%' ORDER BY 'start_time' DESC LIMIT ${pageSize} OFFSET ${ @@ -325,7 +325,7 @@ export class TraceService implements ITraceService { const md = { page, page_size: pageSize, total_pages: totalPages }; if (page! > totalPages) { - throw Error("Page number is greater than total pages"); + page = totalPages; } const query = sql.select( `* FROM ${project_id} ORDER BY 'createdAt' DESC LIMIT ${pageSize} OFFSET ${ From 0e963e226af17ffdba6282496d1979c6e30c20ad Mon Sep 17 00:00:00 2001 From: Karthik Kalyanaraman Date: Thu, 4 Apr 2024 17:13:49 -0700 Subject: [PATCH 2/3] Bug fix --- app/api/user/route.ts | 1 - components/project/traces.tsx | 2 -- lib/utils.ts | 1 + 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/app/api/user/route.ts b/app/api/user/route.ts index d7e95f34..a10d34bf 100644 --- a/app/api/user/route.ts +++ b/app/api/user/route.ts @@ -83,7 +83,6 @@ export async function PUT(req: NextRequest) { } if ("status" in data) { - console.log("updating status"); const user = await prisma.user.update({ where: { id, diff --git a/components/project/traces.tsx b/components/project/traces.tsx index 523aa352..1f56c03e 100644 --- a/components/project/traces.tsx +++ b/components/project/traces.tsx @@ -80,8 +80,6 @@ export default function Traces({ email }: { email: string }) { } // Merge the new data with the existing data - console.log("currentData", currentData); - console.log("newData", newData); if (currentData.length > 0) { const updatedData = [...currentData, ...newData]; diff --git a/lib/utils.ts b/lib/utils.ts index 584d22f2..2c6fd519 100644 --- a/lib/utils.ts +++ b/lib/utils.ts @@ -326,6 +326,7 @@ export function calculatePriceFromUsage( output_tokens: number; } ): any { + if (!model) return { total: 0, input: 0, output: 0 }; if (vendor === "openai") { const costTable = OPENAI_PRICING[model.includes("gpt-4") ? "gpt-4" : model]; if (costTable) { From dbc3c4a9d3d5a05d597974424639291a74a87ede Mon Sep 17 00:00:00 2001 From: Karthik Kalyanaraman Date: Wed, 22 May 2024 13:30:10 -0700 Subject: [PATCH 3/3] Support image inputs --- components/project/traces/logs-view.tsx | 10 +++++++--- lib/utils.ts | 20 ++++++++++++++++++++ package-lock.json | 12 ++++++++++++ package.json | 1 + 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/components/project/traces/logs-view.tsx b/components/project/traces/logs-view.tsx index a942d2b2..f6cad5f4 100644 --- a/components/project/traces/logs-view.tsx +++ b/components/project/traces/logs-view.tsx @@ -5,6 +5,8 @@ import { correctTimestampFormat } from "@/lib/trace_utils"; import { cn, formatDateTime, parseNestedJsonFields } from "@/lib/utils"; import { ChevronDown, ChevronRight } from "lucide-react"; import { useState } from "react"; +import { JsonView, allExpanded, defaultStyles } from "react-json-view-lite"; +import "react-json-view-lite/dist/index.css"; import { serviceTypeColor, vendorBadgeColor, @@ -88,9 +90,11 @@ export const LogsView = ({ )} {!collapsed && ( -
-          {parseNestedJsonFields(span.attributes)}
-        
+ )} diff --git a/lib/utils.ts b/lib/utils.ts index effd61e2..205aabb8 100644 --- a/lib/utils.ts +++ b/lib/utils.ts @@ -444,6 +444,26 @@ export function safeStringify(value: any): string { if (typeof value === "string") { return value; } + + // if its a list, check type and stringify + if (Array.isArray(value)) { + const stringifiedList = value.map((item) => { + if (item?.type === "text") { + return item?.text; + } else if (item?.type === "function") { + return prettyPrintJson.toHtml(item); + } else if (item?.type === "image_url") { + if (typeof item?.image_url === "string") { + return ``; + } else if (typeof item?.image_url === "object") { + return ``; + } + } + return item; + }); + return stringifiedList.join(""); + } + // If it's not a string, stringify it return prettyPrintJson.toHtml(value); } diff --git a/package-lock.json b/package-lock.json index 002227e2..e4db1fb8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -81,6 +81,7 @@ "react-diff-view": "^3.2.1", "react-dom": "^18", "react-hook-form": "^7.49.3", + "react-json-view-lite": "^1.4.0", "react-markdown": "^9.0.1", "react-query": "^3.39.3", "react-syntax-highlighter": "^15.5.0", @@ -12365,6 +12366,17 @@ "version": "16.13.1", "license": "MIT" }, + "node_modules/react-json-view-lite": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/react-json-view-lite/-/react-json-view-lite-1.4.0.tgz", + "integrity": "sha512-wh6F6uJyYAmQ4fK0e8dSQMEWuvTs2Wr3el3sLD9bambX1+pSWUVXIz1RFaoy3TI1mZ0FqdpKq9YgbgTTgyrmXA==", + "engines": { + "node": ">=14" + }, + "peerDependencies": { + "react": "^16.13.1 || ^17.0.0 || ^18.0.0" + } + }, "node_modules/react-markdown": { "version": "9.0.1", "license": "MIT", diff --git a/package.json b/package.json index e71c4bc5..687b2dd1 100644 --- a/package.json +++ b/package.json @@ -89,6 +89,7 @@ "react-diff-view": "^3.2.1", "react-dom": "^18", "react-hook-form": "^7.49.3", + "react-json-view-lite": "^1.4.0", "react-markdown": "^9.0.1", "react-query": "^3.39.3", "react-syntax-highlighter": "^15.5.0",