Update llama2.js
Browse files
llama2.js
CHANGED
@@ -1,4 +1,8 @@
|
|
1 |
|
|
|
|
|
|
|
|
|
2 |
|
3 |
// The Module object: Our interface to the outside world. We import
|
4 |
// and export values on it. There are various ways Module can be used:
|
@@ -97,14 +101,44 @@ var REMOTE_PACKAGE_SIZE = metadata['remote_package_size'];
|
|
97 |
throw new Error("NetworkError for: " + packageName);
|
98 |
}
|
99 |
xhr.onload = function(event) {
|
100 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
var packageData = xhr.response;
|
102 |
callback(packageData);
|
103 |
} else {
|
104 |
throw new Error(xhr.statusText + " : " + xhr.responseURL);
|
105 |
}
|
106 |
};
|
107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
};
|
109 |
|
110 |
function handleError(error) {
|
@@ -1235,6 +1269,7 @@ function getBinary(file) {
|
|
1235 |
}
|
1236 |
|
1237 |
function getBinaryPromise() {
|
|
|
1238 |
// If we don't have the binary yet, try to to load it asynchronously.
|
1239 |
// Fetch has some additional restrictions over XHR, like it can't be used on a file:// url.
|
1240 |
// See https://github.com/github/fetch/pull/92#issuecomment-140665932
|
@@ -5834,3 +5869,4 @@ run();
|
|
5834 |
|
5835 |
|
5836 |
|
|
|
|
1 |
|
2 |
+
var cache;
|
3 |
+
try {
|
4 |
+
cache = typeof caches !== 'undefined' ? caches.open('llama-cache') : null;
|
5 |
+
} catch (_) {}
|
6 |
|
7 |
// The Module object: Our interface to the outside world. We import
|
8 |
// and export values on it. There are various ways Module can be used:
|
|
|
101 |
throw new Error("NetworkError for: " + packageName);
|
102 |
}
|
103 |
xhr.onload = function(event) {
|
104 |
+
|
105 |
+
if(xhr.status == 200) {
|
106 |
+
if (cache) {
|
107 |
+
cache.then(async c => {
|
108 |
+
try {
|
109 |
+
await c.put(packageName, new Response(xhr.response));
|
110 |
+
} catch(_) {}
|
111 |
+
callback(xhr.response);
|
112 |
+
});
|
113 |
+
} else {
|
114 |
+
callback(xhr.response);
|
115 |
+
}
|
116 |
+
} else if (xhr.status == 304 || xhr.status == 206 || (xhr.status == 0 && xhr.response)) { // file URLs can return 0
|
117 |
var packageData = xhr.response;
|
118 |
callback(packageData);
|
119 |
} else {
|
120 |
throw new Error(xhr.statusText + " : " + xhr.responseURL);
|
121 |
}
|
122 |
};
|
123 |
+
|
124 |
+
if (cache) {
|
125 |
+
cache.then(async c => {
|
126 |
+
try {
|
127 |
+
let response = await c.match(packageName);
|
128 |
+
if (response){
|
129 |
+
callback(await response.arrayBuffer());
|
130 |
+
} else {
|
131 |
+
xhr.send(null);
|
132 |
+
}
|
133 |
+
} catch (_) {
|
134 |
+
xhr.send(null);
|
135 |
+
}
|
136 |
+
})
|
137 |
+
}else{
|
138 |
+
xhr.send(null);
|
139 |
+
}
|
140 |
+
|
141 |
+
|
142 |
};
|
143 |
|
144 |
function handleError(error) {
|
|
|
1269 |
}
|
1270 |
|
1271 |
function getBinaryPromise() {
|
1272 |
+
console.log('getBinaryPromise');
|
1273 |
// If we don't have the binary yet, try to to load it asynchronously.
|
1274 |
// Fetch has some additional restrictions over XHR, like it can't be used on a file:// url.
|
1275 |
// See https://github.com/github/fetch/pull/92#issuecomment-140665932
|
|
|
5869 |
|
5870 |
|
5871 |
|
5872 |
+
|