Skip to content

Commit

Permalink
Refactor agreement frontend (#3258)
Browse files Browse the repository at this point in the history
  • Loading branch information
yifanmai authored Jan 9, 2025
1 parent 31c3d8e commit 40675ca
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 45 deletions.
82 changes: 82 additions & 0 deletions helm-frontend/src/components/UserAgreement.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { useRef } from "react";

interface Props {
runName: string;
onAgree: () => void;
}

export default function Tab({ runName, onAgree }: Props) {
const inputRef = useRef<HTMLInputElement>(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") ? (
<GPQATerms />
) : runName.includes("ewok") ? (
<EWoKTerms />
) : null;

return (
<div className="mb-8">
{agreement}
<p className="mb-4">
If you agree to this condition, please type{" "}
<strong>"Yes, I agree"</strong> in the box below and then click{" "}
<strong>Decrypt</strong>.
</p>
<div className="flex gap-2 mt-2">
<input
type="text"
ref={inputRef}
className="input input-bordered"
placeholder='Type "Yes, I agree"'
/>
<button onClick={handleAgreement} className="btn btn-primary">
Decrypt
</button>
</div>
<hr className="my-4" />
</div>
);
}

function GPQATerms() {
return (
<div>
<p className="mb-4">
The GPQA dataset instances are encrypted by default to comply with the
following request:
</p>
<blockquote className="italic border-l-4 border-gray-300 pl-4 text-gray-700 mb-4">
“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.”
</blockquote>
</div>
);
}

function EWoKTerms() {
return (
<div>
<p className="mb-4">
The EWoK dataset instances are encrypted by default to comply with the
following request:
</p>
<blockquote className="italic border-l-4 border-gray-300 pl-4 text-gray-700 mb-4">
“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.”
</blockquote>
</div>
);
}
46 changes: 4 additions & 42 deletions helm-frontend/src/routes/Run.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -37,7 +39,6 @@ export default function Run() {
MetricFieldMap | undefined
>({});

const [agreeInput, setAgreeInput] = useState("");
const [userAgreed, setUserAgreed] = useState(false);

useEffect(() => {
Expand Down Expand Up @@ -96,16 +97,6 @@ export default function Run() {
return <Loading />;
}

// Handler for agreement
const handleAgreement = () => {
if (agreeInput.trim() === "Yes, I agree") {
setUserAgreed(true);
} else {
setUserAgreed(false);
alert("Please type 'Yes, I agree' exactly.");
}
};

return (
<>
<div className="flex justify-between gap-8 mb-12">
Expand Down Expand Up @@ -192,37 +183,8 @@ export default function Run() {
</Tabs>
</div>

{activeTab === 0 && runName.includes("gpqa") && !userAgreed && (
<div className="mb-8">
<hr className="my-4" />
<p className="mb-4">
The GPQA dataset instances are encrypted by default to comply with
the following request:
</p>
<blockquote className="italic border-l-4 border-gray-300 pl-4 text-gray-700 mb-4">
“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.”
</blockquote>
<p className="mb-4">
If you agree to this condition, please type{" "}
<strong>"Yes, I agree"</strong> in the box below and then click{" "}
<strong>Decrypt</strong>.
</p>
<div className="flex gap-2 mt-2">
<input
type="text"
value={agreeInput}
onChange={(e) => setAgreeInput(e.target.value)}
className="input input-bordered"
placeholder='Type "Yes, I agree"'
/>
<button onClick={handleAgreement} className="btn btn-primary">
Decrypt
</button>
</div>
<hr className="my-4" />
</div>
{activeTab === 0 && isScenarioEncrypted(runName) && !userAgreed && (
<UserAgreement runName={runName} onAgree={() => setUserAgreed(true)} />
)}

{activeTab === 0 ? (
Expand Down
3 changes: 2 additions & 1 deletion helm-frontend/src/services/getDisplayPredictionsByName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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/${
Expand Down
3 changes: 2 additions & 1 deletion helm-frontend/src/services/getDisplayRequestsByName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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/${
Expand Down
3 changes: 2 additions & 1 deletion helm-frontend/src/services/getInstances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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/${
Expand Down
3 changes: 3 additions & 0 deletions helm-frontend/src/utils/isScenarioEncrypted.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function isScenarioEncrypted(runName: string): boolean {
return runName.includes("gpqa") || runName.includes("ewok");
}

0 comments on commit 40675ca

Please sign in to comment.