From e92356c4e0390fd06e3ed07d54d7bb52dde28584 Mon Sep 17 00:00:00 2001 From: "use-tusk[bot]" <144006087+use-tusk[bot]@users.noreply.github.com> Date: Wed, 16 Oct 2024 19:20:01 +0000 Subject: [PATCH 01/11] fix(requests): ensure accurate model display in table view --- .../templates/requestsV2/builder/requestBuilder.tsx | 12 ++++++++++-- web/services/hooks/requests.tsx | 6 +++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/web/components/templates/requestsV2/builder/requestBuilder.tsx b/web/components/templates/requestsV2/builder/requestBuilder.tsx index f8a9068c54..76cfd5c7b5 100644 --- a/web/components/templates/requestsV2/builder/requestBuilder.tsx +++ b/web/components/templates/requestsV2/builder/requestBuilder.tsx @@ -194,9 +194,17 @@ const isAssistantRequest = (request: HeliconeRequest) => { const getNormalizedRequest = (request: HeliconeRequest): NormalizedRequest => { try { - return getRequestBuilder(request).build(); + const normalizedRequest = getRequestBuilder(request).build(); + if (!normalizedRequest.model || normalizedRequest.model === "") { + normalizedRequest.model = "Unsupported"; + } + return normalizedRequest; } catch (error) { - return getRequestBuilder(request).build(); + const normalizedRequest = getRequestBuilder(request).build(); + if (!normalizedRequest.model || normalizedRequest.model === "") { + normalizedRequest.model = "Unsupported"; + } + return normalizedRequest; } }; diff --git a/web/services/hooks/requests.tsx b/web/services/hooks/requests.tsx index 024cdf9ea2..06edc61261 100644 --- a/web/services/hooks/requests.tsx +++ b/web/services/hooks/requests.tsx @@ -123,9 +123,9 @@ const useGetRequestsWithBodies = ( request.model_override || request.response_model || request.request_model || - content.response?.model || - content.request?.model || - content.response?.body?.model || + content?.response?.model || + content?.request?.model || + content?.response?.body?.model || getModelFromPath(request.target_url) || ""; From e3adcbae9241cf3b688fbcfa3bf7e09f7ecd9730 Mon Sep 17 00:00:00 2001 From: "use-tusk[bot]" <144006087+use-tusk[bot]@users.noreply.github.com> Date: Wed, 16 Oct 2024 19:33:20 +0000 Subject: [PATCH 02/11] fix: address review from colegottdank --- .../templates/requestsV2/RequestsTable.tsx | 185 ++++++++++++++++++ .../requestsV2/builder/requestBuilder.tsx | 38 ++-- web/services/hooks/requests.tsx | 13 +- 3 files changed, 213 insertions(+), 23 deletions(-) create mode 100755 web/components/templates/requestsV2/RequestsTable.tsx diff --git a/web/components/templates/requestsV2/RequestsTable.tsx b/web/components/templates/requestsV2/RequestsTable.tsx new file mode 100755 index 0000000000..2d6dce6050 --- /dev/null +++ b/web/components/templates/requestsV2/RequestsTable.tsx @@ -0,0 +1,185 @@ +import React from 'react'; +import { + useTable, + useSortBy, + usePagination, +} from 'react-table'; + +interface Request { + request_id: string; + created_at: string; + status: string; + user: string; + cost: string; + model: string; + request_text: string; + response_text: string; + prompt_tokens: number; +} + +interface RequestsTableProps { + requests: Request[]; +} + +const RequestsTable: React.FC = ({ requests }) => { + const data = React.useMemo( + () => requests, + [requests] + ); + + const columns = React.useMemo( + () => [ + { + Header: 'Created At', + accessor: 'created_at', + }, + { + Header: 'Status', + accessor: 'status', + }, + { + Header: 'User', + accessor: 'user', + }, + { + Header: 'Cost', + accessor: 'cost', + }, + { + Header: 'Model', + accessor: 'model', + Cell: ({ cell: { value } }) => value || 'Unknown', + }, + { + Header: 'Request', + accessor: 'request_text', + }, + { + Header: 'Response', + accessor: 'response_text', + }, + { + Header: 'Prompt Tokens', + accessor: 'prompt_tokens', + }, + ], + [] + ); + + const { + getTableProps, + getTableBodyProps, + headerGroups, + prepareRow, + page, + canPreviousPage, + canNextPage, + pageOptions, + pageCount, + gotoPage, + nextPage, + previousPage, + setPageSize, + state: { pageIndex, pageSize }, + } = useTable( + { + columns, + data, + initialState: { pageIndex: 0 }, + }, + useSortBy, + usePagination + ); + + return ( +
+ + + {headerGroups.map(headerGroup => ( + + {headerGroup.headers.map(column => ( + + ))} + + ))} + + + {page.map(row => { + prepareRow(row); + return ( + + {row.cells.map(cell => { + return ( + + ); + })} + + ); + })} + +
+ {column.render('Header')} + + {column.isSorted + ? column.isSortedDesc + ? ' 🔽' + : ' 🔼' + : ''} + +
{cell.render('Cell')}
+ +
+ {' '} + {' '} + {' '} + {' '} + + Page{' '} + + {pageIndex + 1} of {pageOptions.length} + {' '} + + + | Go to page:{' '} + { + const page = e.target.value ? Number(e.target.value) - 1 : 0; + gotoPage(page); + }} + style={{ width: '100px' }} + /> + {' '} + +
+ + +
+ ); +}; + +export default RequestsTable; diff --git a/web/components/templates/requestsV2/builder/requestBuilder.tsx b/web/components/templates/requestsV2/builder/requestBuilder.tsx index 76cfd5c7b5..e2212ec307 100644 --- a/web/components/templates/requestsV2/builder/requestBuilder.tsx +++ b/web/components/templates/requestsV2/builder/requestBuilder.tsx @@ -152,23 +152,21 @@ const builders: { const getModelFromPath = (path: string) => { const regex1 = /\/engines\/([^/]+)/; const regex2 = /models\/([^/:]+)/; + const regex3 = /\/v\d+\/([^/]+)/; - let match = path.match(regex1); + let match = path.match(regex1) || path.match(regex2) || path.match(regex3); - if (!match) { - match = path.match(regex2); - } - - if (match && match[1]) { - return match[1]; - } else { - return undefined; - } + return match && match[1] ? match[1] : undefined; }; const getRequestBuilder = (request: HeliconeRequest) => { let model = - request.request_model || getModelFromPath(request.target_url) || ""; + request.response_model || + request.model_override || + request.request_model || + getModelFromPath(request.target_url) || + ""; + console.log('Model extracted in getRequestBuilder:', model); const builderType = getBuilderType( model, request.provider, @@ -195,16 +193,16 @@ const isAssistantRequest = (request: HeliconeRequest) => { const getNormalizedRequest = (request: HeliconeRequest): NormalizedRequest => { try { const normalizedRequest = getRequestBuilder(request).build(); - if (!normalizedRequest.model || normalizedRequest.model === "") { - normalizedRequest.model = "Unsupported"; - } - return normalizedRequest; + return { + ...normalizedRequest, + model: normalizedRequest.model || request.response_model || request.model_override || request.request_model || "Unknown", + }; } catch (error) { - const normalizedRequest = getRequestBuilder(request).build(); - if (!normalizedRequest.model || normalizedRequest.model === "") { - normalizedRequest.model = "Unsupported"; - } - return normalizedRequest; + console.error("Error in getNormalizedRequest:", error); + return { + ...getRequestBuilder(request).build(), + model: request.response_model || request.model_override || request.request_model || "Unknown", + }; } }; diff --git a/web/services/hooks/requests.tsx b/web/services/hooks/requests.tsx index 06edc61261..43fcdd68d4 100644 --- a/web/services/hooks/requests.tsx +++ b/web/services/hooks/requests.tsx @@ -120,29 +120,36 @@ const useGetRequestsWithBodies = ( if (!content) return request; const model = - request.model_override || request.response_model || + request.model_override || request.request_model || content?.response?.model || content?.request?.model || content?.response?.body?.model || getModelFromPath(request.target_url) || - ""; + "Unknown"; + + console.log('Extracted model:', model, 'for request:', request.request_id); let updatedRequest = { ...request, request_body: content.request, response_body: content.response, + model: model, }; if ( request.provider === "GOOGLE" && model.toLowerCase().includes("gemini") ) { - updatedRequest.llmSchema = mapGeminiPro( + const mappedRequest = mapGeminiPro( updatedRequest as HeliconeRequest, model ); + updatedRequest = { + ...mappedRequest, + model: model, // Ensure we keep our extracted model + }; } return updatedRequest; From 2b026a08d8637615dca7730d08f315baf68c6c21 Mon Sep 17 00:00:00 2001 From: "use-tusk[bot]" <144006087+use-tusk[bot]@users.noreply.github.com> Date: Wed, 16 Oct 2024 19:48:39 +0000 Subject: [PATCH 03/11] fix: Tusk automated feedback for automated check failure --- .../templates/requestsV2/RequestsTable.tsx | 20 ++++++++++--------- .../requestsV2/builder/requestBuilder.tsx | 4 ++-- 2 files changed, 13 insertions(+), 11 deletions(-) mode change 100755 => 100644 web/components/templates/requestsV2/RequestsTable.tsx diff --git a/web/components/templates/requestsV2/RequestsTable.tsx b/web/components/templates/requestsV2/RequestsTable.tsx old mode 100755 new mode 100644 index 2d6dce6050..dcedfad846 --- a/web/components/templates/requestsV2/RequestsTable.tsx +++ b/web/components/templates/requestsV2/RequestsTable.tsx @@ -48,7 +48,7 @@ const RequestsTable: React.FC = ({ requests }) => { { Header: 'Model', accessor: 'model', - Cell: ({ cell: { value } }) => value || 'Unknown', + Cell: ({ cell: { value } }) => value || 'Unsupported', }, { Header: 'Request', @@ -95,10 +95,10 @@ const RequestsTable: React.FC = ({ requests }) => {
- {headerGroups.map(headerGroup => ( - - {headerGroup.headers.map(column => ( - + {headerGroup.headers.map((column, columnIndex) => ( + - {page.map(row => { + {page.map((row, rowIndex) => { prepareRow(row); return ( - - {row.cells.map(cell => { + + {row.cells.map((cell, cellIndex) => { return ( - + ); })} diff --git a/web/components/templates/requestsV2/builder/requestBuilder.tsx b/web/components/templates/requestsV2/builder/requestBuilder.tsx index e2212ec307..7b70218403 100644 --- a/web/components/templates/requestsV2/builder/requestBuilder.tsx +++ b/web/components/templates/requestsV2/builder/requestBuilder.tsx @@ -195,13 +195,13 @@ const getNormalizedRequest = (request: HeliconeRequest): NormalizedRequest => { const normalizedRequest = getRequestBuilder(request).build(); return { ...normalizedRequest, - model: normalizedRequest.model || request.response_model || request.model_override || request.request_model || "Unknown", + model: normalizedRequest.model || request.response_model || request.model_override || request.request_model || "Unsupported", }; } catch (error) { console.error("Error in getNormalizedRequest:", error); return { ...getRequestBuilder(request).build(), - model: request.response_model || request.model_override || request.request_model || "Unknown", + model: request.response_model || request.model_override || request.request_model || "Unsupported", }; } }; From 19271fbdaa216d189e1056126bef78272bfdf984 Mon Sep 17 00:00:00 2001 From: "use-tusk[bot]" <144006087+use-tusk[bot]@users.noreply.github.com> Date: Wed, 16 Oct 2024 19:51:48 +0000 Subject: [PATCH 04/11] fix(11372792741): auto linting --- .../templates/requestsV2/RequestsTable.tsx | 99 +++++++++---------- .../requestsV2/builder/requestBuilder.tsx | 15 ++- 2 files changed, 61 insertions(+), 53 deletions(-) diff --git a/web/components/templates/requestsV2/RequestsTable.tsx b/web/components/templates/requestsV2/RequestsTable.tsx index dcedfad846..5610b73636 100644 --- a/web/components/templates/requestsV2/RequestsTable.tsx +++ b/web/components/templates/requestsV2/RequestsTable.tsx @@ -1,9 +1,5 @@ -import React from 'react'; -import { - useTable, - useSortBy, - usePagination, -} from 'react-table'; +import React from "react"; +import { useTable, useSortBy, usePagination } from "react-table"; interface Request { request_id: string; @@ -22,45 +18,42 @@ interface RequestsTableProps { } const RequestsTable: React.FC = ({ requests }) => { - const data = React.useMemo( - () => requests, - [requests] - ); + const data = React.useMemo(() => requests, [requests]); const columns = React.useMemo( () => [ { - Header: 'Created At', - accessor: 'created_at', + Header: "Created At", + accessor: "created_at", }, { - Header: 'Status', - accessor: 'status', + Header: "Status", + accessor: "status", }, { - Header: 'User', - accessor: 'user', + Header: "User", + accessor: "user", }, { - Header: 'Cost', - accessor: 'cost', + Header: "Cost", + accessor: "cost", }, { - Header: 'Model', - accessor: 'model', - Cell: ({ cell: { value } }) => value || 'Unsupported', + Header: "Model", + accessor: "model", + Cell: ({ cell: { value } }) => value || "Unsupported", }, { - Header: 'Request', - accessor: 'request_text', + Header: "Request", + accessor: "request_text", }, { - Header: 'Response', - accessor: 'response_text', + Header: "Response", + accessor: "response_text", }, { - Header: 'Prompt Tokens', - accessor: 'prompt_tokens', + Header: "Prompt Tokens", + accessor: "prompt_tokens", }, ], [] @@ -96,16 +89,22 @@ const RequestsTable: React.FC = ({ requests }) => {
+ {headerGroups.map((headerGroup, index) => ( +
{column.render('Header')} {column.isSorted @@ -113,13 +113,15 @@ const RequestsTable: React.FC = ({ requests }) => { ))}
{cell.render('Cell')} + {cell.render('Cell')} +
{headerGroups.map((headerGroup, index) => ( - + {headerGroup.headers.map((column, columnIndex) => ( - ))} @@ -120,7 +119,7 @@ const RequestsTable: React.FC = ({ requests }) => { {row.cells.map((cell, cellIndex) => { return ( ); })} @@ -132,42 +131,42 @@ const RequestsTable: React.FC = ({ requests }) => {
{' '} + {"<<"} + {" "} {' '} + {"<"} + {" "} {' '} + {">"} + {" "} {' '} + {">>"} + {" "} - Page{' '} + Page{" "} {pageIndex + 1} of {pageOptions.length} - {' '} + {" "} - | Go to page:{' '} + | Go to page:{" "} { + onChange={(e) => { const page = e.target.value ? Number(e.target.value) - 1 : 0; gotoPage(page); }} - style={{ width: '100px' }} + style={{ width: "100px" }} /> - {' '} + {" "}
- {column.render('Header')} + + {column.render("Header")} {column.isSorted ? column.isSortedDesc - ? ' 🔽' - : ' 🔼' - : ''} + ? " 🔽" + : " 🔼" + : ""} - {cell.render('Cell')} + {cell.render("Cell")}