refac: settings

This commit is contained in:
Timothy J. Baek 2024-02-21 19:06:27 -08:00
parent 797ed9ac7f
commit dc705c4984
2 changed files with 36 additions and 18 deletions

View file

@ -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
app.state.AUTOMATIC1111_BASE_URL = form_data.url.strip("/") else:
return { app.state.AUTOMATIC1111_BASE_URL = form_data.url.strip("/")
"AUTOMATIC1111_BASE_URL": app.state.AUTOMATIC1111_BASE_URL,
"status": True, return {
} "AUTOMATIC1111_BASE_URL": app.state.AUTOMATIC1111_BASE_URL,
except Exception as e: "status": True,
raise HTTPException(status_code=r.status_code, detail=ERROR_MESSAGES.DEFAULT(e)) }
@app.get("/models") @app.get("/models")

View file

@ -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(
config.set(await getBackendConfig(localStorage.token)); (error) => {
toast.error(error);
return false;
}
);
if (enableImageGeneration) {
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);
} }
} }
}); });