Examples menu

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

json
{
  "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
    }
  ]
}

Try it

Samples:
Example: Generate written text

Read about it in the developer docs