1- import { createQuery } from "@tanstack/solid-query" ;
1+ /* eslint-disable @typescript-eslint/no-unsafe-call */
2+ /* eslint-disable @typescript-eslint/no-unsafe-member-access */
3+ /* eslint-disable @typescript-eslint/no-unsafe-assignment */
4+ import { createQuery , CreateQueryResult } from "@tanstack/solid-query" ;
25import { getRagQuery , getSearchQuery } from "../../api/analytics" ;
36import { createMemo , For , Show , useContext } from "solid-js" ;
47import { format } from "date-fns" ;
@@ -10,6 +13,7 @@ import { DataSquare } from "../SingleQueryInfo/DataSquare";
1013import { DatasetContext } from "../../../contexts/DatasetContext" ;
1114import { UserContext } from "../../../contexts/UserContext" ;
1215import { IoArrowBackOutline } from "solid-icons/io" ;
16+ import { isScoreChunkDTO , SearchQueryEvent } from "shared/types" ;
1317
1418interface SingleRAGQueryProps {
1519 queryId : string ;
@@ -24,19 +28,22 @@ export const SingleRAGQuery = (props: SingleRAGQueryProps) => {
2428 } ,
2529 } ) ) ;
2630
27- const search_query = createQuery ( ( ) => ( {
28- queryKey : [ "single_query" , rag_query . data ?. search_id ] ,
29- queryFn : ( ) => {
30- return getSearchQuery (
31- dataset . datasetId ( ) ,
32- rag_query . data ?. search_id ?? "" ,
33- ) ;
34- } ,
35- } ) ) ;
31+ let search_query : CreateQueryResult < SearchQueryEvent , Error > | undefined ;
32+ if ( rag_query . data ?. search_id !== "00000000-0000-0000-0000-000000000000" ) {
33+ search_query = createQuery ( ( ) => ( {
34+ queryKey : [ "single_query" , rag_query . data ?. search_id ] ,
35+ queryFn : ( ) => {
36+ return getSearchQuery (
37+ dataset . datasetId ( ) ,
38+ rag_query . data ?. search_id ?? "" ,
39+ ) ;
40+ } ,
41+ } ) ) ;
42+ }
3643
3744 const DataDisplay = ( props : {
3845 rag_data : NonNullable < typeof rag_query . data > ;
39- search_data : NonNullable < typeof search_query . data > ;
46+ search_data ?: SearchQueryEvent ;
4047 } ) => {
4148 const datasetName = createMemo ( ( ) => {
4249 const userContext = useContext ( UserContext ) ;
@@ -72,65 +79,102 @@ export const SingleRAGQuery = (props: SingleRAGQueryProps) => {
7279 label = "Dataset"
7380 value = { datasetName ( ) || props . rag_data . dataset_id }
7481 />
75- < DataSquare
76- label = "Results"
77- value = { props . search_data . results . length }
78- />
79- < DataSquare
80- label = "Top Score"
81- value = { props . search_data . top_score . toFixed ( 4 ) }
82- />
83- < Show when = { props . rag_data . query_rating } >
82+ < Show
83+ when = {
84+ ( props . search_data ?. results && props . search_data . results [ 0 ] ) ||
85+ ( props . rag_data ?. results && props . rag_data . results [ 0 ] )
86+ }
87+ >
88+ < DataSquare
89+ label = "Results"
90+ value = {
91+ props . search_data
92+ ? props . search_data . results . length
93+ : props . rag_data . results . length
94+ }
95+ />
96+ </ Show >
97+ < Show when = { props . search_data && props . search_data . top_score > 0.0 } >
98+ < DataSquare
99+ label = "Top Score"
100+ value = { props . search_data ?. top_score . toPrecision ( 4 ) ?? "N/A" }
101+ />
102+ </ Show >
103+ < Show
104+ when = {
105+ props . rag_data . query_rating &&
106+ ( props . rag_data . query_rating . rating > 0 ||
107+ props . rag_data . query_rating . note )
108+ }
109+ >
84110 < DataSquare
85111 label = "User Rating"
86112 value = { props . rag_data . query_rating ?. rating . toString ( ) ?? "N/A" }
87113 />
88114 </ Show >
89115 </ dl >
90116 </ div >
91- < Card title = "LLM Response" >
92- < ul >
93- < li > { props . rag_data . llm_response } </ li >
94- </ ul >
95- </ Card >
96- < Card title = "Results" >
97- < div class = "grid gap-4 sm:grid-cols-2" >
98- < For
99- fallback = { < div class = "py-8 text-center" > No Data.</ div > }
100- each = { props . search_data . results }
101- >
102- { ( result ) => < ResultCard result = { result } /> }
103- </ For >
104- </ div >
105- </ Card >
106- < Card title = "Search Request Parameters" >
107- < ul >
108- < For
109- each = { Object . keys ( props . search_data . request_params ) . filter (
110- ( key ) => props . search_data . request_params [ key ] ,
111- ) }
112- >
113- { ( key ) => (
114- < li class = "text-sm" >
115- < span class = "font-medium" > { key } : </ span >
116- { props . search_data . request_params [ key ] as string } { " " }
117- </ li >
118- ) }
119- </ For >
120- </ ul >
121- </ Card >
117+ < Show when = { props . rag_data . llm_response } >
118+ < Card title = "LLM Response" >
119+ < ul >
120+ < li > { props . rag_data . llm_response } </ li >
121+ </ ul >
122+ </ Card >
123+ </ Show >
124+ < Show when = { props . search_data ?. results && props . search_data . results [ 0 ] } >
125+ < Card title = "Results" >
126+ < div class = "grid gap-4 sm:grid-cols-2" >
127+ < For
128+ fallback = { < div class = "py-8 text-center" > No Data.</ div > }
129+ each = {
130+ props . search_data
131+ ? props . search_data . results
132+ : props . rag_data . results
133+ }
134+ >
135+ { ( result ) => {
136+ if ( isScoreChunkDTO ( result ) ) {
137+ return < ResultCard result = { result } /> ;
138+ } else {
139+ return (
140+ < div >
141+ < pre class = "text-sm" >
142+ { JSON . stringify ( result , null , 2 ) }
143+ </ pre >
144+ </ div >
145+ ) ;
146+ }
147+ } }
148+ </ For >
149+ </ div >
150+ </ Card >
151+ </ Show >
152+ < Show when = { props . search_data && props . search_data . request_params } >
153+ < Card title = "Search Request Parameters" >
154+ < ul >
155+ < For
156+ each = { Object . keys (
157+ props . search_data ?. request_params ?? { } ,
158+ ) . filter ( ( key ) => props . search_data ?. request_params [ key ] ) }
159+ >
160+ { ( key ) => (
161+ < li class = "text-sm" >
162+ < span class = "font-medium" > { key } : </ span >
163+ { props . search_data ?. request_params [ key ] as string } { " " }
164+ </ li >
165+ ) }
166+ </ For >
167+ </ ul >
168+ </ Card >
169+ </ Show >
122170 </ div >
123171 ) ;
124172 } ;
125173
126174 return (
127175 < Show when = { rag_query . data } >
128176 { ( rag_data ) => (
129- < Show when = { search_query . data } >
130- { ( search_data ) => (
131- < DataDisplay rag_data = { rag_data ( ) } search_data = { search_data ( ) } />
132- ) }
133- </ Show >
177+ < DataDisplay rag_data = { rag_data ( ) } search_data = { search_query ?. data } />
134178 ) }
135179 </ Show >
136180 ) ;
0 commit comments