diff --git a/client/starwhale/api/_impl/service/service.py b/client/starwhale/api/_impl/service/service.py
index 67be6dcd33..2161cba9d8 100644
--- a/client/starwhale/api/_impl/service/service.py
+++ b/client/starwhale/api/_impl/service/service.py
@@ -2,6 +2,7 @@
import os
import sys
+import json
import typing as t
import functools
@@ -14,7 +15,7 @@
from fastapi import FastAPI
from pydantic import Field
-from starlette.responses import FileResponse
+from starlette.responses import HTMLResponse
from starlette.staticfiles import StaticFiles
from starwhale.utils import console
@@ -149,8 +150,21 @@ def spec() -> t.Union[ServiceSpec, None]:
methods=["POST"],
)
- def index(opt: t.Any) -> FileResponse:
- return FileResponse(os.path.join(STATIC_DIR_DEV, "client/index.html"))
+ def index(_: t.Any) -> HTMLResponse:
+ with open(os.path.join(STATIC_DIR_DEV, "client/index.html"), "r") as file:
+ content = file.read()
+ # https://github.com/star-whale/starwhale/pull/2996
+ root = os.getenv("SW_ONLINE_SERVING_ROOT_PATH", "")
+ opt = {
+ "root": root,
+ }
+ script = f""""""
+ content = content.replace("", script)
+ # replace assets path
+ content = content.replace("/assets/", f"{root}/assets/")
+ return HTMLResponse(content=content)
app.add_route("/", index, methods=["GET"])
app.mount("/", StaticFiles(directory=STATIC_DIR_DEV), name="assets")
diff --git a/console/client/ServingPage.tsx b/console/client/ServingPage.tsx
index 9dca9b4b19..1472576896 100644
--- a/console/client/ServingPage.tsx
+++ b/console/client/ServingPage.tsx
@@ -7,8 +7,11 @@ import { IApiSchema, InferenceType, ISpecSchema } from './schemas/api'
import { useChatStore } from '@starwhale/ui/Serving/store/chat'
import ChatGroup from './components/ChatGroup'
+// @ts-ignore
+const rootPath = window?.starwhaleConfig?.root ?? ''
+
const fetchSpec = async () => {
- const { data } = await axios.get('/api/spec')
+ const { data } = await axios.get(`${rootPath}/api/spec`)
return data
}
@@ -28,7 +31,7 @@ export default function ServingPage() {
job: { id: 'client' } as any,
type: apiSpec?.inference_type,
exposedLink: {
- link: '',
+ link: `${rootPath}/`,
type: 'WEB_HANDLER',
name: 'llm_chat',
},
diff --git a/console/client/index.html b/console/client/index.html
index 2635eab01f..da415c0ffb 100644
--- a/console/client/index.html
+++ b/console/client/index.html
@@ -14,6 +14,8 @@
href="https://starwhale-examples.oss-cn-beijing.aliyuncs.com/ui/iconfont/iconfont.css?v=20230928"
/>
Starwhale Serving
+
+