mirror of
https://github.com/ONLYOFFICE/onlyoffice.github.io.git
synced 2026-04-07 14:04:30 +08:00
Merge pull request #33 from ONLYOFFICE-PLUGINS/feature/AI-fix-request-models
[ai] check provider on fetch to skip wrong models list
This commit is contained in:
@ -220,7 +220,7 @@ window.Asc.plugin.init = function() {
|
|||||||
window.Asc.plugin.attachEvent("onProvidersUpdate", onProvidersUpdate);
|
window.Asc.plugin.attachEvent("onProvidersUpdate", onProvidersUpdate);
|
||||||
window.Asc.plugin.attachEvent("onGetModels", function(data) {
|
window.Asc.plugin.attachEvent("onGetModels", function(data) {
|
||||||
if(data.error == 1) {
|
if(data.error == 1) {
|
||||||
rejectModels && rejectModels(data.message);
|
rejectModels && rejectModels(data);
|
||||||
} else {
|
} else {
|
||||||
modelsList = data.models;
|
modelsList = data.models;
|
||||||
let res = data.models.map(function(model) {
|
let res = data.models.map(function(model) {
|
||||||
@ -230,7 +230,9 @@ window.Asc.plugin.init = function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
res.sort(function(a,b){ return (a.name < b.name) ? -1 : ((a.name === b.name) ? 0 : 1); });
|
res.sort(function(a,b){ return (a.name < b.name) ? -1 : ((a.name === b.name) ? 0 : 1); });
|
||||||
resolveModels && resolveModels(res);
|
|
||||||
|
data.models = res;
|
||||||
|
resolveModels && resolveModels(data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -529,13 +531,17 @@ function updateModelsList() {
|
|||||||
url : providerUrlInputEl.value,
|
url : providerUrlInputEl.value,
|
||||||
key: providerKeyInputEl.value
|
key: providerKeyInputEl.value
|
||||||
}).then(function(data) {
|
}).then(function(data) {
|
||||||
providerModelsList = data;
|
if (providerNameCmbEl.value == data.provider) {
|
||||||
updateHtmlElements();
|
providerModelsList = data.models;
|
||||||
endLoader();
|
updateHtmlElements();
|
||||||
|
endLoader();
|
||||||
|
}
|
||||||
}).catch(function(error) {
|
}).catch(function(error) {
|
||||||
providerModelsList = [];
|
if (providerNameCmbEl.value == error.provider) {
|
||||||
updateHtmlElements();
|
providerModelsList = [];
|
||||||
endLoader(error);
|
updateHtmlElements();
|
||||||
|
endLoader(error.message);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -557,6 +557,7 @@ function fetchExternal(url, options, isStreaming) {
|
|||||||
function resolveRequest(data) {
|
function resolveRequest(data) {
|
||||||
if (data.error)
|
if (data.error)
|
||||||
resolve({
|
resolve({
|
||||||
|
provider: provider.name,
|
||||||
error : 1,
|
error : 1,
|
||||||
message : data.message,
|
message : data.message,
|
||||||
models : []
|
models : []
|
||||||
@ -587,6 +588,7 @@ function fetchExternal(url, options, isStreaming) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
resolve({
|
resolve({
|
||||||
|
provider: provider.name,
|
||||||
error : 0,
|
error : 0,
|
||||||
message : "",
|
message : "",
|
||||||
models : AI.TmpProviderForModels.modelsUI
|
models : AI.TmpProviderForModels.modelsUI
|
||||||
|
|||||||
Reference in New Issue
Block a user