Conversation
📝 WalkthroughWalkthroughExtracts JSON from chatty LLM responses by taking the substring between the first Changes
Sequence DiagramsequenceDiagram
participant Client as Client
participant LLM as Gemini LLM
participant Localizer as Explicit Localizer
participant Parser as JSON Parser
participant Repair as jsonrepair
participant Result as Result Handler
Client->>LLM: Request translation
LLM-->>Localizer: Responds (conversational text + JSON)
Localizer->>Parser: Extract substring between first "{" and last "}"
Parser->>Parser: Attempt JSON.parse(extracted)
alt Parse Success
Parser->>Result: Return parsed JSON object
else Parse Failure
Parser->>Repair: Call jsonrepair(extracted)
Repair->>Parser: Return repaired text
Parser->>Parser: Attempt JSON.parse(repaired)
alt Repair Success
Parser->>Result: Return parsed JSON object
else Repair Failure
Parser->>Result: Throw error with response snippet
end
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
|
@Aparnap2 - pls review failed workflow |
c470823 to
912637d
Compare
- Extract JSON using indexOf/lastIndexOf for structural boundaries - Preserve jsonrepair fallback for malformed JSON internals - Add comprehensive error messages with raw response preview - Add unit tests for chatty response scenarios - Fixes Gemini 2.5 Flash Lite 'OK' prefix parsing error Fixes lingodotdev#1886
- Extract JSON using indexOf/lastIndexOf for structural boundaries - Preserve jsonrepair fallback for malformed JSON internals - Add comprehensive error messages with raw response preview - Add unit tests for chatty response scenarios - Add integration test for Gemini 2.5 Flash Lite real API - Fixes Gemini 2.5 Flash Lite 'OK' prefix parsing error Fixes lingodotdev#1886
912637d to
b59267e
Compare
|
Thank you for your contribution! However, this PR references issue #1886 where you're not currently assigned. To contribute, please either get assigned to the issue first or find an unassigned issue to work on. This helps us coordinate contributions effectively. |
Problem
Closes #1886
Gemini 2.5 Flash Lite and potentially other "chatty" LLMs prefix JSON responses with conversational text
Solution
Implemented robust JSON extraction as discussed with @maxprilutskiy:
Changes
Testing
Unit Tests (6 tests - all passing)
OK prefix extraction: OK{"data":...} ✓
Conversational prefix: Sure, here's...{"data":...} ✓
Clean JSON: {"data":...} ✓
jsonrepair fallback ✓
Text after JSON ✓
Multiline JSON with wrapper ✓
Manually tested with Gemini 2.5 Flash Lite (API key provided):
✅ Gemini 2.5 Flash Lite test passed!
Why This Approach
cc @maxprilutskiy @vrcprl @PatrickHuiskens
Summary by CodeRabbit
Bug Fixes
Tests
Chores