Generate Choice Options Using AI
AI-powered services have become ubiquitous in the modern digital world. Chatbots and assistants, such as ChatGPT, DeepSeek, and Microsoft Copilot, help users with writing and coding; voice recognition services transcribe speech to text; neural networks generate images based on descriptions. This demo shows how you can integrate an AI service into Survey Creator to generate choice options for Dropdown, Radio Button Group, and Checkboxes questions based on the provided question title. Click one of the questions on the design surface and select AI → Generate choices by title or Generate more choices. Another AI-based feature that may be useful for survey authors is spell correction. To test this functionality, make an error in a question title or choice option text and select AI → Fix grammar errors.
AI service integration starts with deploying a language model to your application and exposing an API for interaction with that model. Refer to tutorials dedicated to the model of your choice for instructions. This example uses the GPT-3.5 Turbo model deployed on the SurveyJS website.
A deployed AI model receives text prompts and responds with text completions. Your client-side code should construct the text prompts and send them to the model. For example, a prompt to fix spelling errors may look as shown below. Note the addition of the expected response format:
"Fix grammar errors in the 'choices' and 'title' fields: { title: "...", choices: [ ... ] }. Use JSON format as output."
Once the AI service sends back a text completion with a JSON object, update the required question properties (title
and choices
in this demo). Refer to the Code tab for a code example.