# Generate ChatGPT Message

## Overview

This rule runs after a location and time is collected on `Step 1` and the step is submitted. The field entries are used to query ChatGPT to generate a customized invite message that is editable in a [text area](/platform/build-forms/elements/fields/text-area.md) field on `Step 2`.

This pattern can be used to integrate with any AI service to generate any content from any user inputs.

## Rule Logic

```
const location = AILocation.value;
const time = AITime.value;
const eventType = AIEventType.value;

const res = await feathery.http.POST('https://api.openai.com/v1/chat/completions', {
    "model": "gpt-3.5-turbo",
    "messages": [
      {
        "role": "system",
        "content": "You are a friendly event planner. Maximum 50 word responses."
      },
      {
        "role": "user",
        "content": `Create an invitation message for an event. The location is ${location}. The time is ${time}. The event type is ${eventType}.`
      }
    ]
})

AIMessage.value = res.choices[0].message.content;
```

## API Connector

Under the API connectors tab, create a connector with the following configuration:

* Base URL: <https://api.openai.com/v1>
* Allowed Endpoints: `/chat/completions`
* Headers:
  * `Authorization`: `Bearer {{OPENAI_API_KEY}}`

Fill in `{{OPENAI_API_KEY}}` with your OpenAI API key.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.feathery.io/platform/build-forms/advanced-logic/examples/api-connectors/generate-chatgpt-message.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
