The API is great at pattern recognition and we can use this fact to speed up the task of writing XML. With the following prompt we are able to avoid the need to bracket tags and write closing tags. Spaces are used to denote nested relationships and a word and “:” are used to replace the closing and opening tags.

There are three main section to this prompt, separated with “###”:

  • An Instruction to “Convert the text to XML”

  • An example with tagged sections

  • An input section, to be edited by the user, to convert shorthand text to XML

The first step to creating this prompt is to think about our ideal input and output. In this case the input is as close to plain text as possible and the corresponding output we want is XML. By matching the terms in the instruction to the example and input section, we help the API understand three things:

  • Our output intent

  • What it needs to generate

  • How it should be formatting the content

Convert the text to XML.

###

[text]

breakfast_menu

food

name:Belgian Waffles

price:$5.95

description:Two of our famous Belgian Waffles with plenty of real maple syrup

calories:650

[conversion]

<?xml version="1.0" encoding="UTF-8"?>

<breakfast_menu>

<food>

<name>Belgian Waffles</name>

<price>$5.95</price>

<description>

Two of our famous Belgian Waffles with plenty of real maple syrup

</description>

<calories>650</calories>

</food>

</breakfast_menu>

---

[text]

note

to: Tove

from:Jani

heading:Reminder

body:Don't forget me this weekend!

[conversion]

<?xml version="1.0" encoding="UTF-8"?>

<note>

<to>Tove</to>

<from>Jani</from>

<heading>Reminder</heading>

<body>Don't forget me this weekend!</body>

</note>

Open this example in the Playground and try this yourself by replacing the second “[text]” section with your own. Remember to use spaces to denote nested relationships.

Did this answer your question?