|
|
--- |
|
|
license: apache-2.0 |
|
|
--- |
|
|
|
|
|
[Run `fix-json` on |
|
|
Synthetic!](https://synthetic.new/hf/syntheticlab/fix-json) |
|
|
IMPORTANT: Make sure to set `temperature` to zero, either via the API or in the |
|
|
settings UI on Synthetic (accessed via the gear icon). |
|
|
|
|
|
`fix-json` is a small, fast model to fix broken JSON. While most LLM inference |
|
|
providers support a "JSON mode" that enforces model responses are valid JSON, |
|
|
many *don't* support strict JSON or schema adherence for function calls. While |
|
|
coding LLMs are typically fairly good at generating JSON, at a certain level of |
|
|
nesting they can make small mistakes like forgetting to triple-escape some |
|
|
deeply nested control character. |
|
|
|
|
|
When that happens, most agent frameworks force retries. Retries are bad for a |
|
|
couple of reasons: |
|
|
|
|
|
1. They're slow, and typically expensive, since you're using a fairly large |
|
|
model to do the retry |
|
|
2. They often can confuse the model: models are trained reasonably well on the |
|
|
happy path where they generate working code and tool calls, but often suffer |
|
|
when attempting to self-correct. |
|
|
|
|
|
`fix-json` is trained to fix those broken JSON strings, allowing coding agents |
|
|
to typically skip (expensive, slow, model-confusing) retries, fairly robustly. |
|
|
It's a Llama 3.1 8b LoRA, which means you can run it cheaply on inference |
|
|
providers like [Synthetic](https://synthetic.new/hf/syntheticlab/diff-apply). |
|
|
It was trained against editing any inner string contents, and attempts to only |
|
|
make the minimal control character edits possible to fix the JSON string. |
|
|
|
|
|
The model is generally fairly robust to prompts, but for best performance you |
|
|
should use the original prompt it was trained on: |
|
|
|
|
|
``` |
|
|
|
|
|
The following string may be broken JSON. Fix it if possible. Respond with JSON in the following |
|
|
format, defined as TypeScript types: |
|
|
|
|
|
// Success response: |
|
|
type JsonFixSuccess = { |
|
|
success: true, |
|
|
|
|
|
// The parsed JSON |
|
|
fixed: any, |
|
|
}; |
|
|
|
|
|
// Failure response: |
|
|
type JsonFixFailure = { |
|
|
success: false, |
|
|
}; |
|
|
|
|
|
If it's more-or-less JSON, fix it and respond with the success response. If it's not, respond with |
|
|
the failure response. Here's the string: |
|
|
``` |
|
|
|
|
|
You should append the broken JSON string to the end of the prompt. It'll |
|
|
respond with either `{ "success": false }` if the string is too ambiguous or |
|
|
doesn't appear to be JSON; otherwise, it'll generate `{ "success": true, |
|
|
"fixed": ... }`, where `fixed` is the JSON. |
|
|
|
|
|
Since the model responds with pure JSON, it's suitable for use with LLM |
|
|
inference providers that allow JSON mode, making it even more robust at fixing |
|
|
JSON. |
|
|
|
|
|
## Training details |
|
|
|
|
|
Trained on a single H100 NVL for 2.5 hours using Axolotl. |
|
|
|