Spaces:
Configuration error
Configuration error
File size: 7,152 Bytes
447ebeb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
import React, { useState } from "react";
import { getProviderLogoAndName } from "../provider_info_helpers";
interface VectorStoreContent {
text: string;
type: string;
}
interface VectorStoreResult {
score: number;
content: VectorStoreContent[];
}
interface VectorStoreSearchResponse {
data: VectorStoreResult[];
search_query: string;
}
interface VectorStoreRequestMetadata {
query: string;
end_time: number;
start_time: number;
vector_store_id: string;
custom_llm_provider: string;
vector_store_search_response: VectorStoreSearchResponse;
}
interface VectorStoreViewerProps {
data: VectorStoreRequestMetadata[];
}
export function VectorStoreViewer({ data }: VectorStoreViewerProps) {
const [sectionExpanded, setSectionExpanded] = useState(true);
const [expandedResults, setExpandedResults] = useState<Record<string, boolean>>({});
if (!data || data.length === 0) {
return null;
}
const formatTime = (timestamp: number): string => {
const date = new Date(timestamp * 1000);
return date.toLocaleString();
};
const calculateDuration = (start: number, end: number): string => {
const duration = (end - start) * 1000; // convert to milliseconds
return `${duration.toFixed(2)}ms`;
};
const toggleResult = (index: number, resultIndex: number) => {
const key = `${index}-${resultIndex}`;
setExpandedResults(prev => ({
...prev,
[key]: !prev[key]
}));
};
return (
<div className="bg-white rounded-lg shadow mb-6">
<div
className="flex justify-between items-center p-4 border-b cursor-pointer hover:bg-gray-50"
onClick={() => setSectionExpanded(!sectionExpanded)}
>
<div className="flex items-center">
<svg
className={`w-5 h-5 mr-2 text-gray-600 transition-transform ${sectionExpanded ? 'transform rotate-90' : ''}`}
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
>
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 5l7 7-7 7" />
</svg>
<h3 className="text-lg font-medium">Vector Store Requests</h3>
</div>
<span className="text-sm text-gray-500">{sectionExpanded ? 'Click to collapse' : 'Click to expand'}</span>
</div>
{sectionExpanded && (
<div className="p-4">
{data.map((request, index) => (
<div key={index} className="mb-6 last:mb-0">
<div className="bg-white rounded-lg border p-4 mb-4">
<div className="grid grid-cols-2 gap-4">
<div className="space-y-2">
<div className="flex">
<span className="font-medium w-1/3">Query:</span>
<span className="font-mono">{request.query}</span>
</div>
<div className="flex">
<span className="font-medium w-1/3">Vector Store ID:</span>
<span className="font-mono">{request.vector_store_id}</span>
</div>
<div className="flex">
<span className="font-medium w-1/3">Provider:</span>
<span className="flex items-center">
{(() => {
const { logo, displayName } = getProviderLogoAndName(request.custom_llm_provider);
return (
<>
{logo && (
<img
src={logo}
alt={`${displayName} logo`}
className="h-5 w-5 mr-2"
/>
)}
{displayName}
</>
);
})()}
</span>
</div>
</div>
<div className="space-y-2">
<div className="flex">
<span className="font-medium w-1/3">Start Time:</span>
<span>{formatTime(request.start_time)}</span>
</div>
<div className="flex">
<span className="font-medium w-1/3">End Time:</span>
<span>{formatTime(request.end_time)}</span>
</div>
<div className="flex">
<span className="font-medium w-1/3">Duration:</span>
<span>{calculateDuration(request.start_time, request.end_time)}</span>
</div>
</div>
</div>
</div>
<h4 className="font-medium mb-2">Search Results</h4>
<div className="space-y-2">
{request.vector_store_search_response.data.map((result, resultIndex) => {
const isExpanded = expandedResults[`${index}-${resultIndex}`] || false;
return (
<div key={resultIndex} className="border rounded-lg overflow-hidden">
<div
className="flex items-center p-3 bg-gray-50 cursor-pointer"
onClick={() => toggleResult(index, resultIndex)}
>
<svg
className={`w-5 h-5 mr-2 transition-transform ${isExpanded ? 'transform rotate-90' : ''}`}
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
>
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 5l7 7-7 7" />
</svg>
<div className="flex items-center">
<span className="font-medium mr-2">Result {resultIndex + 1}</span>
<span className="text-gray-500 text-sm">
Score: <span className="font-mono">{result.score.toFixed(4)}</span>
</span>
</div>
</div>
{isExpanded && (
<div className="p-3 border-t bg-white">
{result.content.map((content, contentIndex) => (
<div key={contentIndex} className="mb-2 last:mb-0">
<div className="text-xs text-gray-500 mb-1">{content.type}</div>
<pre className="text-xs font-mono whitespace-pre-wrap break-all bg-gray-50 p-2 rounded">
{content.text}
</pre>
</div>
))}
</div>
)}
</div>
);
})}
</div>
</div>
))}
</div>
)}
</div>
);
} |