chore: 更新后端配置、Docker部署及前端API请求配置
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -10,6 +10,13 @@ def _int_env(name: str, default: int) -> int:
|
|||||||
return int(raw)
|
return int(raw)
|
||||||
|
|
||||||
|
|
||||||
|
def _list_env(name: str, default: list[str]) -> list[str]:
|
||||||
|
raw = os.getenv(name)
|
||||||
|
if raw is None or raw.strip() == "":
|
||||||
|
return default
|
||||||
|
return [item.strip() for item in raw.split(",") if item.strip()]
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
@dataclass(frozen=True)
|
||||||
class Settings:
|
class Settings:
|
||||||
app_name: str = os.getenv("APP_NAME", "YG Fine-Tune Platform API")
|
app_name: str = os.getenv("APP_NAME", "YG Fine-Tune Platform API")
|
||||||
@@ -17,6 +24,7 @@ class Settings:
|
|||||||
route_prefix: str = os.getenv("MODELTF_ROUTE_PREFIX", "/modelTF")
|
route_prefix: str = os.getenv("MODELTF_ROUTE_PREFIX", "/modelTF")
|
||||||
app_mode: str = os.getenv("APP_MODE", "local")
|
app_mode: str = os.getenv("APP_MODE", "local")
|
||||||
database_url: str = os.getenv("DATABASE_URL", "postgresql+psycopg://yg_ft:change_me@localhost:15432/yg_ft")
|
database_url: str = os.getenv("DATABASE_URL", "postgresql+psycopg://yg_ft:change_me@localhost:15432/yg_ft")
|
||||||
|
cors_allow_origins: list[str] = None # type: ignore[assignment]
|
||||||
compute_mode: str = os.getenv("COMPUTE_MODE", "real")
|
compute_mode: str = os.getenv("COMPUTE_MODE", "real")
|
||||||
compute_status_sync_mode: str = os.getenv("COMPUTE_STATUS_SYNC_MODE", "polling")
|
compute_status_sync_mode: str = os.getenv("COMPUTE_STATUS_SYNC_MODE", "polling")
|
||||||
compute_poll_interval_seconds: int = _int_env("COMPUTE_POLL_INTERVAL_SECONDS", 3)
|
compute_poll_interval_seconds: int = _int_env("COMPUTE_POLL_INTERVAL_SECONDS", 3)
|
||||||
@@ -27,6 +35,21 @@ class Settings:
|
|||||||
log_max_bytes: int = _int_env("LOG_MAX_BYTES", 20 * 1024 * 1024)
|
log_max_bytes: int = _int_env("LOG_MAX_BYTES", 20 * 1024 * 1024)
|
||||||
log_retention_days: int = _int_env("LOG_RETENTION_DAYS", 10)
|
log_retention_days: int = _int_env("LOG_RETENTION_DAYS", 10)
|
||||||
|
|
||||||
|
def __post_init__(self) -> None:
|
||||||
|
object.__setattr__(
|
||||||
|
self,
|
||||||
|
"cors_allow_origins",
|
||||||
|
_list_env(
|
||||||
|
"CORS_ALLOW_ORIGINS",
|
||||||
|
[
|
||||||
|
"http://localhost:16801",
|
||||||
|
"http://127.0.0.1:16801",
|
||||||
|
"http://localhost:17861",
|
||||||
|
"http://127.0.0.1:17861",
|
||||||
|
],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@lru_cache
|
@lru_cache
|
||||||
def get_settings() -> Settings:
|
def get_settings() -> Settings:
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
|
|
||||||
from app.api.v1.router import api_router
|
from app.api.v1.router import api_router
|
||||||
from app.core.config import get_settings
|
from app.core.config import get_settings
|
||||||
@@ -10,6 +11,13 @@ def create_app() -> FastAPI:
|
|||||||
configure_logging(settings)
|
configure_logging(settings)
|
||||||
|
|
||||||
app = FastAPI(title=settings.app_name)
|
app = FastAPI(title=settings.app_name)
|
||||||
|
app.add_middleware(
|
||||||
|
CORSMiddleware,
|
||||||
|
allow_origins=settings.cors_allow_origins,
|
||||||
|
allow_credentials=True,
|
||||||
|
allow_methods=["*"],
|
||||||
|
allow_headers=["*"],
|
||||||
|
)
|
||||||
setup_request_logging(app)
|
setup_request_logging(app)
|
||||||
app.include_router(api_router, prefix=settings.route_prefix)
|
app.include_router(api_router, prefix=settings.route_prefix)
|
||||||
return app
|
return app
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
APP_ENV=prod
|
APP_ENV=prod
|
||||||
APP_NAME=YG Fine-Tune Platform API
|
APP_NAME=YG Fine-Tune Platform API
|
||||||
MODELTF_ROUTE_PREFIX=/modelTF
|
MODELTF_ROUTE_PREFIX=/modelTF
|
||||||
|
CORS_ALLOW_ORIGINS=http://localhost:16801,http://127.0.0.1:16801
|
||||||
|
|
||||||
FRONTEND_IMAGE=yg-ft-frontend-runtime:latest
|
FRONTEND_IMAGE=yg-ft-frontend-runtime:latest
|
||||||
BACKEND_API_IMAGE=yg-ft-backend-api:latest
|
BACKEND_API_IMAGE=yg-ft-backend-api:latest
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ services:
|
|||||||
APP_ENV: ${APP_ENV:-prod}
|
APP_ENV: ${APP_ENV:-prod}
|
||||||
APP_NAME: ${APP_NAME:-YG Fine-Tune Platform API}
|
APP_NAME: ${APP_NAME:-YG Fine-Tune Platform API}
|
||||||
MODELTF_ROUTE_PREFIX: ${MODELTF_ROUTE_PREFIX:-/modelTF}
|
MODELTF_ROUTE_PREFIX: ${MODELTF_ROUTE_PREFIX:-/modelTF}
|
||||||
|
CORS_ALLOW_ORIGINS: ${CORS_ALLOW_ORIGINS:-http://localhost:16801,http://127.0.0.1:16801}
|
||||||
DATABASE_URL: ${DATABASE_URL:-postgresql+psycopg://yg_ft:change_me@postgres:5432/yg_ft}
|
DATABASE_URL: ${DATABASE_URL:-postgresql+psycopg://yg_ft:change_me@postgres:5432/yg_ft}
|
||||||
REDIS_URL: ${REDIS_URL:-redis://redis:6379/0}
|
REDIS_URL: ${REDIS_URL:-redis://redis:6379/0}
|
||||||
USE_BUILTIN_POSTGRES: ${USE_BUILTIN_POSTGRES:-true}
|
USE_BUILTIN_POSTGRES: ${USE_BUILTIN_POSTGRES:-true}
|
||||||
|
|||||||
@@ -40,7 +40,8 @@ service.interceptors.response.use(
|
|||||||
return Promise.reject(new Error(message))
|
return Promise.reject(new Error(message))
|
||||||
},
|
},
|
||||||
(error) => {
|
(error) => {
|
||||||
const message = error.response?.data?.message || error.message || '网络异常'
|
const detail = error.response?.data?.detail
|
||||||
|
const message = detail?.message || error.response?.data?.message || detail || error.message || '网络异常'
|
||||||
ElMessage.error(message)
|
ElMessage.error(message)
|
||||||
return Promise.reject(error)
|
return Promise.reject(error)
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user