Project NOMAD is an offline-first knowledge and education server. Wikipedia, thousands of books, courses, maps, and optional local AI, all running on hardware you own with no internet required.
TypeScript
feat(benchmark): dashboard re-run banner prompting a Score v2 re-run (#1096)
chriscrosstalk0a2666a2da19
diff --git a/admin/app/controllers/benchmark_controller.ts b/admin/app/controllers/benchmark_controller.tsindex da483c05..144bb54c 100644--- a/admin/app/controllers/benchmark_controller.ts+++ b/admin/app/controllers/benchmark_controller.ts@@ -248,6 +248,13 @@ export default class BenchmarkController {return this.benchmarkService.getStatus()}+ /**+ * Whether to show the dashboard "re-run under Score v2" banner+ */+ async rerunBanner({}: HttpContext) {+ return { show: await this.benchmarkService.shouldShowRerunBanner() }+ }+/*** Get benchmark settings*/diff --git a/admin/app/services/benchmark_service.ts b/admin/app/services/benchmark_service.tsindex 4d7e2f95..e0ae188a 100644--- a/admin/app/services/benchmark_service.ts+++ b/admin/app/services/benchmark_service.ts@@ -215,6 +215,25 @@ export class BenchmarkService {return await BenchmarkResult.findBy('benchmark_id', benchmarkId)}+ /**+ * Whether to show the dashboard "re-run under Score v2" banner. Shown to users+ * who have a v1 leaderboard submission but no Score v2 result yet, and who+ * haven't dismissed it. Self-clears two ways: dismiss sets the KV flag, and any+ * result carrying a nomad_score_v2 (i.e. a v2 run happened) flips (b) false.+ */+ async shouldShowRerunBanner(): Promise<boolean> {+ const dismissed = await KVStore.getValue('benchmark.rerunBannerDismissed')+ if (dismissed === true) return false++ const hasV2Run = await BenchmarkResult.query().whereNotNull('nomad_score_v2').first()+ if (hasV2Run) return false++ const hasSubmittedV1 = await BenchmarkResult.query()+ .where('submitted_to_repository', true)+ .first()+ return hasSubmittedV1 !== null+ }+/*** Submit benchmark results to central repository*/diff --git a/admin/constants/kv_store.ts b/admin/constants/kv_store.tsindex 939bdb58..e071c1ba 100644--- a/admin/constants/kv_store.ts+++ b/admin/constants/kv_store.ts@@ -1,3 +1,3 @@import { KVStoreKey } from "../types/kv_store.js";-export const SETTINGS_KEYS: KVStoreKey[] = ['chat.suggestionsEnabled', 'chat.lastModel', 'ui.hasVisitedEasySetup', 'ui.theme', 'system.earlyAccess', 'system.internetStatusTestUrl', 'ai.assistantCustomName', 'ai.remoteOllamaUrl', 'ai.ollamaFlashAttention', 'ai.autoThinking', 'rag.defaultIngestPolicy', 'autoUpdate.enabled', 'autoUpdate.windowStart', 'autoUpdate.windowEnd', 'autoUpdate.cooloffHours', 'appAutoUpdate.enabled', 'contentAutoUpdate.enabled', 'contentAutoUpdate.windowStart', 'contentAutoUpdate.windowEnd', 'contentAutoUpdate.cooloffHours', 'contentAutoUpdate.maxBytesPerWindow'];\ No newline at end of file+export const SETTINGS_KEYS: KVStoreKey[] = ['chat.suggestionsEnabled', 'chat.lastModel', 'ui.hasVisitedEasySetup', 'ui.theme', 'system.earlyAccess', 'system.internetStatusTestUrl', 'ai.assistantCustomName', 'ai.remoteOllamaUrl', 'ai.ollamaFlashAttention', 'ai.autoThinking', 'rag.defaultIngestPolicy', 'autoUpdate.enabled', 'autoUpdate.windowStart', 'autoUpdate.windowEnd', 'autoUpdate.cooloffHours', 'appAutoUpdate.enabled', 'contentAutoUpdate.enabled', 'contentAutoUpdate.windowStart', 'contentAutoUpdate.windowEnd', 'contentAutoUpdate.cooloffHours', 'contentAutoUpdate.maxBytesPerWindow', 'benchmark.rerunBannerDismissed'];\ No newline at end of filediff --git a/admin/inertia/hooks/useBenchmarkRerunBanner.ts b/admin/inertia/hooks/useBenchmarkRerunBanner.tsnew file mode 100644index 00000000..cf837726--- /dev/null+++ b/admin/inertia/hooks/useBenchmarkRerunBanner.ts@@ -0,0 +1,15 @@+import api from "~/lib/api"+import { useQuery } from "@tanstack/react-query"++export const BENCHMARK_RERUN_BANNER_QUERY_KEY = ['benchmark-rerun-banner']++export const useBenchmarkRerunBanner = () => {+ const queryData = useQuery<{ show: boolean } | undefined>({+ queryKey: BENCHMARK_RERUN_BANNER_QUERY_KEY,+ queryFn: () => api.checkBenchmarkRerunBanner(),+ refetchInterval: Infinity, // Disable automatic refetching+ refetchOnWindowFocus: false,+ })++ return queryData.data+}diff --git a/admin/inertia/lib/api.ts b/admin/inertia/lib/api.tsindex 704ebe50..33172a2a 100644--- a/admin/inertia/lib/api.ts+++ b/admin/inertia/lib/api.ts@@ -382,6 +382,13 @@ class API {})()}+ async checkBenchmarkRerunBanner() {+ return catchInternal(async () => {+ const response = await this.client.get<{ show: boolean }>('/benchmark/rerun-banner')+ return response.data+ })()+ }+async getChatSessions() {return catchInternal(async () => {const response = await this.client.get<Array<{diff --git a/admin/inertia/pages/home.tsx b/admin/inertia/pages/home.tsxindex f51a282e..2322fe0e 100644--- a/admin/inertia/pages/home.tsx+++ b/admin/inertia/pages/home.tsx@@ -13,6 +13,12 @@ import { ServiceSlim } from '../../types/services'import DynamicIcon, { DynamicIconName } from '~/components/DynamicIcon'import { useUpdateAvailable } from '~/hooks/useUpdateAvailable'import { useSystemSetting } from '~/hooks/useSystemSetting'+import {+ useBenchmarkRerunBanner,+ BENCHMARK_RERUN_BANNER_QUERY_KEY,+} from '~/hooks/useBenchmarkRerunBanner'+import { useQueryClient } from '@tanstack/react-query'+import api from '~/lib/api'import Alert from '~/components/Alert'import WhatsNewBanner from '~/components/WhatsNewBanner'import { SERVICE_NAMES } from '../../constants/service_names'@@ -92,8 +98,15 @@ export default function Home(props: {}) {const items: DashboardItem[] = []const updateInfo = useUpdateAvailable();+ const rerunBanner = useBenchmarkRerunBanner()+ const queryClient = useQueryClient()const { aiAssistantName } = usePage<{ aiAssistantName: string }>().props+ const handleDismissRerunBanner = async () => {+ await api.updateSetting('benchmark.rerunBannerDismissed', true)+ queryClient.invalidateQueries({ queryKey: BENCHMARK_RERUN_BANNER_QUERY_KEY })+ }+// Check if user has visited Easy Setupconst { data: easySetupVisited } = useSystemSetting({key: 'ui.hasVisitedEasySetup'@@ -157,6 +170,27 @@ export default function Home(props: {)}<WhatsNewBanner />+ {+ rerunBanner?.show && (+ <div className='flex justify-center items-center px-4 pt-4 w-full'>+ <Alert+ title="Your benchmark can be re-scored with Score v2"+ message="We've upgraded the benchmark scoring system. Re-run your benchmark to get an updated Score v2 result on the community leaderboard."+ type="info-inverted"+ variant="solid"+ className="w-full"+ dismissible+ onDismiss={handleDismissRerunBanner}+ buttonProps={{+ variant: 'primary',+ children: 'Re-run benchmark',+ icon: 'IconRefresh',+ onClick: () => router.visit('/settings/benchmark'),+ }}+ />+ </div>+ )+ }<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4 p-4">{items.map((item) => {const isEasySetup = item.label === 'Easy Setup'diff --git a/admin/start/routes.ts b/admin/start/routes.tsindex ee1d2e94..ab70b9f9 100644--- a/admin/start/routes.ts+++ b/admin/start/routes.ts@@ -253,6 +253,7 @@ routerrouter.post('/builder-tag', [BenchmarkController, 'updateBuilderTag'])router.get('/comparison', [BenchmarkController, 'comparison'])router.get('/status', [BenchmarkController, 'status'])+ router.get('/rerun-banner', [BenchmarkController, 'rerunBanner'])router.get('/settings', [BenchmarkController, 'settings'])router.post('/settings', [BenchmarkController, 'updateSettings'])})diff --git a/admin/types/kv_store.ts b/admin/types/kv_store.tsindex ffed5ebd..b0377f43 100644--- a/admin/types/kv_store.ts+++ b/admin/types/kv_store.ts@@ -44,6 +44,7 @@ export const KV_STORE_SCHEMA = {'ai.autoFixGpuPassthrough': 'boolean','gpu.autoRemediatedAt': 'string','apps.homebox.apiKeyPepper': 'string',+ 'benchmark.rerunBannerDismissed': 'boolean',} as consttype KVTagToType<T extends string> = T extends 'boolean' ? boolean : string