Documentation

Documentation versions (currently viewingVaadin 24)

Advanced Example

An advanced example of how to use AI Form Filler.

This page provides an advanced example of how to use the AI Form Filler with ChatGPT to fill in forms.

Creating a Form

First, you’ll need to create the form. Below is an example of this:

FormLayout formLayout = new FormLayout();

TextField nameField = new TextField("Name");
nameField.setId("name");
formLayout.add(nameField);

TextField addressField = new TextField("Address");
addressField.setId("address");
formLayout.add(addressField);

TextField phoneField = new TextField("Phone");
phoneField.setId("phone");
formLayout.add(phoneField);

TextField emailField = new TextField("Email");
emailField.setId("email");
formLayout.add(emailField);

DateTimePicker dateCreationField = new DateTimePicker("Creation Date");
dateCreationField.setId("creationDate");
formLayout.add(dateCreationField);

DatePicker dueDateField = new DatePicker("Due Date");
dueDateField.setId("dueDate");
formLayout.add(dueDateField);

ComboBox<String> orderEntity = new ComboBox<>("Order Entity");
orderEntity.setId("orderEntity");
orderEntity.setItems("Person", "Company");
formLayout.add(orderEntity);

NumberField orderTotal = new NumberField("Order Total");
orderTotal.setId("orderTotal");
formLayout.add(orderTotal);

TextArea orderDescription = new TextArea("Order Description");
orderDescription.setId("orderDescription");
formLayout.add(orderDescription);

RadioButtonGroup<String> paymentMethod = new RadioButtonGroup<>("Payment Method");
paymentMethod.setItems("Credit Card", "Cash", "Paypal");
paymentMethod.setId("paymentMethod");
formLayout.add(paymentMethod);

Checkbox isFinnishCustomer = new Checkbox("Is Finnish Customer");
isFinnishCustomer.setId("isFinnishCustomer");
formLayout.add(isFinnishCustomer);

CheckboxGroup<String> typeService = new CheckboxGroup<>("Type of Service");
typeService.setItems("Software", "Hardware", "Consultancy");
typeService.setId("typeService");
formLayout.add(typeService);

Grid<OrderItem> orderGrid = new Grid<>(OrderItem.class);
orderGrid.setId("orders");

formLayout.add(orderGrid);

Filling the Form

Here are some examples of how the form might be filled in. This first example is a common use case:

FormFiller formFiller = new FormFiller(formLayout);
FormFillerResult result = formFiller.fill(input);

This next example involves adding extra instructions:

FormFiller formFiller = new FormFiller(formLayout, fieldsInstructions, contextInformation);
FormFillerResult result = formFiller.fill(input);

This last example is one using a different model:

FormFiller formFiller = new FormFiller(formLayout, new ChatGPTService());
FormFillerResult result = formFiller.fill(input);