From 8ff0b168ef6eaa9a4fdcc20ca02d6b4d9ee70cf1 Mon Sep 17 00:00:00 2001 From: Shivank Kacker Date: Tue, 30 Jan 2024 19:29:31 +0530 Subject: [PATCH] updated react query and other dependencies --- package.json | 16 +- src/app/(auth)/forgot-password/page.tsx | 16 +- src/app/(auth)/login/page.tsx | 4 +- src/app/(auth)/register/page.tsx | 14 +- src/app/(auth)/reset-password/page.tsx | 18 +- src/app/(main)/page.tsx | 7 +- src/app/(main)/profile/page.tsx | 7 +- .../[project_id]/chat/[chat_id]/page.tsx | 30 +- src/app/(main)/project/[project_id]/page.tsx | 42 +- src/app/admin/page.tsx | 29 +- .../[project_id]/chats/[chat_id]/page.tsx | 15 +- .../projects/[project_id]/chats/page.tsx | 14 +- .../documents/[document_id]/page.tsx | 22 +- .../[project_id]/documents/new/page.tsx | 12 +- src/app/admin/projects/[project_id]/page.tsx | 41 +- src/app/admin/projects/new/page.tsx | 4 +- .../admin/tests/[testsuite_id]/edit/page.tsx | 11 +- src/app/admin/tests/[testsuite_id]/page.tsx | 123 +- .../[testsuite_id]/runs/[testrun_id]/page.tsx | 87 +- src/app/admin/tests/new/page.tsx | 4 +- src/app/admin/tests/page.tsx | 8 +- src/app/admin/users/[username]/page.tsx | 13 +- src/app/admin/users/page.tsx | 61 +- src/app/chatbot/page.tsx | 18 +- src/components/chatblock.tsx | 6 +- src/components/forms/documentform.tsx | 2 +- src/components/forms/projectform.tsx | 8 +- src/components/sidebar/chatSidebar.tsx | 13 +- src/utils/converse.ts | 2 - src/utils/hooks/useInfiQuery.tsx | 43 +- src/utils/hydrate.client.tsx | 4 +- src/utils/provider.tsx | 2 +- yarn.lock | 1707 +++++++++-------- 33 files changed, 1255 insertions(+), 1148 deletions(-) diff --git a/package.json b/package.json index c3639024..6469023d 100644 --- a/package.json +++ b/package.json @@ -19,9 +19,9 @@ }, "dependencies": { "@microsoft/fetch-event-source": "^2.0.1", - "@sentry/nextjs": "^7.88.0", - "@tanstack/react-query": "^4.29.3", - "@tanstack/react-query-devtools": "^4.29.3", + "@sentry/nextjs": "^7.98.0", + "@tanstack/react-query": "^5.17.19", + "@tanstack/react-query-devtools": "^5.17.21", "audio-recorder-polyfill": "^0.4.1", "jotai": "^2.0.4", "json2csv": "^6.0.0-alpha.2", @@ -33,10 +33,10 @@ "react-google-recaptcha": "^3.1.0", "react-hot-toast": "^2.4.1", "react-infinite-scroller": "^1.2.6", - "react-markdown": "^8.0.7", - "rehype-raw": "^6.1.1", - "remark-gfm": "^3.0.1", - "tailwind-merge": "^1.12.0" + "react-markdown": "^9.0.1", + "rehype-raw": "^7.0.0", + "remark-gfm": "^4.0.0", + "tailwind-merge": "^2.2.1" }, "devDependencies": { "@types/eslint": "^8", @@ -49,7 +49,7 @@ "autoprefixer": "^10.4.16", "eslint": "^8.56.0", "eslint-config-next": "^14.0.4", - "husky": "^8.0.3", + "husky": "^9.0.7", "postcss": "^8.4.33", "postcss-prefixer": "^3.0.0", "prettier": "^3.1.1", diff --git a/src/app/(auth)/forgot-password/page.tsx b/src/app/(auth)/forgot-password/page.tsx index 7426d252..6264cb67 100644 --- a/src/app/(auth)/forgot-password/page.tsx +++ b/src/app/(auth)/forgot-password/page.tsx @@ -1,9 +1,7 @@ "use client"; import { Button, Errors, Input } from "@/components/ui/interactive"; -import { storageAtom } from "@/store"; import { API } from "@/utils/api"; import { useMutation } from "@tanstack/react-query"; -import { useAtom } from "jotai"; import Link from "next/link"; import { useRouter } from "next/navigation"; import { useState } from "react"; @@ -14,11 +12,13 @@ export default function ForgotPassword() { }); const router = useRouter(); - const forgotMutation = useMutation(() => API.user.forgot(creds.email), { - onSuccess: (data) => { - router.push("/reset-password?email=" + creds.email); - }, - }); + const forgotMutation = useMutation( + { + mutationFn: () => API.user.forgot(creds.email), + onSuccess: (data) => { + router.push("/reset-password?email=" + creds.email); + }, + }); const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); @@ -43,7 +43,7 @@ export default function ForgotPassword() { - +

Go back diff --git a/src/app/(auth)/login/page.tsx b/src/app/(auth)/login/page.tsx index e67d8370..8153afd8 100644 --- a/src/app/(auth)/login/page.tsx +++ b/src/app/(auth)/login/page.tsx @@ -19,8 +19,8 @@ export default function Login() { const resetSuccess = sp?.get("reset_success"); const loginMutation = useMutation( - () => API.user.login(creds.email, creds.password), { + mutationFn: () => API.user.login(creds.email, creds.password), onSuccess: (data) => { setStorage({ ...storage, @@ -68,7 +68,7 @@ export default function Login() { - +

Don't have an account?{" "} API.user.register(creds), { - onSuccess: (data) => { - router.push("/login"); - }, - }); + const registerMutation = useMutation( + { + mutationFn: () => API.user.register(creds), + onSuccess: (data) => { + router.push("/login"); + }, + }); const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); @@ -81,7 +83,7 @@ export default function Register() { - +

Already have an account?{" "} diff --git a/src/app/(auth)/reset-password/page.tsx b/src/app/(auth)/reset-password/page.tsx index 89f22c63..20cf62ea 100644 --- a/src/app/(auth)/reset-password/page.tsx +++ b/src/app/(auth)/reset-password/page.tsx @@ -20,11 +20,13 @@ export default function ForgotPassword() { const router = useRouter(); - const verifyMutation = useMutation(() => API.user.verify(otp, email || ""), { - onSuccess: (data) => { - setVerified(true); - }, - }); + const verifyMutation = useMutation( + { + mutationFn: () => API.user.verify(otp, email || ""), + onSuccess: (data) => { + setVerified(true); + }, + }); useEffect(() => { if (token && email) { @@ -38,8 +40,8 @@ export default function ForgotPassword() { }; const resetMutation = useMutation( - () => API.user.reset(otp, email || "", password.password), { + mutationFn: () => API.user.reset(otp, email || "", password.password), onSuccess: (data) => { router.push("/login?reset_success=true"); }, @@ -93,7 +95,7 @@ export default function ForgotPassword() { }) } /> - +

Cancel @@ -119,7 +121,7 @@ export default function ForgotPassword() { - +

Go back diff --git a/src/app/(main)/page.tsx b/src/app/(main)/page.tsx index 86985de5..944b6941 100644 --- a/src/app/(main)/page.tsx +++ b/src/app/(main)/page.tsx @@ -1,12 +1,15 @@ "use client"; import { Project } from "@/types/project"; -import { API } from "@/utils/api"; +import { API, paginatedResponse } from "@/utils/api"; import { useQuery } from "@tanstack/react-query"; import { useRouter } from "next/navigation"; import { useEffect } from "react"; export default function Page() { - const projectsQuery = useQuery(["projects"], () => API.projects.list()); + const projectsQuery = useQuery>({ + queryKey: ["projects"], + queryFn: () => API.projects.list() + }); const router = useRouter(); useEffect(() => { diff --git a/src/app/(main)/profile/page.tsx b/src/app/(main)/profile/page.tsx index edffd658..63bd6763 100644 --- a/src/app/(main)/profile/page.tsx +++ b/src/app/(main)/profile/page.tsx @@ -14,7 +14,10 @@ export default function Page() { const [showPassword, setShowPassword] = useState(false); const [showConfirmPassword, setShowConfirmPassword] = useState(false); - const userQuery = useQuery(["userDetails"], API.user.me); + const userQuery = useQuery({ + queryKey: ["userDetails"], + queryFn: API.user.me + }); const userData: User | undefined = userQuery.data || undefined; const [formData, setFormData] = useState({ @@ -34,8 +37,8 @@ export default function Page() { }; const updateProfileMutation = useMutation( - (params: { userDetails: UserUpdate }) => API.user.save(params.userDetails), { + mutationFn: (params: { userDetails: UserUpdate }) => API.user.save(params.userDetails), retry: false, onSuccess: async (data, vars) => { toast.success("Profile updated successfully"); diff --git a/src/app/(main)/project/[project_id]/chat/[chat_id]/page.tsx b/src/app/(main)/project/[project_id]/chat/[chat_id]/page.tsx index 65223f56..a08a0842 100644 --- a/src/app/(main)/project/[project_id]/chat/[chat_id]/page.tsx +++ b/src/app/(main)/project/[project_id]/chat/[chat_id]/page.tsx @@ -25,17 +25,17 @@ export default function Chat(params: { const [isTyping, setIsTyping] = useState(false); const chatQuery = useQuery( - ["chat", chat_id], - () => API.chat.get(project_id, chat_id), { + queryKey: ["chat", chat_id], + queryFn: () => API.chat.get(project_id, chat_id), refetchOnWindowFocus: false, }, ); const projectQuery = useQuery( - ["chat", project_id], - () => API.projects.get(project_id), { + queryKey: ["chat", project_id], + queryFn: () => API.projects.get(project_id), refetchOnWindowFocus: false, }, ); @@ -92,17 +92,17 @@ export default function Chat(params: { }; const converseMutation = useMutation( - (params: { formdata: FormData }) => - API.chat.converse( - project_id, - chat_id, - params.formdata, - openai_key, - streamChatMessage, - 20, - !project?.assistant_id, - ), { + mutationFn: (params: { formdata: FormData }) => + API.chat.converse( + project_id, + chat_id, + params.formdata, + openai_key, + streamChatMessage, + 20, + !project?.assistant_id, + ), retry: false, onSuccess: async (data, vars) => { setAutoPlayIndex((chat?.chats?.length || 0) + 1); @@ -194,7 +194,7 @@ export default function Chat(params: { onSubmit={handleSubmit} onAudio={handleAudio} errors={[(converseMutation.error as any)?.error?.error]} - loading={converseMutation.isLoading || isTyping} + loading={converseMutation.isPending || isTyping} projectId={project_id} />

diff --git a/src/app/(main)/project/[project_id]/page.tsx b/src/app/(main)/project/[project_id]/page.tsx index 55cb25b1..b19df1af 100644 --- a/src/app/(main)/project/[project_id]/page.tsx +++ b/src/app/(main)/project/[project_id]/page.tsx @@ -32,9 +32,9 @@ export default function Chat(params: { params: { project_id: string } }) { }, [chatID, isTyping, project_id, router]); const projectQuery = useQuery( - ["chat", project_id], - () => API.projects.get(project_id), { + queryKey: ["chat", project_id], + queryFn: () => API.projects.get(project_id), refetchOnWindowFocus: false, }, ); @@ -53,13 +53,13 @@ export default function Chat(params: { params: { project_id: string } }) { }; const newChatMutation = useMutation( - (params: { formdata: FormData }) => - API.chat.create( - project_id, - chat !== "" ? chat.slice(0, 50) : "new chat", - storage.openai_api_key, - ), { + mutationFn: (params: { formdata: FormData }) => + API.chat.create( + project_id, + chat !== "" ? chat.slice(0, 50) : "new chat", + storage.openai_api_key, + ), retry: false, onSuccess: async (data, vars) => { await converseMutation.mutateAsync({ @@ -72,22 +72,22 @@ export default function Chat(params: { params: { project_id: string } }) { ); const converseMutation = useMutation( - (params: { external_id: string; formdata: FormData }) => - API.chat.converse( - project_id, - params.external_id, - params.formdata, - openai_key, - streamChatMessage, - 20, - !project?.assistant_id, - ), { + mutationFn: (params: { external_id: string; formdata: FormData }) => + API.chat.converse( + project_id, + params.external_id, + params.formdata, + openai_key, + streamChatMessage, + 20, + !project?.assistant_id, + ), retry: false, onSuccess: async (data, vars) => { if (!data) return; setChatID(data.external_id); - await queryClient.invalidateQueries(["chats"]); + await queryClient.invalidateQueries({ queryKey: ["chats"] }); setIsTyping(false); }, }, @@ -145,7 +145,7 @@ export default function Chat(params: { params: { project_id: string } }) { const fd = await getFormData(undefined, prompt); newChatMutation.mutate({ formdata: fd }); }} - disabled={newChatMutation.isLoading} + disabled={newChatMutation.isPending} className="bg-white hover:shadow-lg hover:bg-gray-100 hover:text-indigo-500 text-left border border-gray-200 rounded-lg p-4 transition disabled:opacity-50 disabled:hover:text-gray-400" key={i} > @@ -204,7 +204,7 @@ export default function Chat(params: { params: { project_id: string } }) { (newChatMutation.error as any)?.error?.non_field_errors, ]} loading={ - newChatMutation.isLoading || converseMutation.isLoading || isTyping + newChatMutation.isPending || converseMutation.isPending || isTyping } projectId={project_id} /> diff --git a/src/app/admin/page.tsx b/src/app/admin/page.tsx index b3a59d8b..b8a8f2fe 100644 --- a/src/app/admin/page.tsx +++ b/src/app/admin/page.tsx @@ -9,9 +9,9 @@ import { useEffect, useState } from "react"; export default function Page() { const [isArchived, setIsArchived] = useState(false); const limit = 10; - const projectsQuery = useInfiQuery( - ["projects"], - ({ pageParam = 1 }) => { + const projectsQuery = useInfiQuery({ + queryKey: ["projects"], + queryFn: ({ pageParam = 1 }) => { const offset = (pageParam - 1) * limit; return API.projects.list({ limit: limit, @@ -20,8 +20,7 @@ export default function Page() { archived: isArchived, }); }, - {}, - ); + }); const projects: any[] = projectsQuery.data?.pages || []; useEffect(() => { @@ -33,15 +32,13 @@ export default function Page() {

Projects

diff --git a/src/app/admin/projects/[project_id]/page.tsx b/src/app/admin/projects/[project_id]/page.tsx index 8cd2e894..b3cf1e80 100644 --- a/src/app/admin/projects/[project_id]/page.tsx +++ b/src/app/admin/projects/[project_id]/page.tsx @@ -12,13 +12,15 @@ import { useState } from "react"; export default function Page({ params }: { params: { project_id: string } }) { const { project_id } = params; - const projectsQuery = useQuery(["project", project_id], () => - API.projects.get(project_id), - ); + const projectsQuery = useQuery({ + queryKey: ["project", project_id], + queryFn: () => API.projects.get(project_id), + }); const project: Project | undefined = projectsQuery.data || undefined; - const documentsQuery = useQuery(["project", project_id, "documents"], () => - API.projects.documents.list(project_id), - ); + const documentsQuery = useQuery({ + queryKey: ["project", project_id, "documents"], + queryFn: () => API.projects.documents.list(project_id), + }); const documents: Document[] | undefined = documentsQuery.data?.results; const [showDeleteModal, setShowDeleteModel] = useState(false); const [showArchiveModal, setShowArchiveModal] = useState(false); @@ -33,8 +35,8 @@ export default function Page({ params }: { params: { project_id: string } }) { }; const updateProjectMutation = useMutation( - (project: Partial) => API.projects.update(project_id, project), { + mutationFn: (project: Partial) => API.projects.update(project_id, project), onSuccess: () => { projectsQuery.refetch(); }, @@ -42,8 +44,8 @@ export default function Page({ params }: { params: { project_id: string } }) { ); const deleteProjectMutation = useMutation( - () => API.projects.delete(project_id), { + mutationFn: () => API.projects.delete(project_id), onSuccess: () => { router.push("/admin"); }, @@ -51,11 +53,11 @@ export default function Page({ params }: { params: { project_id: string } }) { ); const setAsDefautMutation = useMutation( - () => - API.projects.update(project_id, { - is_default: true, - }), { + mutationFn: () => + API.projects.update(project_id, { + is_default: true, + }), onSuccess: () => { projectsQuery.refetch(); }, @@ -63,11 +65,11 @@ export default function Page({ params }: { params: { project_id: string } }) { ); const archiveProjectMutation = useMutation( - () => - API.projects.update(project_id, { - archived: !project?.archived, - }), { + mutationFn: () => + API.projects.update(project_id, { + archived: !project?.archived, + }), onSuccess: () => { projectsQuery.refetch(); }, @@ -125,9 +127,8 @@ export default function Page({ params }: { params: { project_id: string } }) { >
{document.title}
@@ -154,7 +155,7 @@ export default function Page({ params }: { params: { project_id: string } }) { )} diff --git a/src/app/admin/projects/new/page.tsx b/src/app/admin/projects/new/page.tsx index 5403fce5..9406506b 100644 --- a/src/app/admin/projects/new/page.tsx +++ b/src/app/admin/projects/new/page.tsx @@ -10,8 +10,8 @@ export default function Page() { const router = useRouter(); const createProjectMutation = useMutation( - (project) => API.projects.create(project as any), { + mutationFn: (project) => API.projects.create(project as any), onSuccess: (data) => { router.push(`/admin/projects/${data.external_id}`); }, @@ -29,7 +29,7 @@ export default function Page() {
diff --git a/src/app/admin/tests/[testsuite_id]/edit/page.tsx b/src/app/admin/tests/[testsuite_id]/edit/page.tsx index 41b11d73..1b314a05 100644 --- a/src/app/admin/tests/[testsuite_id]/edit/page.tsx +++ b/src/app/admin/tests/[testsuite_id]/edit/page.tsx @@ -9,14 +9,15 @@ import { useRouter } from "next/navigation"; export default function Page({ params }: { params: { testsuite_id: string } }) { const router = useRouter(); const { testsuite_id } = params; - const testSuiteQuery = useQuery(["testsuite", testsuite_id], () => - API.tests.suites.get(testsuite_id), - ); + const testSuiteQuery = useQuery({ + queryKey: ["testsuite", testsuite_id], + queryFn: () => API.tests.suites.get(testsuite_id), + }); const testSuite: TestSuite | undefined = testSuiteQuery.data || undefined; const updateTestSuiteMutation = useMutation( - (testSuite) => API.tests.suites.update(testsuite_id, testSuite as any), { + mutationFn: (testSuite) => API.tests.suites.update(testsuite_id, testSuite as any), onSuccess: (data) => { router.push(`/admin/tests/${data.external_id}`); }, @@ -35,7 +36,7 @@ export default function Page({ params }: { params: { testsuite_id: string } }) { )} diff --git a/src/app/admin/tests/[testsuite_id]/page.tsx b/src/app/admin/tests/[testsuite_id]/page.tsx index b60cb86d..454fc5d5 100644 --- a/src/app/admin/tests/[testsuite_id]/page.tsx +++ b/src/app/admin/tests/[testsuite_id]/page.tsx @@ -1,8 +1,6 @@ "use client"; import { supportedLanguages } from "@/utils/constants"; -import ProjectForm from "@/components/forms/projectform"; -import TestSuiteForm from "@/components/forms/testsuiteform"; import Modal from "@/components/modal"; import { Button, CheckBox, Input, TextArea } from "@/components/ui/interactive"; import { Document, DocumentType, Project } from "@/types/project"; @@ -30,39 +28,44 @@ export default function Page({ params }: { params: { testsuite_id: string } }) { const { testsuite_id } = params; const testSuiteQuery = useQuery( - ["testsuite", testsuite_id], - () => API.tests.suites.get(testsuite_id), { + queryKey: ["testsuite", testsuite_id], + queryFn: () => API.tests.suites.get(testsuite_id), refetchOnWindowFocus: false, }, ); const testSuite: TestSuite | undefined = testSuiteQuery.data || undefined; const TestQuestionsQuery = useQuery( - ["testsuitequestion", testsuite_id], - () => - API.tests.questions.list(testsuite_id, { - ordering: "created_at", - limit: 100, - }), - { refetchOnWindowFocus: false }, + { + queryKey: ["testsuitequestion", testsuite_id], + queryFn: () => + API.tests.questions.list(testsuite_id, { + ordering: "created_at", + limit: 100, + }), + refetchOnWindowFocus: false + }, ); const testQuestions: TestQuestion[] | undefined = TestQuestionsQuery.data?.results || undefined; - const ProjectListQuery = useQuery(["projects"], () => API.projects.list()); + const ProjectListQuery = useQuery({ + queryKey: ["projects"], + queryFn: () => API.projects.list() + }); const projects: Project[] = ProjectListQuery.data?.results || []; const createDocumentMutation = useMutation( - async (args: { question_id: string; formData: any }) => { - const { question_id, formData } = args; - await API.tests.questions.documents.create( - testsuite_id, - question_id, - formData, - ); - }, { + mutationFn: async (args: { question_id: string; formData: any }) => { + const { question_id, formData } = args; + await API.tests.questions.documents.create( + testsuite_id, + question_id, + formData, + ); + }, onSuccess: () => { toast.success("Document Attached!"); TestQuestionsQuery.refetch(); @@ -76,15 +79,15 @@ export default function Page({ params }: { params: { testsuite_id: string } }) { ); const deleteDocumentMutation = useMutation( - async (args: { question_id: string; document_id: string }) => { - const { question_id, document_id } = args; - await API.tests.questions.documents.delete( - testsuite_id, - question_id, - document_id, - ); - }, { + mutationFn: async (args: { question_id: string; document_id: string }) => { + const { question_id, document_id } = args; + await API.tests.questions.documents.delete( + testsuite_id, + question_id, + document_id, + ); + }, onSuccess: () => { toast.success("Document Deleted"); TestQuestionsQuery.refetch(); @@ -105,7 +108,7 @@ export default function Page({ params }: { params: { testsuite_id: string } }) { offset: number | null; }; - const fetchData: QueryFunction = async ({ pageParam }) => { + const fetchData: QueryFunction = async ({ pageParam = 0 }) => { const offset = pageParam ? pageParam : 0; const res = await API.tests.runs.list(testsuite_id, { ordering: "-created_at", @@ -161,9 +164,9 @@ export default function Page({ params }: { params: { testsuite_id: string } }) { ); const TestQuestionsAddMutation = useMutation( - (question: Partial) => - API.tests.questions.create(testsuite_id, question), { + mutationFn: (question: Partial) => + API.tests.questions.create(testsuite_id, question), onSuccess: () => { toast.success("Test Question Added"); TestQuestionsQuery.refetch(); @@ -172,9 +175,9 @@ export default function Page({ params }: { params: { testsuite_id: string } }) { ); const TestQuestionDeleteMutation = useMutation( - (question_id: string) => - API.tests.questions.delete(testsuite_id, question_id), { + mutationFn: (question_id: string) => + API.tests.questions.delete(testsuite_id, question_id), onSuccess: () => { toast.success("Test Question Deleted"); TestQuestionsQuery.refetch(); @@ -183,8 +186,8 @@ export default function Page({ params }: { params: { testsuite_id: string } }) { ); const TestRunCreateMutation = useMutation( - (testRun: Partial) => API.tests.runs.create(testsuite_id, testRun), { + mutationFn: (testRun: Partial) => API.tests.runs.create(testsuite_id, testRun), onSuccess: (testRun) => { toast.success("Test Started"); refetch(); @@ -342,9 +345,9 @@ export default function Page({ params }: { params: { testsuite_id: string } }) { ) .toString() .padStart(2, "0")}-${date.getFullYear()} at ${date - .getHours() - .toString() - .padStart(2, "0")}:${date.getMinutes().toString().padStart(2, "0")}`; + .getHours() + .toString() + .padStart(2, "0")}:${date.getMinutes().toString().padStart(2, "0")}`; } function getStatusClassName(status: number): string { @@ -604,11 +607,10 @@ export default function Page({ params }: { params: { testsuite_id: string } }) { > {has_new_document ? (
{ if (document.state === "uploading") return; setDocument({ @@ -690,18 +692,18 @@ export default function Page({ params }: { params: { testsuite_id: string } }) { const avgBleu = testRun && testRun.test_results ? testRun?.test_results?.reduce( - (acc: number, test: TestResult) => - acc + (test.bleu_score || 0), - 0, - ) / (testRun?.test_results?.length || 1) + (acc: number, test: TestResult) => + acc + (test.bleu_score || 0), + 0, + ) / (testRun?.test_results?.length || 1) : 0; const avgCosineSim = testRun && testRun.test_results ? testRun?.test_results?.reduce( - (acc: number, test: TestResult) => - acc + (test.cosine_sim || 0), - 0, - ) / (testRun?.test_results?.length || 1) + (acc: number, test: TestResult) => + acc + (test.cosine_sim || 0), + 0, + ) / (testRun?.test_results?.length || 1) : 0; return (