mirror of
https://github.com/open-webui/extension
synced 2025-06-26 18:25:58 +00:00
feat: 0.2.0 support
This commit is contained in:
parent
24ed32f7f2
commit
635b90c685
8
extension/dist/main.js
vendored
8
extension/dist/main.js
vendored
File diff suppressed because one or more lines are too long
@ -1,12 +1,12 @@
|
|||||||
export const getOpenAIModels = async (token = "", url = "") => {
|
export const getModels = async (key, url) => {
|
||||||
let error = null;
|
let error = null;
|
||||||
|
|
||||||
const res = await fetch(`${url}/models`, {
|
const res = await fetch(`${url}/api/models`, {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
Accept: "application/json",
|
Accept: "application/json",
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
...(token && { authorization: `Bearer ${token}` }),
|
...(key && { authorization: `Bearer ${key}` }),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then(async (res) => {
|
.then(async (res) => {
|
||||||
@ -14,48 +14,36 @@ export const getOpenAIModels = async (token = "", url = "") => {
|
|||||||
return res.json();
|
return res.json();
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
error = `OpenAI: ${err?.error?.message ?? "Network Problem"}`;
|
console.log(err);
|
||||||
return [];
|
error = err;
|
||||||
|
return null;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
const models = Array.isArray(res) ? res : res?.data ?? null;
|
let models = res?.data ?? [];
|
||||||
|
|
||||||
return models
|
|
||||||
? models
|
|
||||||
.map((model) => ({
|
|
||||||
id: model.id,
|
|
||||||
name: model.name ?? model.id,
|
|
||||||
url: url,
|
|
||||||
custom_info: model.custom_info,
|
|
||||||
}))
|
|
||||||
.sort((a, b) => {
|
|
||||||
return a.name.localeCompare(b.name);
|
|
||||||
})
|
|
||||||
: models;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getModels = async (key, url) => {
|
|
||||||
let models = await Promise.all([
|
|
||||||
getOpenAIModels(key, `${url}/ollama/v1`).catch((error) => {
|
|
||||||
console.log(error);
|
|
||||||
return null;
|
|
||||||
}),
|
|
||||||
getOpenAIModels(key, `${url}/openai/api`).catch((error) => {
|
|
||||||
console.log(error);
|
|
||||||
return null;
|
|
||||||
}),
|
|
||||||
]);
|
|
||||||
|
|
||||||
models = models
|
models = models
|
||||||
.filter((models) => models)
|
.filter((models) => models)
|
||||||
.reduce((a, e, i, arr) => a.concat(e), []);
|
.sort((a, b) => {
|
||||||
|
// Compare case-insensitively
|
||||||
|
const lowerA = a.name.toLowerCase();
|
||||||
|
const lowerB = b.name.toLowerCase();
|
||||||
|
|
||||||
|
if (lowerA < lowerB) return -1;
|
||||||
|
if (lowerA > lowerB) return 1;
|
||||||
|
|
||||||
|
// If same case-insensitively, sort by original strings,
|
||||||
|
// lowercase will come before uppercase due to ASCII values
|
||||||
|
if (a < b) return -1;
|
||||||
|
if (a > b) return 1;
|
||||||
|
|
||||||
|
return 0; // They are equal
|
||||||
|
});
|
||||||
|
|
||||||
console.log(models);
|
console.log(models);
|
||||||
|
|
||||||
return models;
|
return models;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
url = "";
|
url = "";
|
||||||
key = "";
|
key = "";
|
||||||
model = "";
|
model = "";
|
||||||
|
models = [];
|
||||||
showConfig = true;
|
showConfig = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -80,10 +81,18 @@
|
|||||||
key = _storageCache.key ?? "";
|
key = _storageCache.key ?? "";
|
||||||
model = _storageCache.model ?? "";
|
model = _storageCache.model ?? "";
|
||||||
if (_storageCache.url && _storageCache.key && _storageCache.model) {
|
if (_storageCache.url && _storageCache.key && _storageCache.model) {
|
||||||
models = await getModels(_storageCache.key, _storageCache.url);
|
models = await getModels(_storageCache.key, _storageCache.url).catch(
|
||||||
|
(error) => {
|
||||||
|
console.log(error);
|
||||||
|
resetConfig();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
if (models) {
|
||||||
showConfig = false;
|
showConfig = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const down = async (e) => {
|
const down = async (e) => {
|
||||||
// Reset the configuration when ⌘Shift+Escape is pressed
|
// Reset the configuration when ⌘Shift+Escape is pressed
|
||||||
@ -161,7 +170,11 @@
|
|||||||
],
|
],
|
||||||
stream: true,
|
stream: true,
|
||||||
},
|
},
|
||||||
models.find((m) => m.id === model)?.url
|
|
||||||
|
models.find((m) => m.id === model)?.owned_by === "openai" ??
|
||||||
|
false
|
||||||
|
? `${url}/openai`
|
||||||
|
: `${url}/ollama/v1`
|
||||||
);
|
);
|
||||||
|
|
||||||
if (res && res.ok) {
|
if (res && res.ok) {
|
||||||
|
Loading…
Reference in New Issue
Block a user