fix: 避免 assistant.content=nil 注入 "null" 导致工具历史混杂#79
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0e261ff0a0
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| default: | ||
| return marshalToPromptString(v) | ||
| } | ||
| return prompt.NormalizeContent(v) |
There was a problem hiding this comment.
Preserve content fallback when text is empty
Delegating normalizeOpenAIContentForPrompt to prompt.NormalizeContent changes behavior for array content items that include both text and content: the previous implementation only consumed text when it was non-empty, then fell back to content, but NormalizeContent treats an empty text string as present and continues, so non-empty content is dropped. For OpenAI-compatible payloads that send placeholder "text": "" with real text in "content", this now strips message text from the prompt and can alter downstream tool-selection and model behavior.
Useful? React with 👍 / 👎.
Merge pull request #79 from CJackHwang/codex/analyze-and-optimize-issue-#77 fix: 避免 assistant.content=nil 注入 "null" 导致工具历史混杂
Motivation
assistant仅返回tool_calls且content = null时,归一化过程把nil序列化为字面量null并注入到提示词中,导致工具历史块与自然语言混杂,干扰后续工具识别和执行。Description
normalizeOpenAIContentForPrompt中对nil值做了提前返回空字符串处理以避免注入"null"(修改文件:internal/adapter/openai/message_normalize.go)。TestNormalizeOpenAIMessagesForPrompt_AssistantNilContentDoesNotInjectNullLiteral覆盖assistant.content=nil + tool_calls场景,确保不会注入null字面量且工具历史块仍被保留(修改文件:internal/adapter/openai/message_normalize_test.go)。Testing
go test ./internal/adapter/openai ./internal/util,所有测试均通过。Codex Task