From 40675ca2247dbc2fc044ab7268c7f93a7986ab29 Mon Sep 17 00:00:00 2001 From: Yifan Mai Date: Wed, 8 Jan 2025 16:00:43 -0800 Subject: [PATCH] Refactor agreement frontend (#3258) --- .../src/components/UserAgreement.tsx | 82 +++++++++++++++++++ helm-frontend/src/routes/Run.tsx | 46 +---------- .../services/getDisplayPredictionsByName.ts | 3 +- .../src/services/getDisplayRequestsByName.ts | 3 +- helm-frontend/src/services/getInstances.ts | 3 +- .../src/utils/isScenarioEncrypted.ts | 3 + 6 files changed, 95 insertions(+), 45 deletions(-) create mode 100644 helm-frontend/src/components/UserAgreement.tsx create mode 100644 helm-frontend/src/utils/isScenarioEncrypted.ts diff --git a/helm-frontend/src/components/UserAgreement.tsx b/helm-frontend/src/components/UserAgreement.tsx new file mode 100644 index 00000000000..280aaf1d6dc --- /dev/null +++ b/helm-frontend/src/components/UserAgreement.tsx @@ -0,0 +1,82 @@ +import { useRef } from "react"; + +interface Props { + runName: string; + onAgree: () => void; +} + +export default function Tab({ runName, onAgree }: Props) { + const inputRef = useRef(null); + + const handleAgreement = () => { + if ( + inputRef.current !== null && + inputRef.current.value.trim() === "Yes, I agree" + ) { + onAgree(); + } else { + alert("Please type 'Yes, I agree' exactly."); + } + }; + const agreement = runName.includes("gpqa") ? ( + + ) : runName.includes("ewok") ? ( + + ) : null; + + return ( +
+ {agreement} +

+ If you agree to this condition, please type{" "} + "Yes, I agree" in the box below and then click{" "} + Decrypt. +

+
+ + +
+
+
+ ); +} + +function GPQATerms() { + return ( +
+

+ The GPQA dataset instances are encrypted by default to comply with the + following request: +

+
+ “We ask that you do not reveal examples from this dataset in plain text + or images online, to minimize the risk of these instances being included + in foundation model training corpora.” +
+
+ ); +} + +function EWoKTerms() { + return ( +
+

+ The EWoK dataset instances are encrypted by default to comply with the + following request: +

+
+ “PLEASE DO NOT distribute any of the EWoK materials or derivatives + publicly in plain-text! Any materials should appear in + password-protected ZIP files or behind gated authentication mechanisms + such as Huggingface datasets.” +
+
+ ); +} diff --git a/helm-frontend/src/routes/Run.tsx b/helm-frontend/src/routes/Run.tsx index 49a4eba2249..e85f9c0081d 100644 --- a/helm-frontend/src/routes/Run.tsx +++ b/helm-frontend/src/routes/Run.tsx @@ -24,6 +24,8 @@ import getRunsToRunSuites from "@/services/getRunsToRunSuites"; import getSuiteForRun from "@/services/getSuiteForRun"; import Instances from "@/components/Instances"; import RunMetrics from "@/components/RunMetrics"; +import UserAgreement from "@/components/UserAgreement"; +import isScenarioEncrypted from "@/utils/isScenarioEncrypted"; export default function Run() { const { runName } = useParams(); @@ -37,7 +39,6 @@ export default function Run() { MetricFieldMap | undefined >({}); - const [agreeInput, setAgreeInput] = useState(""); const [userAgreed, setUserAgreed] = useState(false); useEffect(() => { @@ -96,16 +97,6 @@ export default function Run() { return ; } - // Handler for agreement - const handleAgreement = () => { - if (agreeInput.trim() === "Yes, I agree") { - setUserAgreed(true); - } else { - setUserAgreed(false); - alert("Please type 'Yes, I agree' exactly."); - } - }; - return ( <>
@@ -192,37 +183,8 @@ export default function Run() {
- {activeTab === 0 && runName.includes("gpqa") && !userAgreed && ( -
-
-

- The GPQA dataset instances are encrypted by default to comply with - the following request: -

-
- “We ask that you do not reveal examples from this dataset in plain - text or images online, to minimize the risk of these instances being - included in foundation model training corpora.” -
-

- If you agree to this condition, please type{" "} - "Yes, I agree" in the box below and then click{" "} - Decrypt. -

-
- setAgreeInput(e.target.value)} - className="input input-bordered" - placeholder='Type "Yes, I agree"' - /> - -
-
-
+ {activeTab === 0 && isScenarioEncrypted(runName) && !userAgreed && ( + setUserAgreed(true)} /> )} {activeTab === 0 ? ( diff --git a/helm-frontend/src/services/getDisplayPredictionsByName.ts b/helm-frontend/src/services/getDisplayPredictionsByName.ts index e8a3f558eb6..d7d74390b3c 100644 --- a/helm-frontend/src/services/getDisplayPredictionsByName.ts +++ b/helm-frontend/src/services/getDisplayPredictionsByName.ts @@ -2,6 +2,7 @@ import type DisplayPrediction from "@/types/DisplayPrediction"; import { EncryptionDataMap } from "@/types/EncryptionDataMap"; import getBenchmarkEndpoint from "@/utils/getBenchmarkEndpoint"; import getBenchmarkSuite from "@/utils/getBenchmarkSuite"; +import isScenarioEncrypted from "@/utils/isScenarioEncrypted"; async function decryptField( ciphertext: string, @@ -53,7 +54,7 @@ export default async function getDisplayPredictionsByName( ); const displayPredictions = (await response.json()) as DisplayPrediction[]; - if (runName.includes("gpqa") && userAgreed) { + if (isScenarioEncrypted(runName) && userAgreed) { const encryptionResponse = await fetch( getBenchmarkEndpoint( `/runs/${ diff --git a/helm-frontend/src/services/getDisplayRequestsByName.ts b/helm-frontend/src/services/getDisplayRequestsByName.ts index a5d3794ad26..71c0461cc15 100644 --- a/helm-frontend/src/services/getDisplayRequestsByName.ts +++ b/helm-frontend/src/services/getDisplayRequestsByName.ts @@ -2,6 +2,7 @@ import type DisplayRequest from "@/types/DisplayRequest"; import { EncryptionDataMap } from "@/types/EncryptionDataMap"; import getBenchmarkEndpoint from "@/utils/getBenchmarkEndpoint"; import getBenchmarkSuite from "@/utils/getBenchmarkSuite"; +import isScenarioEncrypted from "@/utils/isScenarioEncrypted"; // Helper function for decryption async function decryptField( @@ -54,7 +55,7 @@ export default async function getDisplayRequestsByName( ); const displayRequests = (await response.json()) as DisplayRequest[]; - if (runName.startsWith("gpqa") && userAgreed) { + if (isScenarioEncrypted(runName) && userAgreed) { const encryptionResponse = await fetch( getBenchmarkEndpoint( `/runs/${ diff --git a/helm-frontend/src/services/getInstances.ts b/helm-frontend/src/services/getInstances.ts index 45c370bd392..5b80216fa41 100644 --- a/helm-frontend/src/services/getInstances.ts +++ b/helm-frontend/src/services/getInstances.ts @@ -2,6 +2,7 @@ import Instance from "@/types/Instance"; import { EncryptionDataMap } from "@/types/EncryptionDataMap"; import getBenchmarkEndpoint from "@/utils/getBenchmarkEndpoint"; import getBenchmarkSuite from "@/utils/getBenchmarkSuite"; +import isScenarioEncrypted from "@/utils/isScenarioEncrypted"; // Helper function for decryption async function decryptField( @@ -53,7 +54,7 @@ export default async function getInstancesByRunName( ); const instances = (await response.json()) as Instance[]; - if (runName.includes("gpqa") && userAgreed) { + if (isScenarioEncrypted(runName) && userAgreed) { const encryptionResponse = await fetch( getBenchmarkEndpoint( `/runs/${ diff --git a/helm-frontend/src/utils/isScenarioEncrypted.ts b/helm-frontend/src/utils/isScenarioEncrypted.ts new file mode 100644 index 00000000000..1a1cb7f8071 --- /dev/null +++ b/helm-frontend/src/utils/isScenarioEncrypted.ts @@ -0,0 +1,3 @@ +export default function isScenarioEncrypted(runName: string): boolean { + return runName.includes("gpqa") || runName.includes("ewok"); +}