Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REQUEST] 将web host、api host相关环境变量集成进 swanlab.login #792

Open
SAKURA-CAT opened this issue Jan 18, 2025 · 7 comments
Assignees
Labels
💪 enhancement New feature or request 🌍 prepare for the future Feature prepare for the future

Comments

@SAKURA-CAT
Copy link
Contributor

🤩 Features description [Please make everyone to understand it]

如题,我打算将设置web host、api host的能力整合进swanlab.login

👍 What problem does this feature solve

我们知道在sdk中SWANLAB_WEB_HOSTSWANLAB_API_HOST两个环境变量分别用于表示云端前端的url和后端url。目前,用户如果需要修改此环境变量必须使用如下方式:

os.environ["SWANLAB_API_HOST"] = "https://xxx"
os.environ["SWANLAB_WEB_HOST"] = "https://xxx"

这通常过于繁琐,也不符合人机交互直觉,因此需要拓展这部分功能——此外,这也为后面私有化部署做准备。

👾 What does the proposed API look like

swanlab.login(api_key="", host="xxx")

设置host参数可以同时设置web hostapi host,我们约定api hostweb host/api子路由下的内容。为了保证函数简洁性,不支持分别设置web hostapi host(如果有这需求,还是用os.environ进行设置)

@SAKURA-CAT SAKURA-CAT added 🌍 prepare for the future Feature prepare for the future 💪 enhancement New feature or request labels Jan 18, 2025
@SAKURA-CAT SAKURA-CAT self-assigned this Jan 18, 2025
@Zeyi-Lin
Copy link
Member

关于CLI的交互用法:

swanlab login --host=https://xxx

@SAKURA-CAT
Copy link
Contributor Author

Image

@SAKURA-CAT
Copy link
Contributor Author

Image

简单来讲:

  1. 如果用户执行了swanlab.login,则此函数完成对host等环境变量的初始化,并生成http对象,在swanlab.init中跳过这段逻辑
  2. 如果用户未执行swanlab.login,则swanlab.init同时担任初始化host等环境变量,并生成http对象的任务,在后端校验的过程中直接报错。

如果未执行swanlab.login,且在swanlab.init中发现用户并没有存储api key,则会进行 #632 的逻辑。这里有个问题是目前并不允许选择host。

@SAKURA-CAT
Copy link
Contributor Author

这里有个问题是目前并不允许选择host

目前先不管此问题

@SAKURA-CAT
Copy link
Contributor Author

输入的api host和web host会在http对象初始化以后挂载在对象上,不可修改。这意味着即使在init或者login后修改环境变量,也没有用了。

@SAKURA-CAT
Copy link
Contributor Author

SAKURA-CAT commented Feb 5, 2025

还有一个问题是,在netrc文件保存时host的名称不仅仅是域名 还携带了/api路由,这是有点问题的。
我们希望前端显示的登录提示不包含路由,类似:

swanlab login --api-key xxxx --host example.com

那么为了与之前保持一致,我们就需要在写入时手动添加路由前缀,但是假设在未来私有化部署时用户在上层设置了网关或者中间件改变了路由前缀,自动添加又显得不那么合适。

为了解决这个问题,还是需要新增一个参数,在代码内,api应该是:

swanlab.login(api_key="xxx", host="xxx", api_path=False)

其中api_path 默认为True,代表在输入的host后自动添加/api前缀,可以设置为False取消,此时需要在host上添加相应的路由前缀。

对应到cli中:

swanlab login --api-key xxxx --host example.com  --no-api-path

至于选择https还是http协议,默认为https协议,除非用户显式添加了http://前缀。

@SAKURA-CAT
Copy link
Contributor Author

还有一个问题是,在netrc文件保存时host的名称不仅仅是域名 还携带了/api路由,这是有点问题的。
我们希望前端显示的登录提示不包含路由,类似:

swanlab login --api-key xxxx --host example.com

那么为了与之前保持一致,我们就需要在写入时手动添加路由前缀,但是假设在未来私有化部署时用户在上层设置了网关或者中间件改变了路由前缀,自动添加又显得不那么合适。

为了解决这个问题,还是需要新增一个参数,在代码内,api应该是:

swanlab.login(api_key="xxx", host="xxx", api_path=False)

其中api_path 默认为True,代表在输入的host后自动添加/api前缀,可以设置为False取消,此时需要在host上添加相应的路由前缀。

对应到cli中:

swanlab login --api-key xxxx --host example.com  --no-api-path

至于选择https还是http协议,默认为https协议,除非用户显式添加了http://前缀。

还是有点问题,在计算机网络中host代表的是服务器资源标识,不应该包含路径等内容:

协议://host:端口/路径?查询参数#片段

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💪 enhancement New feature or request 🌍 prepare for the future Feature prepare for the future
Projects
None yet
Development

No branches or pull requests

2 participants