Repository navigation
Conversation
The greedy regex matched from the first '{' to the last '}', so a trailing prose segment containing another object made the blob invalid and silently dropped the whole analysis.
Fails on the unmodified source when a second object follows the answer; pins plain JSON, fenced JSON and invalid text.
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.
变更
EmotionAnalyzer._parse_json()在json.loads()失败后用re.search(r'\{[\s\S]*\}', text)兜底提取 JSON。这个正则是贪婪的:它从第一个{一直匹配到文本里最后一个}。Reproduced on main
d8138b501a755f662a024f7e8eb879613eabf1d3:LLM 偶尔会在结果 JSON 后面再附一段带花括号的说明、示例或第二个对象;此时兜底提取拼出一个非法 JSON,
_parse_json()直接返回{}。调用方拿不到 valence/arousal,整条情绪分析静默降级为默认值,且没有任何错误信号。单纯的后缀散文(不含})不受影响,所以这个问题在常规测试里不显眼。修复:改用
json.JSONDecoder().raw_decode()从第一个{开始解析,只取第一个完整对象,忽略其后所有文本;顺带移除不再使用的import re。plain JSON、```json 代码块、完全非法输入的原有行为不变。无 API、schema 或依赖变更。两个逻辑 commit 分别承载生产修复和回归测试。用户影响
LLM 在情绪结果后附加说明文字时,不会再让整条分析静默丢失;valence/arousal 正常落库。此前已能正确解析的输出保持原样。
验证
tests/test_emotion_parse_json_trailing.py— baseline 1 failed, 3 passed(第二个对象场景返回{});修复后 4 passed。tests/test_emotion_parse_json_trailing.py tests/test_emotion_clamp_nan.py tests/test_tag_point_id_delimiter.py tests/test_keyword_ties_all_equal.py tests/test_retrieval.py -q→ 50 passed。uv run pytest tests/未在本地通过:隔离环境缺少chromadb等可选依赖,与本次改动无关。查重
No issue claimed. 已检查当前全部 open PR:#507 修复的是同文件
_clamp()的 NaN 处理,与本 PR 的_parse_json()是不同函数、不同动因;#116 处理的是 extractor 的语言检测路由。tests/下此前无 emotion 相关测试文件。AI assistance: the change was located, implemented and tested by an AI agent; the author reviewed the diff and test output. No human maintainer review is claimed.