fix: strip markdown JSON code blocks in OpenAI adapter responseFormat#55
Merged
Conversation
Closes #54 When responseFormat.type is 'json', many LLMs return JSON wrapped in markdown code fences (\\\). This causes JSON.parse failures in consumers. Added stripJsonCodeBlock() utility that detects and removes the fencing, called in doGenerate() when responseFormat is set to json. Changes: - Add stripJsonCodeBlock() to openai-adapter.ts - Call it in doGenerate() when responseFormat.type === 'json' - Export stripJsonCodeBlock from @openlinkos/ai index - Add 8 unit tests for stripJsonCodeBlock All 1033 tests pass.
There was a problem hiding this comment.
🤖 AI Code Review
Automated review for PR #55 — informational only, does not block merge.
Checklist
| Item | Notes | |
|---|---|---|
| ✅ | Type Safety | No issues detected |
| ✅ | Error Handling | No issues detected |
| ✅ | Test Coverage | 1 test file(s) updated |
| ✅ | API Consistency | 1 new export(s) added |
| ✅ | Breaking Changes | No breaking changes detected |
Stats
- 📁 Files changed: 3 (3 TypeScript)
- ➕ Lines added: 79
- 🧪 Test files updated: 1
All checks passed — looks good! 🎉
Powered by openlinkos/agent · AI PR Review workflow
Contributor
Author
🔍 代码审查 — PR #55关联 Issue: #54 — responseFormat JSON 返回 markdown 包裹导致解析失败 方案: ✅ 审查通过
注意事项(不阻塞):
CI 全绿: Build ✅ | Test ✅ | AI Review ✅ | Release check ✅ 已执行 squash merge。 |
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.
Closes #54
Problem
When using
responseFormat: { type: 'json' }, many LLMs (especially OpenAI-compatible endpoints like MiniMax) return JSON wrapped in markdown code fences: