Skip to content

Commit

Permalink
Switch from alert to confirm to allow the user to not download
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjaycal committed Jan 16, 2025
1 parent c8400b0 commit ee0e255
Showing 1 changed file with 41 additions and 25 deletions.
66 changes: 41 additions & 25 deletions src/renderer/components/Experiment/Train/ImportRecipeModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,35 +109,51 @@ export default function ImportRecipeModal({ open, setOpen, mutate }) {
} else if (!response.dataset || ! response.dataset.path) {
alert("Warning: This recipe does not have an associated dataset")
} else {
let msg = "";
let msg = "Warning: To use this recipe you will need to download the following:";
let shouldDownload = false;

if (!response.dataset.downloaded) {
msg += "\n Download dataset " + response.dataset.path + ", this will be done automatically";
fetch(chatAPI.Endpoints.Dataset.Download(response.dataset.path))
.then((response) => {
if (!response.ok) {
console.log(response);
throw new Error(`HTTP Status: ${response.status}`);
}
return response.json();
})
.catch((error) => {
alert('Download failed:\n' + error);
});
msg += "\n- Dataset: " + response.dataset.path;
shouldDownload = true;
}
if (!response.model.downloaded) {
msg += "\n Download model " + response.model.path + ", this will be done automatically";
chatAPI.downloadModelFromHuggingFace(response.model.path)
.then((response) => {
if (response.status == "error") {
console.log(response);
throw new Error(`${response.message}`);
}
return response;
})
msg += "\n- Model: " + response.model.path;
shouldDownload = true;
}
if (msg) {
const alert_msg = "Warning: To use this recipe you will need to: " + msg
alert(alert_msg);

if (shouldDownload) {
msg += "\n\nDo you want to download these now?";
if (confirm(msg)) { // Use confirm() to get Accept/Cancel
if (!response.dataset.downloaded) {
fetch(chatAPI.Endpoints.Dataset.Download(response.dataset.path))
.then((response) => {
if (!response.ok) {
console.log(response);
throw new Error(`HTTP Status: ${response.status}`);
}
return response.json();
})
.catch((error) => {
alert('Dataset download failed:\n' + error);
});
}
if (!response.model.downloaded) {
chatAPI.downloadModelFromHuggingFace(response.model.path)
.then((response) => {
if (response.status == "error") {
console.log(response);
throw new Error(`${response.message}`);
}
return response;
})
.catch((error) => {
alert('Model download failed:\n' + error);
});
}
} else {
// User pressed Cancel
alert("Downloads cancelled. This recipe might not work correctly.");
}
}
}
}
Expand Down

0 comments on commit ee0e255

Please sign in to comment.