Cleaning up

This commit is contained in:
James Ketr 2025-05-16 15:43:11 -07:00
parent 9d3d952619
commit 4bbaa15e09
7 changed files with 62 additions and 43 deletions

4
.gitignore vendored
View File

@ -1,3 +1,7 @@
users/**
!users/eliza
users-prod/**
!users-prod/eliza
.env* .env*
docs/** docs/**
docs-prod/** docs-prod/**

View File

@ -1,4 +1,3 @@
.Conversation { .Conversation {
display: flex; display: flex;
background-color: #F5F5F5; background-color: #F5F5F5;
@ -12,3 +11,4 @@
overflow-y: auto; overflow-y: auto;
height: calc(100vh - 72px); height: calc(100vh - 72px);
} }

View File

@ -1,19 +1,13 @@
/* .js-plotly-plot {
width: 100%;
height: 100%;
}
.js-plotly-plot .plotly { .VectorVisualizer {
display: flex;
flex-grow: 1;
flex-direction: column;
background-color: #F5F5F5;
border: 1px solid #E0E0E0;
font-size: 0.9rem;
margin: 0 auto;
padding: 10px;
position: relative;
width: 100%; width: 100%;
height: 100%;
} }
.js-plotly-plot .plotly .main-svg {
width: 100%;
height: 100%;
}
.plotly .svg-container {
width: 100% !important;
height: 100% !important;
} */

View File

