Просмотр исходного кода

refac/fix: automatic1111 params

Timothy Jaeryang Baek 3 месяцев назад
Родитель
Сommit
9370b263f5
2 измененных файлов с 16 добавлено и 12 удалено
  1. 1 2
      backend/open_webui/config.py
  2. 15 10
      backend/open_webui/routers/images.py

+ 1 - 2
backend/open_webui/config.py

@@ -3184,10 +3184,9 @@ try:
 except json.JSONDecodeError:
     automatic1111_params = {}
 
-
 AUTOMATIC1111_PARAMS = PersistentConfig(
     "AUTOMATIC1111_PARAMS",
-    "image_generation.automatic1111.api_auth",
+    "image_generation.automatic1111.api_params",
     automatic1111_params,
 )
 

+ 15 - 10
backend/open_webui/routers/images.py

@@ -44,18 +44,23 @@ def set_image_model(request: Request, model: str):
     request.app.state.config.IMAGE_GENERATION_MODEL = model
     if request.app.state.config.IMAGE_GENERATION_ENGINE in ["", "automatic1111"]:
         api_auth = get_automatic1111_api_auth(request)
-        r = requests.get(
-            url=f"{request.app.state.config.AUTOMATIC1111_BASE_URL}/sdapi/v1/options",
-            headers={"authorization": api_auth},
-        )
-        options = r.json()
-        if model != options["sd_model_checkpoint"]:
-            options["sd_model_checkpoint"] = model
-            r = requests.post(
+
+        try:
+            r = requests.get(
                 url=f"{request.app.state.config.AUTOMATIC1111_BASE_URL}/sdapi/v1/options",
-                json=options,
                 headers={"authorization": api_auth},
             )
+            options = r.json()
+            if model != options["sd_model_checkpoint"]:
+                options["sd_model_checkpoint"] = model
+                r = requests.post(
+                    url=f"{request.app.state.config.AUTOMATIC1111_BASE_URL}/sdapi/v1/options",
+                    json=options,
+                    headers={"authorization": api_auth},
+                )
+        except Exception as e:
+            log.debug(f"{e}")
+
     return request.app.state.config.IMAGE_GENERATION_MODEL
 
 
@@ -108,7 +113,7 @@ class ImagesConfig(BaseModel):
     IMAGES_OPENAI_API_VERSION: str
 
     AUTOMATIC1111_BASE_URL: str
-    AUTOMATIC1111_API_AUTH: str
+    AUTOMATIC1111_API_AUTH: Optional[dict | str]
     AUTOMATIC1111_PARAMS: Optional[dict | str]
 
     COMFYUI_BASE_URL: str