parseStructuredText method
Providers return structured output as a JSON document inside a text field; this parses that document into Dartvel's typed value tree.
Implementation
DVJsonObject parseStructuredText(String text) {
final Object? decoded;
try {
decoded = jsonDecode(text);
} on FormatException catch (error) {
throw DVAIProviderException(
providerName,
'Structured output was not valid JSON: ${error.message}',
responseBody: text,
);
}
if (decoded is! Map<String, Object?>) {
throw DVAIProviderException(
providerName,
'Structured output must be a JSON object.',
responseBody: text,
);
}
return DVJsonCodec.fromJsonObject(decoded);
}