> Markdown version of [Advanced Example](https://vaadin.com/docs/v24/tools/ai-form-filler/advanced-example). Section index: [llms.txt](https://vaadin.com/docs/v24/tools/llms.txt)

# Advanced Example

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

## <a id="creating-a-form"></a>Creating a Form

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

```java
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);
```

## <a id="filling-the-form"></a>Filling the Form

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

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

This next example involves adding extra instructions:

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

This last example is one using a different model:

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