From 71213430ff45c33b65018c684ca13dca3e4d2ee3 Mon Sep 17 00:00:00 2001 From: Ink <55043165+swpfY@users.noreply.github.com> Date: Mon, 23 Dec 2024 21:47:33 +0800 Subject: [PATCH] fix: temporary domain (#756) add temporary domain --- swanlab/env.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/swanlab/env.py b/swanlab/env.py index 0472c293..13cfccbb 100644 --- a/swanlab/env.py +++ b/swanlab/env.py @@ -13,6 +13,19 @@ import swankit.env as E from swankit.env import SwanLabSharedEnv +import requests + + +DOMAIN = 'swanlab.cn' +DOMAIN1 = 'swanlab.115.zone' # temporary domain + +# domain state detection +try: + response = requests.get(f'https://{DOMAIN}/api', timeout=3) + if response.status_code != 200: + DOMAIN = DOMAIN1 +except Exception: + DOMAIN = DOMAIN1 # ---------------------------------- 环境变量枚举类 ---------------------------------- @@ -73,9 +86,13 @@ def set_default(cls): """ 设置默认的环境变量值 """ + api_host = f'https://api.{DOMAIN}/api' + if DOMAIN == DOMAIN1: + api_host = f'https://{DOMAIN}/api' + envs = { - cls.WEB_HOST.value: "https://swanlab.cn", - cls.API_HOST.value: "https://api.swanlab.cn/api", + cls.WEB_HOST.value: f"https://{DOMAIN}", + cls.API_HOST.value: api_host, cls.RUNTIME.value: "user", } for k, v in envs.items():