fix: convert dict entities to text strings for highlights field (Fixes #386)#667
Conversation
…ritesh-1918#386) entities from ner_service.extract_entities() returns list[dict] with keys {"text", "label", "confidence"}, not EntityInfo objects. The highlights field expects list[str]. Changed highlights=[e.text for e in entities] to highlights=[e.get("text", "") for e in entities] to properly extract text from dict entries.
|
@lb1192176991-lab is attempting to deploy a commit to the ritesh Team on Vercel. A member of the Team first needs to authorize it. |
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
What
The
/ai/analyzeendpoint crashes with a 500 error because thehighlightsfield inTicketResponseis typed aslist[str]but receiveslist[dict]objects.Root cause:
ner_service.extract_entities()returnslist[dict]with keys{"text", "label", "confidence"}. When this list is passed tohighlights=[e.text for e in entities], it crashes withAttributeError: dict object has no attribute textbecause the entities variable is stilllist[dict]at that point in the code (it is only converted tolist[EntityInfo]in the separateentities=parameter).Fix: Changed line 1855 from:
to:
The
analyze_stream()endpoint already had the correct form (e.get("text", "")) on line 2019 — it was only theanalyze_only()function that had the wrong access pattern.Why
Users hitting the
/ai/analyzeendpoint get a 500 error when NER entities are present, making the AI analysis feature completely broken whenever entities are detected. Pydantic v2 cannot coercedictobjects intostr.Testing
entities = [{"text": "Python", "label": "tech", "confidence": 0.95}], highlights becomes["Python"]✓entities = [], highlights becomes[]✓entities = [{"label": "tech"}](missing text key), highlights becomes[""]✓ (graceful fallback)