Repository navigation
Conversation
Nl2SqlServiceImpl#generateSql used llmService.callSystem() on the new-SQL path, which builds a request containing only a system message. Many OpenAI-compatible providers (DeepSeek, Qwen, ...) require at least one role:"user" message and fail with "at least one message is required", so first-time SQL generation broke while the SQL repair path in the same method already used callUser(). Switch the new-generation path to callUser() so both branches send a user message. Update Nl2SqlServiceImplTest to stub and verify callUser() on that path and assert callSystem() is never used, and drop the now unused stubSystemSql() helper. Second instance of spring-ai-alibaba#461; PR spring-ai-alibaba#515 only fixed PythonAnalyzeNode.
Author
|
Note for reviewers on CI status: the three jobs in Local verification on this branch (offline,
Happy to re-run anything maintainers want once CI is allowed to execute on the upstream side. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR 描述(候选 1:#461 的第二处实例)
Fixes
Fixes #461(第二处实例)
关联既有 PR
#515 已修
PythonAnalyzeNode(llmService.callSystem(systemPrompt)→callUser(...)),但同源的
Nl2SqlServiceImpl#generateSql新 SQL 生成分支仍在使用callSystem。本 PR 补上这处,两者根因相同:请求只含 system message,缺 user message。
Root cause
StreamLlmService#callSystem:.system(system)只设置 system message,没有.user(...)。许多 OpenAI 兼容 provider(DeepSeek、通义千问等)硬性要求 messages 数组中至少有一条
role: "user",否则直接返回at least one message is required。Nl2SqlServiceImpl#generateSql(第 79 行,新 SQL 生成分支):而同一方法第 71 行的 SQL 修复分支已经用
callUser:同类两条路径,一条兼容一条不兼容——不一致本身即是佐证。
What this PR does
1 行主代码改动:
callSystem(prompt)→callUser(prompt)。Nl2SqlServiceImpl中 5 处 LLM 调用(L56 / L71 / L79 / L120 / L160)现已统一为callUser。关于推翻既有测试断言
Nl2SqlServiceImplTest原有断言锁定了错误行为:这里必须显式说明为何推翻它:
callSystem不是被刻意选择的调用方式,而是与 provider兼容性要求相悖的疏漏。测试原本通过,是因为 mock 不会校验 messages 数组结构;真实
provider 会拒绝。改为:
同时删除随之无用的
stubSystemSql()helper。How to verify
RED(修复前)
./mvnw -pl data-agent-management -am -Dtest=Nl2SqlServiceImplTest -Dsurefire.failIfNoSpecifiedTests=false test栈精确指向第 79 行:
callSystem未被 stub 而返回null。GREEN(修复后)
同命令:
反证(瑶光)
把第 79 行回滚成
callSystem→ 3 个参数化用例重新变红;恢复 → 转绿。证明红灯来自被测层,不是 mock 假红。
全量 + checkstyle
关于那 6 个失败:它们是上游
main基线既有失败,与本次改动无关。已用基线隔离证明——把两个文件还原成 upstream
main原版后单独跑:这三个套件均不在本次改动范围内。(PR #630 的 Notes 也记录了同样的失败。)
Patch
data-agent-management/src/main/java/com/alibaba/cloud/ai/dataagent/service/nl2sql/Nl2SqlServiceImpl.javadata-agent-management/src/test/java/com/alibaba/cloud/ai/dataagent/service/nl2sql/Nl2SqlServiceImplTest.javaSpecial notes for review
callSystem仍剩一处:PythonAnalyzeNode.java:87,正是 PR fix: use user message for python analyze prompt #515 的处理对象。本 PR 不触碰它,避免与 fix: use user message for python analyze prompt #515 冲突。两PR都合并后
callSystem可考虑从LlmService接口移除,但那超出本 PR 范围。
lint-pr-title.yml:fix(nl2sql): ...。