-
Notifications
You must be signed in to change notification settings - Fork 14
/
interpAPI.ts
58 lines (50 loc) · 1.64 KB
/
interpAPI.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import {Feature, FeatureInfo} from './types';
import {memoizeAsync} from "./utils"
export const load_file_no_cache = async(path: string) => {
const data = {
path: path
}
const url = new URL("/load_az", window.location.href)
url.port = '8000';
return await (
await fetch(url, {
method: "POST", // or 'PUT'
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(data),
})
).json()
}
export const load_file_az = async(path: string) => {
const res = (
await fetch(path, {
method: "GET",
mode: "cors",
headers: {
"Content-Type": "application/json",
},
})
)
if (!res.ok) {
console.error(`HTTP error: ${res.status} - ${res.statusText}`);
return;
}
return await res.json()
}
// export const load_file = memoizeAsync('load_file', load_file_no_cache)
// export const load_file = window.location.host.indexOf('localhost:') === -1 ? load_file_az : load_file_no_cache;
export const load_file = load_file_no_cache;
export async function get_feature_info(feature: Feature, ablated?: boolean): Promise<FeatureInfo> {
let load_fn = load_file_az;
let prefix = "https://openaipublic.blob.core.windows.net/sparse-autoencoder/viewer"
if (window.location.host.indexOf('localhost:') !== -1) {
load_fn = load_file;
prefix = "az:https://openaipublic/sparse-autoencoder/viewer"
// prefix = az:https://oaialignment/interp/autoencoder-vis/ae
}
const ae = feature.autoencoder;
const result = await load_fn(`${prefix}/${ae.subject}/${ae.path}/atoms/${feature.atom}${ablated ? '-ablated': ''}.json`)
// console.log('result', result)
return result
}