-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add searching against all features (#22)
* Add searching against all features * Cleanup * Style search bars and update backend * Search * Fixup * Refactor runpod calling logic * Refactor sequence input component * Input sequence validation * Touchups and mobile * Touchup * Add sort * Add description * Improve folding error * UX stuff * Add examples * Add seq to feature url * Clean
- Loading branch information
Showing
22 changed files
with
948 additions
and
323 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { createContext, useState, useEffect } from "react"; | ||
import { SAE_CONFIGS, SAEConfig } from "./SAEConfigs"; | ||
import { DEFAULT_SAE_MODEL } from "./config"; | ||
import { SidebarProvider } from "@/components/ui/sidebar"; | ||
import { useNavigate } from "react-router-dom"; | ||
import SAESidebar from "./components/SAESidebar"; | ||
|
||
interface SAEContextType { | ||
selectedModel: string; | ||
setSelectedModel: (model: string) => void; | ||
selectedFeature: number | undefined; | ||
setSelectedFeature: (feature: number | undefined) => void; | ||
SAEConfig: SAEConfig; | ||
} | ||
|
||
export const SAEContext = createContext<SAEContextType>({ | ||
selectedModel: DEFAULT_SAE_MODEL, | ||
setSelectedModel: () => {}, | ||
SAEConfig: SAE_CONFIGS[DEFAULT_SAE_MODEL], | ||
selectedFeature: SAE_CONFIGS[DEFAULT_SAE_MODEL].defaultDim, | ||
setSelectedFeature: () => {}, | ||
}); | ||
|
||
export const SAEProvider = ({ children }: { children: React.ReactNode }) => { | ||
const path = window.location.hash.substring(1); | ||
|
||
const modelMatch = path.match(/\/(?:sae-viz\/)?([^/]+)/); | ||
const featureMatch = path.match(/\/(?:sae-viz\/)?[^/]+\/(\d+)/); | ||
|
||
const urlModel = modelMatch ? modelMatch[1] : DEFAULT_SAE_MODEL; | ||
const [selectedModel, setSelectedModel] = useState<string>( | ||
SAE_CONFIGS[urlModel] ? urlModel : DEFAULT_SAE_MODEL | ||
); | ||
|
||
const urlFeature = featureMatch ? Number(featureMatch[1]) : undefined; | ||
const [selectedFeature, setSelectedFeature] = useState<number | undefined>(urlFeature); | ||
|
||
const navigate = useNavigate(); | ||
|
||
useEffect(() => { | ||
if (urlFeature !== undefined && urlFeature !== selectedFeature) { | ||
setSelectedFeature(urlFeature); | ||
} | ||
}, [urlFeature, selectedFeature]); | ||
|
||
return ( | ||
<SAEContext.Provider | ||
value={{ | ||
selectedModel: selectedModel, | ||
setSelectedModel: (model: string) => { | ||
setSelectedModel(model); | ||
if (selectedFeature !== undefined) { | ||
navigate(`/sae-viz/${model}/${selectedFeature}`); | ||
} else { | ||
navigate(`/sae-viz/${model}`); | ||
} | ||
}, | ||
selectedFeature: selectedFeature, | ||
setSelectedFeature: (feature: number | undefined) => { | ||
setSelectedFeature(feature); | ||
if (feature !== undefined) { | ||
navigate(`/sae-viz/${selectedModel}/${feature}`); | ||
} | ||
}, | ||
SAEConfig: SAE_CONFIGS[selectedModel], | ||
}} | ||
> | ||
<SidebarProvider> | ||
<SAESidebar /> | ||
{children} | ||
</SidebarProvider> | ||
</SAEContext.Provider> | ||
); | ||
}; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.