@ -70,8 +70,8 @@ const config: Partial<Plotly.Config> = {
showSendToCloud: false, showSendToCloud: false,
staticPlot: false, staticPlot: false,
frameMargins: 0, frameMargins: 0,
scrollZoom: true, scrollZoom: false,
doubleClick: "reset+autosize", doubleClick: false,
// | "lasso2d" // | "lasso2d"
// | "select2d" // | "select2d"
// | "sendDataToCloud" // | "sendDataToCloud"
@ -116,6 +116,7 @@ const config: Partial<Plotly.Config> = {
const layout: Partial<Plotly.Layout> = { const layout: Partial<Plotly.Layout> = {
autosize: false, autosize: false,
clickmode: 'event+select',
paper_bgcolor: '#FFFFFF', // white paper_bgcolor: '#FFFFFF', // white
plot_bgcolor: '#FFFFFF', // white plot background plot_bgcolor: '#FFFFFF', // white plot background
font: { font: {
@ -193,6 +194,7 @@ const VectorVisualizer: React.FC<VectorVisualizerProps> = (props: VectorVisualiz
const [result, setResult] = useState<QuerySet | undefined>(undefined); const [result, setResult] = useState<QuerySet | undefined>(undefined);
const [view2D, setView2D] = useState<boolean>(true); const [view2D, setView2D] = useState<boolean>(true);
const plotlyRef = useRef(null); const plotlyRef = useRef(null);
const boxRef = useRef<HTMLElement>(null);
const [node, setNode] = useState<Node | null>(null); const [node, setNode] = useState<Node | null>(null);
const theme = useTheme(); const theme = useTheme();
const isMobile = useMediaQuery(theme.breakpoints.down('md')); const isMobile = useMediaQuery(theme.breakpoints.down('md'));
@ -201,16 +203,24 @@ const VectorVisualizer: React.FC<VectorVisualizerProps> = (props: VectorVisualiz
/* Force resize of Plotly as it tends to not be the correct size if it is initially rendered /* Force resize of Plotly as it tends to not be the correct size if it is initially rendered
* off screen (eg., the VectorVisualizer is not on the tab the app loads to) */ * off screen (eg., the VectorVisualizer is not on the tab the app loads to) */
useEffect(() => { useEffect(() => {
if (!boxRef.current) {
return;
}
const resize = () => {
requestAnimationFrame(() => { requestAnimationFrame(() => {
const plotContainer = document.querySelector('.plot-container') as HTMLElement; const plotContainer = document.querySelector('.plot-container') as HTMLElement;
const svgContainer = document?.querySelector('.svg-container') as HTMLElement; const svgContainer = document?.querySelector('.svg-container') as HTMLElement;
if ( plotContainer && svgContainer) { if (plotContainer && svgContainer) {
const plotContainerRect = plotContainer.getBoundingClientRect(); const plotContainerRect = plotContainer.getBoundingClientRect();
svgContainer.style.width = `${plotContainerRect.width}px`; svgContainer.style.width = `${plotContainerRect.width}px`;
svgContainer.style.height = `${plotContainerRect.height}px`; svgContainer.style.height = `${plotContainerRect.height}px`;
setPlotDimensions({ width: plotContainerRect.width, height: plotContainerRect.height}); if (plotDimensions.width !== plotContainerRect.width || plotDimensions.height != plotContainerRect.height) {
setPlotDimensions({ width: plotContainerRect.width, height: plotContainerRect.height });
}
} }
}); });
}
resize();
}); });
// Get the collection to visualize // Get the collection to visualize
@ -237,7 +247,7 @@ const VectorVisualizer: React.FC<VectorVisualizerProps> = (props: VectorVisualiz
}; };
fetchCollection(); fetchCollection();
}, [result, setResult, setSnack, sessionId, view2D]) }, [result, setSnack, sessionId, view2D])
useEffect(() => { useEffect(() => {
if (!result || !result.embeddings) return; if (!result || !result.embeddings) return;
@ -365,12 +375,7 @@ const VectorVisualizer: React.FC<VectorVisualizerProps> = (props: VectorVisualiz
setPlotData(data); setPlotData(data);
}, [result, querySet, view2D, setPlotData, setSnack]); }, [result, querySet, view2D]);
if (setSnack === undefined) {
console.error('setSnack function is undefined');
return null;
}
const handleKeyPress = (event: any) => { const handleKeyPress = (event: any) => {
if (event.key === 'Enter') { if (event.key === 'Enter') {
@ -465,7 +470,8 @@ The scatter graph shows the query in N-dimensional space, mapped to ${view2D ? '
}; };
return ( return (
<Box className="VectorVisualizer Conversation" <Box className="VectorVisualizer"
ref={boxRef}
sx={{ sx={{
display: 'flex', display: 'flex',
position: 'relative', position: 'relative',
@ -507,7 +513,7 @@ The scatter graph shows the query in N-dimensional space, mapped to ${view2D ? '
control={<Switch checked={!view2D} />} onChange={() => setView2D(!view2D)} label="3D" /> control={<Switch checked={!view2D} />} onChange={() => setView2D(!view2D)} label="3D" />
<Plot <Plot
ref={plotlyRef} ref={plotlyRef}
onClick={(event: any) => { onNodeSelected(event.points[0].customdata); }} onClick={(event: any) => { console.log("click"); onNodeSelected(event.points[0].customdata); }}
data={plotData} data={plotData}
useResizeHandler={true} useResizeHandler={true}
config={config} config={config}

View File

@ -0,0 +1,15 @@
.VectorVisualizerPage {
display: flex;
flex-grow: 1;
flex-direction: column;
background-color: #F5F5F5;
border: 1px solid #E0E0E0;
font-size: 0.9rem;
margin: 0 auto;
padding: 10px;
position: relative;
width: 100%;
max-width: 1024px;
height: calc(100vh - 72px);
}

View File

@ -1,9 +1,11 @@
import React, { useEffect, useState, useRef } from 'react'; import React from 'react';
import { Scrollable } from '../Components/Scrollable'; import { Scrollable } from '../Components/Scrollable';
import { VectorVisualizer } from '../Components/VectorVisualizer'; import { VectorVisualizer } from '../Components/VectorVisualizer';
import { BackstoryPageProps } from '../Components/BackstoryTab'; import { BackstoryPageProps } from '../Components/BackstoryTab';
import './VectorVisualizerPage.css';
interface VectorVisualizerProps extends BackstoryPageProps { interface VectorVisualizerProps extends BackstoryPageProps {
inline?: boolean; inline?: boolean;
rag?: any; rag?: any;
@ -11,10 +13,10 @@ interface VectorVisualizerProps extends BackstoryPageProps {
const VectorVisualizerPage: React.FC<VectorVisualizerProps> = (props: VectorVisualizerProps) => { const VectorVisualizerPage: React.FC<VectorVisualizerProps> = (props: VectorVisualizerProps) => {
return <Scrollable return <Scrollable
className="VectorVisualizerPage"
autoscroll={false} autoscroll={false}
sx={{ sx={{
maxWidth: "1024px", overflowY: "scroll",
height: "calc(100vh - 72px)",
}} }}
> >
<VectorVisualizer {...props} /> <VectorVisualizer {...props} />

View File

@ -5,8 +5,6 @@ import os
os.environ["TORCH_CPP_LOG_LEVEL"] = "ERROR" os.environ["TORCH_CPP_LOG_LEVEL"] = "ERROR"
import warnings import warnings
warnings.filterwarnings("ignore", message="Couldn't find ffmpeg or avconv")
import ollama import ollama
from ..utils import rag as Rag, Context, defines from ..utils import rag as Rag, Context, defines