mirror of
https://github.com/open-webui/open-webui.git
synced 2026-12-03 18:17:56 -05:00
refac
This commit is contained in:
1 parent
f20f00056f
commit
affe67b7df
6 files changed
+161
-125
No files matched your search
@@ -73,6 +73,7 @@
|
||||
|
||||
const updateModelsHandler = async () => {
|
||||
updateCancelled = false;
|
||||
let failed = false;
|
||||
toast.info('Checking for model updates...');
|
||||
|
||||
for (const model of ollamaModels) {
|
||||
@@ -80,66 +81,39 @@
|
||||
break;
|
||||
}
|
||||
|
||||
console.debug(model);
|
||||
|
||||
updateModelId = model.id;
|
||||
const [res, controller] = await pullModel(localStorage.token, model.id, urlIdx).catch(
|
||||
(error) => {
|
||||
if (error.name !== 'AbortError') {
|
||||
toast.error(`${error}`);
|
||||
}
|
||||
return [null, null];
|
||||
}
|
||||
);
|
||||
try {
|
||||
const [res, controller] = await pullModel(localStorage.token, model.id, urlIdx);
|
||||
updateModelsControllers = { ...updateModelsControllers, [model.id]: controller };
|
||||
|
||||
updateModelsControllers = {
|
||||
...updateModelsControllers,
|
||||
[model.id]: controller
|
||||
};
|
||||
|
||||
if (res) {
|
||||
const reader = res.body
|
||||
.pipeThrough(new TextDecoderStream())
|
||||
.pipeThrough(splitStream('\n'))
|
||||
.getReader();
|
||||
|
||||
while (true) {
|
||||
try {
|
||||
const { value, done } = await reader.read();
|
||||
if (done) break;
|
||||
const { value, done } = await reader.read();
|
||||
if (done) break;
|
||||
|
||||
let lines = value.split('\n');
|
||||
for (const line of value.split('\n')) {
|
||||
if (line === '') continue;
|
||||
|
||||
for (const line of lines) {
|
||||
if (line !== '') {
|
||||
let data = JSON.parse(line);
|
||||
|
||||
console.log(data);
|
||||
if (data.error) {
|
||||
throw data.error;
|
||||
}
|
||||
if (data.detail) {
|
||||
throw data.detail;
|
||||
}
|
||||
if (data.status) {
|
||||
if (data.digest) {
|
||||
updateProgress = 0;
|
||||
if (data.completed) {
|
||||
updateProgress = Math.round((data.completed / data.total) * 1000) / 10;
|
||||
} else {
|
||||
updateProgress = 100;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const data = JSON.parse(line);
|
||||
if (data.error || data.detail) {
|
||||
throw data.error ?? data.detail;
|
||||
}
|
||||
} catch (err) {
|
||||
if (err.name !== 'AbortError') {
|
||||
console.error(err);
|
||||
if (data.status && data.digest) {
|
||||
updateProgress = data.completed
|
||||
? Math.round((data.completed / data.total) * 1000) / 10
|
||||
: 100;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
if (err.name !== 'AbortError') {
|
||||
failed = true;
|
||||
toast.error(`${model.id}: ${err}`);
|
||||
}
|
||||
}
|
||||
|
||||
delete updateModelsControllers[model.id];
|
||||
@@ -148,7 +122,7 @@
|
||||
|
||||
if (updateCancelled) {
|
||||
toast.info('Model update cancelled');
|
||||
} else {
|
||||
} else if (!failed) {
|
||||
toast.success('All models are up to date');
|
||||
}
|
||||
updateModelId = null;
|
||||
|
||||
Reference in new issue
Block a user