discourse-ai/lib/completions
Roman Rizzi d72ad84f8f
FIX: Retry parsing escaped inner JSON to handle control chars. (#1357)
The structured output JSON comes embedded inside the API response, which is also a JSON. Since we have to parse the response to process it, any control characters inside the structured output are unescaped into regular characters, leading to invalid JSON and breaking during parsing. This change adds a retry mechanism that escapes
the string again if parsing fails, preventing the parser from breaking on malformed input and working around this issue.

For example:

```
  original = '{ "a": "{\\"key\\":\\"value with \\n newline\\"}" }'
  JSON.parse(original) => { "a" => "{\"key\":\"value with \n newline\"}" }
  # At this point, the inner JSON string contains an actual newline.
```
2025-05-21 11:25:59 -03:00
..
dialects DEV: use a proper object for tool definition (#1337) 2025-05-15 17:32:39 +10:00
endpoints FIX: Don't dig on nil when checking for the gemini schema (#1356) 2025-05-21 08:30:47 -03:00
anthropic_message_processor.rb DEV: Use structured responses for summaries (#1252) 2025-05-06 10:09:39 -03:00
cancel_manager.rb FEATURE: forum researcher persona for deep research (#1313) 2025-05-14 12:36:16 +10:00
json_stream_decoder.rb FEATURE: improve tool support (#904) 2024-11-12 08:14:30 +11:00
json_streaming_parser.rb FEATURE: partial tool call support for OpenAI and Anthropic (#908) 2024-11-14 06:58:24 +11:00
json_streaming_tracker.rb FIX: Retry parsing escaped inner JSON to handle control chars. (#1357) 2025-05-21 11:25:59 -03:00
llm.rb FEATURE: forum researcher persona for deep research (#1313) 2025-05-14 12:36:16 +10:00
nova_message_processor.rb DEV: Use structured responses for summaries (#1252) 2025-05-06 10:09:39 -03:00
open_ai_message_processor.rb DEV: Use structured responses for summaries (#1252) 2025-05-06 10:09:39 -03:00
prompt.rb DEV: use a proper object for tool definition (#1337) 2025-05-15 17:32:39 +10:00
prompt_messages_builder.rb FEATURE: forum researcher persona for deep research (#1313) 2025-05-14 12:36:16 +10:00
report.rb FEATURE: Allow for persona & llm selection in bot conversations page (#1276) 2025-04-24 11:17:24 -05:00
structured_output.rb FIX: Structured output discrepancies. (#1340) 2025-05-15 11:32:10 -03:00
thinking.rb FEATURE: implement thinking token support (#1155) 2025-03-04 12:22:30 +11:00
tool_call.rb FEATURE: AI artifacts (#898) 2024-11-19 09:22:39 +11:00
tool_definition.rb DEV: use a proper object for tool definition (#1337) 2025-05-15 17:32:39 +10:00
upload_encoder.rb FEATURE: enforce jpg/png for all images (#1309) 2025-05-05 17:46:37 +10:00
xml_tag_stripper.rb FIX: display search correctly, bug when stripping XML (#668) 2024-06-14 15:28:40 +10:00
xml_tool_processor.rb DEV: use a proper object for tool definition (#1337) 2025-05-15 17:32:39 +10:00