PartialJson
org.llm4s.schema.PartialJson
@Experimental
object PartialJson
A tolerant parser for the JSON a model has written so far: given a prefix of a JSON document, it closes the open strings, arrays and objects and returns the value the prefix describes.
What the prefix does not finish is left out rather than guessed:
- a property whose value has not started, or whose key is still being written, is absent;
- a number is surfaced only once a character after it shows that it is complete, so
12.5never shows as1; true,falseandnullare surfaced only once complete;- a string still being written is surfaced as its prefix (without an escape that has not finished), or left out with
partialStrings = false.
So the value for a prefix is always a prefix of the value for the whole document: every property it has, the whole document has with the same or a longer value. Text after the first value, or after JSON that is not valid, is ignored: the value is what came before it. Nesting deeper than 512 levels is cut there, as BoundedJson refuses it. The parser never throws.
client.streamStructuredOf[A] uses it to turn a streamed reply into typed partial values.
Attributes
- Graph
-
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
PartialJson.type
Members list
In this article