Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
liamjxu committed Dec 18, 2024
1 parent b96b3a9 commit e6c599d
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 30 deletions.
7 changes: 6 additions & 1 deletion helm-frontend/src/components/Instances.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ interface Props {
userAgreed: boolean;
}

export default function Instances({ runName, suite, metricFieldMap, userAgreed }: Props) {
export default function Instances({
runName,
suite,
metricFieldMap,
userAgreed,
}: Props) {
const [searchParams, setSearchParams] = useSearchParams();
const [instances, setInstances] = useState<Instance[]>([]);
const [displayPredictionsMap, setDisplayPredictionsMap] = useState<
Expand Down
14 changes: 9 additions & 5 deletions helm-frontend/src/routes/Run.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -192,18 +192,22 @@ export default function Run() {
</Tabs>
</div>

{activeTab === 0 && runName.includes('gpqa') && !userAgreed && (
{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:
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.”
“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>.
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
Expand Down
26 changes: 18 additions & 8 deletions helm-frontend/src/services/getDisplayPredictionsByName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,21 @@ import getBenchmarkEndpoint from "@/utils/getBenchmarkEndpoint";
import getBenchmarkSuite from "@/utils/getBenchmarkSuite";

// Helper function for decryption
async function decryptField(ciphertext: string, key: string, iv: string, tag: string): Promise<string> {
async function decryptField(
ciphertext: string,
key: string,
iv: string,
tag: string,
): Promise<string> {
const decodeBase64 = (str: string) =>
Uint8Array.from(atob(str), c => c.charCodeAt(0));
Uint8Array.from(atob(str), (c) => c.charCodeAt(0));

const cryptoKey = await window.crypto.subtle.importKey(
"raw",
decodeBase64(key),
"AES-GCM",
true,
["decrypt"]
["decrypt"],
);

const combinedCiphertext = new Uint8Array([
Expand All @@ -25,7 +30,7 @@ async function decryptField(ciphertext: string, key: string, iv: string, tag: st
const decrypted = await window.crypto.subtle.decrypt(
{ name: "AES-GCM", iv: ivArray },
cryptoKey,
combinedCiphertext
combinedCiphertext,
);

return new TextDecoder().decode(decrypted);
Expand All @@ -47,11 +52,13 @@ export default async function getDisplayPredictionsByName(
{ signal },
);
const displayPredictions = (await response.json()) as DisplayPrediction[];

if (runName.includes("gpqa") && userAgreed) {
const encryptionResponse = await fetch(
getBenchmarkEndpoint(
`/runs/${suite || getBenchmarkSuite()}/${runName}/encryption_data.json`,
`/runs/${
suite || getBenchmarkSuite()
}/${runName}/encryption_data.json`,
),
{ signal },
);
Expand All @@ -67,10 +74,13 @@ export default async function getDisplayPredictionsByName(
encryptionDetails.ciphertext,

Check failure on line 74 in helm-frontend/src/services/getDisplayPredictionsByName.ts

View workflow job for this annotation

GitHub Actions / test

Unsafe argument of type `any` assigned to a parameter of type `string`

Check failure on line 74 in helm-frontend/src/services/getDisplayPredictionsByName.ts

View workflow job for this annotation

GitHub Actions / test

Unsafe member access .ciphertext on an `any` value
encryptionDetails.key,

Check failure on line 75 in helm-frontend/src/services/getDisplayPredictionsByName.ts

View workflow job for this annotation

GitHub Actions / test

Unsafe argument of type `any` assigned to a parameter of type `string`

Check failure on line 75 in helm-frontend/src/services/getDisplayPredictionsByName.ts

View workflow job for this annotation

GitHub Actions / test

Unsafe member access .key on an `any` value
encryptionDetails.iv,

Check failure on line 76 in helm-frontend/src/services/getDisplayPredictionsByName.ts

View workflow job for this annotation

GitHub Actions / test

Unsafe argument of type `any` assigned to a parameter of type `string`

Check failure on line 76 in helm-frontend/src/services/getDisplayPredictionsByName.ts

View workflow job for this annotation

GitHub Actions / test

Unsafe member access .iv on an `any` value
encryptionDetails.tag
encryptionDetails.tag,

Check failure on line 77 in helm-frontend/src/services/getDisplayPredictionsByName.ts

View workflow job for this annotation

GitHub Actions / test

Unsafe argument of type `any` assigned to a parameter of type `string`
);
} catch (error) {
console.error(`Failed to decrypt predicted_text for instance_id: ${prediction.instance_id}`, error);
console.error(
`Failed to decrypt predicted_text for instance_id: ${prediction.instance_id}`,
error,
);
}
}
}
Expand Down
25 changes: 17 additions & 8 deletions helm-frontend/src/services/getDisplayRequestsByName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,21 @@ import getBenchmarkEndpoint from "@/utils/getBenchmarkEndpoint";
import getBenchmarkSuite from "@/utils/getBenchmarkSuite";

// Helper function for decryption
async function decryptField(ciphertext: string, key: string, iv: string, tag: string): Promise<string> {
async function decryptField(
ciphertext: string,
key: string,
iv: string,
tag: string,
): Promise<string> {
const decodeBase64 = (str: string) =>
Uint8Array.from(atob(str), c => c.charCodeAt(0));
Uint8Array.from(atob(str), (c) => c.charCodeAt(0));

const cryptoKey = await window.crypto.subtle.importKey(
"raw",
decodeBase64(key),
"AES-GCM",
true,
["decrypt"]
["decrypt"],
);

const combinedCiphertext = new Uint8Array([
Expand All @@ -25,7 +30,7 @@ async function decryptField(ciphertext: string, key: string, iv: string, tag: st
const decrypted = await window.crypto.subtle.decrypt(
{ name: "AES-GCM", iv: ivArray },
cryptoKey,
combinedCiphertext
combinedCiphertext,
);

return new TextDecoder().decode(decrypted);
Expand All @@ -49,10 +54,11 @@ export default async function getDisplayRequestsByName(
const displayRequests = (await response.json()) as DisplayRequest[];

if (runName.startsWith("gpqa") && userAgreed) {

const encryptionResponse = await fetch(
getBenchmarkEndpoint(
`/runs/${suite || getBenchmarkSuite()}/${runName}/encryption_data.json`,
`/runs/${
suite || getBenchmarkSuite()
}/${runName}/encryption_data.json`,
),
{ signal },
);
Expand All @@ -68,10 +74,13 @@ export default async function getDisplayRequestsByName(
encryptionDetails.ciphertext,
encryptionDetails.key,
encryptionDetails.iv,
encryptionDetails.tag
encryptionDetails.tag,
);
} catch (error) {
console.error(`Failed to decrypt prompt for instance_id: ${request.instance_id}`, error);
console.error(
`Failed to decrypt prompt for instance_id: ${request.instance_id}`,
error,
);
}
}
}
Expand Down
23 changes: 15 additions & 8 deletions helm-frontend/src/services/getInstances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@ import getBenchmarkEndpoint from "@/utils/getBenchmarkEndpoint";
import getBenchmarkSuite from "@/utils/getBenchmarkSuite";

// Helper function for decryption
async function decryptField(ciphertext: string, key: string, iv: string, tag: string): Promise<string> {
async function decryptField(
ciphertext: string,
key: string,
iv: string,
tag: string,
): Promise<string> {
// Convert Base64 strings to Uint8Array
const decodeBase64 = (str: string) =>
Uint8Array.from(atob(str), c => c.charCodeAt(0));
Uint8Array.from(atob(str), (c) => c.charCodeAt(0));

const cryptoKey = await window.crypto.subtle.importKey(
"raw",
decodeBase64(key),
"AES-GCM",
true,
["decrypt"]
["decrypt"],
);

const combinedCiphertext = new Uint8Array([
Expand All @@ -26,7 +31,7 @@ async function decryptField(ciphertext: string, key: string, iv: string, tag: st
const decrypted = await window.crypto.subtle.decrypt(
{ name: "AES-GCM", iv: ivArray },
cryptoKey,
combinedCiphertext
combinedCiphertext,
);

return new TextDecoder().decode(decrypted);
Expand All @@ -50,7 +55,9 @@ export default async function getInstancesByRunName(
if (runName.includes("gpqa") && userAgreed) {
const encryptionResponse = await fetch(
getBenchmarkEndpoint(
`/runs/${suite || getBenchmarkSuite()}/${runName}/encryption_data.json`,
`/runs/${
suite || getBenchmarkSuite()
}/${runName}/encryption_data.json`,
),
{ signal },
);
Expand All @@ -64,18 +71,18 @@ export default async function getInstancesByRunName(
inputEncryption.ciphertext,
inputEncryption.key,
inputEncryption.iv,
inputEncryption.tag
inputEncryption.tag,
);
}

for (const reference of instance.references) {
const referenceEncryption = encryptionData[reference.output.text];
if (referenceEncryption) {
reference.output.text = await decryptField(
referenceEncryption.ciphertext,
referenceEncryption.key,
referenceEncryption.iv,
referenceEncryption.tag
referenceEncryption.tag,
);
}
}
Expand Down

0 comments on commit e6c599d

Please sign in to comment.