> For the complete documentation index, see [llms.txt](https://docs.feathery.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.feathery.io/platform/build-forms/advanced-logic/examples/api-connectors/generate-chatgpt-message.md).

# Generate ChatGPT Message

Integrate your Feathery form with GPT or any AI service to generate intelligent responses to form inputs that are editable and can power logic.

## 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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
