Examples / Fill in forms
Generate written text
The AI writes a text field, such as a draft reply, from the rest of the form, and the person edits it before saving.
The AI can write free-text fields, such as a reply, from what is already in the form. Here it writes the Reply field, which is marked with the task name reply in uag.
Its instructions are part of the form: the Criteria text (a content component marked uagField: "criteria") tells the AI what to write, and it gets no other instructions. Because they live in the form, whoever designs the form controls what the AI writes, and can change it in the form builder without touching code.
Nothing is saved by generating. When the Draft a reply button is pressed, the page code asks the UAG's agent/generate for a draft and puts it into the Reply field, where the person can change it before submitting. Pressing the button again replaces the reply with a new draft.
Try it: pick a sample to fill in the message, then press Draft a reply.
Turn it on
{
"title": "Example: Generate written text",
"name": "exampleGenerateText",
"path": "example-generate-text",
"type": "form",
"display": "form",
"tags": [
"uag"
],
"properties": {
"description": "A message received, and a reply to send back."
},
"components": [
{
"type": "select",
"key": "topic",
"label": "Topic",
"input": true,
"dataSrc": "values",
"data": {
"values": [
{
"label": "Question",
"value": "question"
},
{
"label": "Problem",
"value": "problem"
},
{
"label": "Request",
"value": "request"
},
{
"label": "Feedback",
"value": "feedback"
}
]
}
},
{
"type": "textarea",
"key": "message",
"label": "Message received",
"input": true,
"rows": 4,
"validate": {
"required": true
}
},
{
"type": "content",
"key": "replyCriteria",
"label": "Criteria",
"input": false,
"html": "<p>Write a reply to the message in <code>message</code>, about its <code>topic</code>. Be warm and brief: two to four sentences, under 80 words. Answer what was asked if you can; otherwise say what happens next. Do not promise anything specific, such as a refund or a date. Sign it \"The team\".</p>",
"properties": {
"uag": "reply",
"uagField": "criteria"
}
},
{
"type": "button",
"key": "draft",
"label": "Draft a reply",
"action": "event",
"event": "draftReply",
"input": true,
"theme": "secondary"
},
{
"type": "textarea",
"key": "reply",
"label": "Reply",
"input": true,
"rows": 5,
"properties": {
"uag": "reply"
}
},
{
"type": "button",
"key": "submit",
"label": "Submit",
"action": "submit",
"input": true
}
]
}<link rel="stylesheet" href="https://ai.form.io/uag-js/uag-js.css">
<script src="https://cdn.jsdelivr.net/npm/@formio/js@5.6.1/dist/formio.full.min.js"></script>
<!-- Registers @formio/uag-js with this UAG: forms tagged uag save through it, and get Agent Input and the chat. -->
<script src="https://ai.form.io/uag-js/uag.use.js"></script>
<div id="form"></div>
<script>
Formio.createForm(document.getElementById('form'), 'https://uag.form.io/example-generate-text').then((form) => {
// The form's "Draft a reply" button (an event button) asks the UAG for a draft.
form.on('draftReply', async () => {
const response = await fetch('https://ai.form.io/uag/example-generate-text/agent/generate', {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'x-jwt-token': Formio.getToken() },
body: JSON.stringify({ task: 'reply', data: form.submission.data, overwrite: true }),
});
const result = await response.json();
// Only the fields the task wrote; the person's own values stay as they are.
const reply = result.fields && result.fields.reply;
if (reply && reply.value) form.getComponent('reply').setValue(reply.value);
});
});
</script>Try it
Start the live examples
The examples call real models. Starting them signs you in as a temporary guest of the examples' project, for every example; what you enter is deleted after a day.
Not supported without a license
This demo needs a license (LICENSE_KEY) that includes the UAG, or a 30-day free trial project on portal.form.io. This deployment has neither: it serves an Open Source project, or its UAG is unlicensed.
The chat widget examples work everywhere, with no license.