fix: 自动提取 LLM 返回内容中的 JSON,避免 pydantic 校验失败#37
Open
chinaguole wants to merge 1 commit into
Open
Conversation
## 变更内容 - 在 LLMs.py 的 _validate_response 方法中,增加了自动提取 JSON 的逻辑。 - 解决了 LLM 返回内容包含非 JSON 部分(如 <think> 标签等)时,pydantic 校验失败的问题。 ## 变更原因 - 某些 LLM 返回内容可能包含额外的注释、标签或 markdown,导致 pydantic 的 model_validate_json 解析失败。 - 通过正则提取第一个合法 JSON,有效提升了兼容性和健壮性。 ## 测试说明 - 本地测试通过,LLM 返回内容包含非 JSON 部分时,依然可以正常解析和校验。 --- 如有需要可进一步完善单元测试。
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.
变更内容
变更原因
测试说明
如有需要可进一步完善单元测试。