forked from zhouruizhe/gmTouringMiniApp
feat(travel): 接入远端 AI 推荐服务,支持 GLM real 模式与本地静默回退
AI Code Review / review (pull_request) Successful in 1s
AI Code Review / review (pull_request) Successful in 1s
- createPlan 在配置 VITE_TRAVEL_ASSISTANT_API_BASE_URL 时调用 FastAPI 推荐服务 做无坐标选点,路线/交通/时长仍由本机核算;远端不可用即静默回退本地规划 - 放开 loadPlan 对远端行程的回读限制(原 AI 冻结期禁用),行程页跳转不再丢行程 - planner/assistant 文案按是否启用远端如实切换,不再谎称「本期不调用 AI」 - 新增远端接通/回退/候选载荷单测;server/README 更新联调与 real 模式说明 - .env.development 默认指向已部署推荐服务;server/.env.example 补 GLM 示例 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,9 @@
|
||||
LLM_MODE=mock
|
||||
|
||||
# Configure these on the server only when LLM_MODE=real.
|
||||
# Any OpenAI-compatible endpoint works, e.g. Zhipu GLM:
|
||||
# OPENAI_BASE_URL=https://open.bigmodel.cn/api/paas/v4
|
||||
# OPENAI_MODEL=glm-4-flash # free tier; use glm-4-plus etc. if you have credit
|
||||
OPENAI_API_KEY=
|
||||
OPENAI_BASE_URL=https://api.openai.com/v1
|
||||
OPENAI_MODEL=
|
||||
|
||||
+14
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
This FastAPI service is the server-only AI boundary for the Guangming travel POC. It defaults to deterministic `mock` mode. Model credentials belong only in `server/.env` or the deployment environment and must never be added to the mini-program build.
|
||||
|
||||
This service is reserved for a later AI integration phase. The current mini-program `createPlan` entry point is hard-wired to the local planner and does not call this service.
|
||||
The mini-program calls this service when `VITE_TRAVEL_ASSISTANT_API_BASE_URL` is set (`.env.development` points it at `http://localhost:8000`). If that variable is empty, or the service is unreachable or returns an error, the client silently falls back to its deterministic local planner — so the demo always works. The model only ever recommends POIs from a coordinate-free client whitelist; route geometry, transfer estimates, and final itinerary time remain client responsibilities. The itinerary page labels the result `真实 AI 推荐` (real), `远端演示规划` (mock), or `本地 POC 规划` (local fallback).
|
||||
|
||||
## Contract
|
||||
|
||||
@@ -60,3 +60,16 @@ Run tests from the repository root:
|
||||
```bash
|
||||
corepack pnpm server:test
|
||||
```
|
||||
|
||||
## Real model mode
|
||||
|
||||
Mock mode is deterministic and needs no credentials. To use a real model, set `LLM_MODE=real` in `server/.env` (gitignored) with any OpenAI-compatible endpoint — for example Zhipu GLM:
|
||||
|
||||
```
|
||||
LLM_MODE=real
|
||||
OPENAI_BASE_URL=https://open.bigmodel.cn/api/paas/v4
|
||||
OPENAI_MODEL=glm-4-flash
|
||||
OPENAI_API_KEY=<your key>
|
||||
```
|
||||
|
||||
`GET /api/v1/health` then reports `mode=real, configured=true, ready=true`. With `pnpm server:dev` running, generate a plan from the mini-program (H5 dev server on `:5173` is already in `CORS_ORIGINS`; for `mp-weixin` enable “不校验合法域名” in the devtools). To force the local planner again, unset `VITE_TRAVEL_ASSISTANT_API_BASE_URL` or stop the server.
|
||||
|
||||
Reference in New Issue
Block a user