forked from open-webui/open-webui
refac: settings
This commit is contained in:
parent
797ed9ac7f
commit
dc705c4984
2 changed files with 36 additions and 18 deletions
|
@ -62,16 +62,16 @@ async def get_openai_url(user=Depends(get_admin_user)):
|
||||||
|
|
||||||
@app.post("/url/update")
|
@app.post("/url/update")
|
||||||
async def update_openai_url(form_data: UrlUpdateForm, user=Depends(get_admin_user)):
|
async def update_openai_url(form_data: UrlUpdateForm, user=Depends(get_admin_user)):
|
||||||
try:
|
|
||||||
r = requests.head(form_data.url)
|
if form_data.url == "":
|
||||||
if r.ok:
|
app.state.AUTOMATIC1111_BASE_URL = AUTOMATIC1111_BASE_URL
|
||||||
|
else:
|
||||||
app.state.AUTOMATIC1111_BASE_URL = form_data.url.strip("/")
|
app.state.AUTOMATIC1111_BASE_URL = form_data.url.strip("/")
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"AUTOMATIC1111_BASE_URL": app.state.AUTOMATIC1111_BASE_URL,
|
"AUTOMATIC1111_BASE_URL": app.state.AUTOMATIC1111_BASE_URL,
|
||||||
"status": True,
|
"status": True,
|
||||||
}
|
}
|
||||||
except Exception as e:
|
|
||||||
raise HTTPException(status_code=r.status_code, detail=ERROR_MESSAGES.DEFAULT(e))
|
|
||||||
|
|
||||||
|
|
||||||
@app.get("/models")
|
@app.get("/models")
|
||||||
|
|
|
@ -25,6 +25,14 @@
|
||||||
let selectedModel = '';
|
let selectedModel = '';
|
||||||
let models = [];
|
let models = [];
|
||||||
|
|
||||||
|
const getModels = async () => {
|
||||||
|
models = await getDiffusionModels(localStorage.token).catch((error) => {
|
||||||
|
toast.error(error);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
selectedModel = await getDefaultDiffusionModel(localStorage.token);
|
||||||
|
};
|
||||||
|
|
||||||
const updateAUTOMATIC1111UrlHandler = async () => {
|
const updateAUTOMATIC1111UrlHandler = async () => {
|
||||||
const res = await updateAUTOMATIC1111Url(localStorage.token, AUTOMATIC1111_BASE_URL).catch(
|
const res = await updateAUTOMATIC1111Url(localStorage.token, AUTOMATIC1111_BASE_URL).catch(
|
||||||
(error) => {
|
(error) => {
|
||||||
|
@ -34,11 +42,13 @@
|
||||||
);
|
);
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
toast.success('Server connection verified');
|
|
||||||
AUTOMATIC1111_BASE_URL = res;
|
AUTOMATIC1111_BASE_URL = res;
|
||||||
|
|
||||||
models = await getDiffusionModels(localStorage.token);
|
await getModels();
|
||||||
selectedModel = await getDefaultDiffusionModel(localStorage.token);
|
|
||||||
|
if (models) {
|
||||||
|
toast.success('Server connection verified');
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
AUTOMATIC1111_BASE_URL = await getAUTOMATIC1111Url(localStorage.token);
|
AUTOMATIC1111_BASE_URL = await getAUTOMATIC1111Url(localStorage.token);
|
||||||
}
|
}
|
||||||
|
@ -46,8 +56,17 @@
|
||||||
|
|
||||||
const toggleImageGeneration = async () => {
|
const toggleImageGeneration = async () => {
|
||||||
if (AUTOMATIC1111_BASE_URL) {
|
if (AUTOMATIC1111_BASE_URL) {
|
||||||
enableImageGeneration = await toggleImageGenerationEnabledStatus(localStorage.token);
|
enableImageGeneration = await toggleImageGenerationEnabledStatus(localStorage.token).catch(
|
||||||
|
(error) => {
|
||||||
|
toast.error(error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
if (enableImageGeneration) {
|
||||||
config.set(await getBackendConfig(localStorage.token));
|
config.set(await getBackendConfig(localStorage.token));
|
||||||
|
getModels();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
enableImageGeneration = false;
|
enableImageGeneration = false;
|
||||||
toast.error('AUTOMATIC1111_BASE_URL not provided');
|
toast.error('AUTOMATIC1111_BASE_URL not provided');
|
||||||
|
@ -59,9 +78,8 @@
|
||||||
enableImageGeneration = await getImageGenerationEnabledStatus(localStorage.token);
|
enableImageGeneration = await getImageGenerationEnabledStatus(localStorage.token);
|
||||||
AUTOMATIC1111_BASE_URL = await getAUTOMATIC1111Url(localStorage.token);
|
AUTOMATIC1111_BASE_URL = await getAUTOMATIC1111Url(localStorage.token);
|
||||||
|
|
||||||
if (AUTOMATIC1111_BASE_URL) {
|
if (enableImageGeneration && AUTOMATIC1111_BASE_URL) {
|
||||||
models = await getDiffusionModels(localStorage.token);
|
getModels();
|
||||||
selectedModel = await getDefaultDiffusionModel(localStorage.token);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue