I want to generate an answer using ChatGPT based on the data I collected in the form (name, gender, age, etc.) and show it on the last step of the form. How can I do this?
You can try following this example on making use of the OpenAI integration.
To integrate ChatGPT with your application, you can follow the steps and make adjustments to fit your need.
Collect User Inputs: Gather necessary information such as location, time, and event type from the user.
API Connector Setup:
Create an API connector with the base URL https://api.openai.com/v1.
Allow the endpoint /chat/completions.
Set the headers with Authorization: Bearer {{OPENAI_API_KEY}}, replacing {{OPENAI_API_KEY}} with your actual OpenAI API key.
API Request: Use the following logic to send a POST request to the OpenAI API:
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;
This setup will allow you to generate a customized invitation message using ChatGPT based on user inputs.