3 ms·
For the TS compiler: If you took each generation step, closed any partial JSON objects (ie close any open `{`), checked that it was valid JSON and then validate
by rezonant 3y ago
For the TS compiler: If you took each generation step, closed any partial JSON objects (ie close any open `{`), checked that it was valid JSON and then validated it using a deep version of Partial<T>, that should do the trick.
- akavi 3y agoNot for even the simplest schemas. Eg, given even the type: {"aLongerKey": "value"} The generation prefix: {"a would by your algorithm produce the following invalid output: {"a}
- just-ok 3y agoBut that isn’t valid JSON
- akavi 3y agoRight, it would fail even before hitting the typing check.
- rezonant 3y agoThat's why I mentioned you check the JSON validity first. You'd obviously need to continue letting it generate tokens until you can parse the JSON to check if the type is partial. You could of course close even the quotes but then you'd get "not valid" signals from TS when the AI is like "just let me finish!" :-)