Skip to content

Commit

Permalink
Merge pull request #34 from ibelem/latest-dev-ort
Browse files Browse the repository at this point in the history
Support latest ORT Web dists via URL parameter
  • Loading branch information
fdwr authored Aug 21, 2024
2 parents 721dd67 + 90906b8 commit c49c5e6
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions assets/js/common_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,36 @@ const KNOWN_COMPATIBLE_ORT_VERSION = {

const ORT_BASE_URL = 'https://www.npmjs.com/package/onnxruntime-web/v/';
const ORT_CDN_URL = 'https://cdn.jsdelivr.net/npm/onnxruntime-web@';
const ORT_CDN_DATA_URL = 'https://data.jsdelivr.com/v1/packages/npm/onnxruntime-web';
const ortLink = (version) => `${ORT_BASE_URL}${version}?activeTab=versions`;

// Get the latest dev version of ONNX Runtime Web dists
const getLatestOrtWebDevVersion = async () => {
try {
const response = await fetch(ORT_CDN_DATA_URL);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
if (data.tags && data.tags.dev) {
return data.tags.dev;
} else {
console.error("Latest dev version of ONNX Runtime Web not found in the response");
}
} catch (error) {
console.error('Error:', error.message);
}
};

const loadScriptWithMessage = async (version) => {
try {
if (version === 'test') {
await loadScript('onnxruntime-web', '../../assets/dist/ort.all.min.js');
return 'ONNX Runtime Web: Test version';
} else {
if (version === 'latest') {
version = await getLatestOrtWebDevVersion();
}
await loadScript('onnxruntime-web', `${ORT_CDN_URL}${version}/dist/ort.all.min.js`);
return `ONNX Runtime Web: <a href="${ortLink(version)}">${version}</a>`;
}
Expand Down

0 comments on commit c49c5e6

Please sign in to comment.