Utilizing Model Examples to Convert Text to JSON

Basic Model Block

The basic Model Block accepts a specified prompt string and returns a Language Model completion as the result.

Advanced Model Block

The advanced Model Block provides parameters for the Introduction and Examples

  • Introduction: A paragraph that will appear at the beginning of your prompt once. Provides instruction to the model about how it should interpret your examples

  • Examples: Provide examples of the type of response you want the model to output. This could be a list of examples that are organized as a template question and answer.

  • Prompt: The final question that will appear at the end of the prompt that the user wants the model to complete.

Converting Text to JSON

In order to create a callable that can change plain text into a JSON, we need to provide examples for our model to reference back to so that the model would know what kind of output we are looking for.

To do this, let's initialize our examples as an array of example objects with a question and an answer field. There are two ways to do this, the first way will use a code block.

We can also load examples using the Data Block and inputting the examples in the dataset tab.

That uses the following example dataset.

After initializing the examples, we can now set up an advanced language model block that has an introduction that describes our desired task to our model and then enter in our examples as a question followed by an answer. Finally, we enter our original input question as our prompt.

We can now run some test cases to see if this works. When we try the input:

We can see that our callable successful returns the JSON object as:

Once tested, deploy the callable to use in any application.

Last updated