flipped-aurora/gin-vue-admin · error
llmAuto 缺少 mode 参数
Error message
llmAuto 缺少 mode 参数
What it means
After validating AiPath, buildLLMAutoPath() reads llm["mode"] from the request's JSONMap, trims and stringifies it. If mode is empty it returns 'llmAuto 缺少 mode 参数', because {FUNC} in the AiPath cannot be substituted without a mode.
Source
Thrown at server/service/system/auto_code_llm.go:98
},
nil,
payload,
-1, // 不设置 client.Timeout,SSE 流的生命周期由 ctx 控制
)
if err != nil {
return nil, fmt.Errorf("调用上游大模型流式服务失败: %w", err)
}
return res, nil
}
func buildLLMAutoPath(llm common.JSONMap) (string, error) {
if global.GVA_CONFIG.AutoCode.AiPath == "" {
return "", errors.New("请先前往插件市场个人中心获取 AiPath 并填写到 config.yaml 中")
}
mode := strings.TrimSpace(fmt.Sprintf("%v", llm["mode"]))
if mode == "" {
return "", errors.New("llmAuto 缺少 mode 参数")
}
return strings.ReplaceAll(global.GVA_CONFIG.AutoCode.AiPath, "{FUNC}", mode), nil
}
func cloneLLMAutoJSONMap(src common.JSONMap) common.JSONMap {
dst := make(common.JSONMap, len(src))
for key, value := range src {
dst[key] = value
}
return dst
}
func previewResponseBody(body []byte) string {
text := strings.TrimSpace(string(body))
text = strings.ReplaceAll(text, "\r", " ")
text = strings.ReplaceAll(text, "\n", " ")
text = strings.Join(strings.Fields(text), " ")View on GitHub (pinned to 3136500ef3)
Solutions
- Include a non-empty llm.mode in the request body (the AI auto-generation mode selected in the UI).
- Inspect the outgoing JSON payload in devtools to confirm the mode field is present under llm.
- Update the frontend caller to always send mode before invoking the LLMAuto endpoint.
- If mode is dynamic, validate it client-side and block submission when empty.
Example fix
// before
const payload = { llm: { prompt } } // mode missing
// after
const payload = { llm: { mode: selectedMode, prompt } } // e.g. mode: 'code'
if (!selectedMode) return ElMessage.warning('请先选择生成模式') Defensive patterns
Strategy: validation
Validate before calling
// validate payload before calling the API
if (!payload.llm || typeof payload.llm.mode !== 'string' || !payload.llm.mode.trim()) {
throw new Error('llm.mode is required (the AI generation mode)')
} Try / catch
try {
const res = await api.llmAuto(payload)
} catch (err) {
if (String(err.msg || err).includes('缺少 mode')) {
// fix request: add llm.mode then retry once
} else {
throw err
}
} Prevention
- Always send llm.mode from the UI's selected generation mode
- Add client-side required-field checks before submit
- Keep frontend field names in sync with the backend JSONMap keys
- Cover the LLMAuto call in e2e tests with a real mode value
When it happens
Trigger: Calling LLMAuto or LLMAutoStream with a request body whose llm object omits "mode", sets it to null, or sets it to an empty/whitespace-only string.
Common situations: Frontend form not sending the selected AI generation mode (file/table/package auto paths); older clients calling a renamed field; hand-crafted API requests in tests/Postman missing the llm.mode key; mode cleared by a UI reset before submit.
Understand the failure class
Background: Missing required parameter errors: what 'X is required' and 'the required X param is missing' mean, and how to fix them — this error's family across 27 libraries.
Related errors
AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31).
Data as JSON: /api/errors/ad04c077b733de2e.
Report an issue: GitHub.