How can I use ChatGPT to generate product descriptions in Hygraph?
You can integrate ChatGPT with Hygraph by creating a custom field element that leverages OpenAI's completion API. This allows you to automatically generate product descriptions for your ecommerce system, saving significant time and creative effort. The integration involves setting up a Hygraph project, adding a custom field, and configuring an API endpoint to call ChatGPT for description generation. For a step-by-step guide, see the official documentation.
What are the prerequisites for integrating ChatGPT with Hygraph?
To use this integration, you need:
A Hygraph account and project
Familiarity with Next.js and React.js
Node.js (version 14.6.0 or newer) and npm (version 9.5.0)
An OpenAI API key
Apps are environment-specific, so configuration is applied per environment. For more details, see the prerequisites section.
What steps are involved in setting up Hygraph for AI-generated product descriptions?
The setup process includes:
Creating a Hygraph project using the Commerce Shop starter
Cloning the Hygraph React.js example project from GitHub
Modifying GraphQL queries to retrieve product data
Developing a custom field element and sidebar element using Hygraph's app framework
Registering and installing the custom app in your Hygraph project
Adding the custom field to the product schema
Configuring the API to call ChatGPT and updating the UI to display the generated description
How does the custom field element work for generating AI product descriptions?
The custom field element is a String field with a "Generate Description" button. When clicked, it builds a prompt from product data and calls the OpenAI API to generate a marketing description. The generated text is then populated into the field for review and publishing. You can customize the prompt and field behavior to suit your needs. See the Field element API Reference for more details.
Can I customize the prompt sent to ChatGPT for product descriptions?
Yes, you can modify the prompt based on available product data such as name, slug, description, price, and variants. The tutorial provides sample code for building dynamic prompts, and you can experiment with different prompt formats to achieve your desired output. The full source code is available on GitHub.
How do I secure the API used for generating product descriptions?
The sample API provided in the tutorial is not secure by default. You should add authentication and authorization checks to ensure only authorized users can access the endpoint. Consider using environment variables for sensitive keys and deploying the API on a secure production server. For more security best practices, refer to Hygraph's security features page.
Features & Capabilities
What are the key features of Hygraph for AI and automation?
Hygraph offers a flexible app framework, custom field elements, and integration capabilities with AI services like ChatGPT. Its GraphQL-native architecture, content federation, and Smart Edge Cache ensure high performance and scalability. For automation, you can build custom workflows, integrate third-party APIs, and extend the CMS with custom apps. Learn more at Hygraph Features.
Does Hygraph support integration with other AI tools besides ChatGPT?
Hygraph's app framework and API-first design allow integration with various AI and automation tools, provided you can connect via API. While the documentation focuses on ChatGPT, similar approaches can be used for other AI services. For more on integrations, see Hygraph Integrations.
Technical Requirements
What technical skills are required to implement the ChatGPT integration with Hygraph?
You should be familiar with Next.js, React.js, Node.js (14.6.0+), and npm (9.5.0+). Experience with API development and handling authentication is recommended. The integration involves modifying code, setting up custom fields, and deploying APIs. For detailed steps, see the integration guide.
Are there any environment-specific considerations when installing apps in Hygraph?
Yes, apps in Hygraph are environment-specific, meaning their configuration applies per environment. If your project uses multiple environments (e.g., staging, production), you must configure the app separately for each. For more details, see the prerequisites section.
Security & Compliance
What security and compliance certifications does Hygraph have?
Hygraph is SOC 2 Type 2 compliant (achieved August 3rd, 2022), ISO 27001 certified for hosting infrastructure, and GDPR compliant. These certifications demonstrate Hygraph's commitment to secure and compliant content management. For more details, visit the security features page and security report.
How does Hygraph ensure data security for AI-generated content?
Hygraph provides granular permissions, SSO integrations, audit logs, encryption at rest and in transit, and regular backups. Enterprise-grade compliance features include dedicated hosting, custom SLAs, and support for GDPR and CCPA. For transparency, Hygraph offers a process for reporting security issues and provides a public security report. Learn more at Hygraph Security.
Support & Implementation
What support and resources are available for implementing AI integrations in Hygraph?
Hygraph offers 24/7 support via chat, email, and phone, real-time troubleshooting through Intercom chat, a community Slack channel, extensive documentation, webinars, live streams, and how-to videos. Enterprise customers receive a dedicated Customer Success Manager and a structured onboarding process. Access documentation at Hygraph Documentation and join the community on Slack.
How long does it take to implement an AI integration with Hygraph?
Implementation time varies by project scope. For example, Top Villas launched a new project within 2 months, and Si Vale met aggressive deadlines during their initial implementation. Hygraph's free API playground and developer account allow teams to start immediately. Structured onboarding and training resources further accelerate adoption. See Top Villas case study for details.
Use Cases & Benefits
Who can benefit from using Hygraph's AI integration for product descriptions?
Developers, product managers, and marketing teams in ecommerce, automotive, technology, food and beverage, and manufacturing industries can benefit. Hygraph is ideal for businesses seeking to modernize legacy tech stacks, scale content operations, and deliver consistent, high-quality product descriptions across channels. For more on target audiences, see the integration guide.
What problems does Hygraph solve for ecommerce product content teams?
Hygraph eliminates developer dependency for content updates, streamlines workflows, and accelerates speed-to-market. It reduces operational costs, supports scalability, and enables integration with AI tools for automated product descriptions. Content federation ensures consistency across global teams. For more, see CMS KPIs blog.
Performance & Usability
How does Hygraph perform for high-traffic and global ecommerce sites?
Hygraph's Smart Edge Cache and high-performance endpoints ensure fast, reliable content delivery for high-traffic and global audiences. The platform measures GraphQL API performance and provides optimization guidance for developers. For more details, see the performance improvements blog.
Is Hygraph easy to use for non-technical users?
Yes, Hygraph is frequently praised for its intuitive user interface and accessibility for non-technical users. Customers report that it's easy to set up and use, even without technical expertise. Hygraph was recognized for "Best Usability" in Summer 2023. For more feedback, see customer reviews.
Customer Success & Metrics
Can you share some customer success stories with Hygraph?
Yes. Komax achieved a 3X faster time-to-market, Autoweb saw a 20% increase in website monetization, and Samsung improved customer engagement by 15% with a scalable platform. Stobag increased online revenue share from 15% to 70%. For more, see customer stories.
What KPIs and metrics are associated with Hygraph's solutions?
Key metrics include time saved on content updates, reduction in operational costs, speed-to-market, system uptime, user satisfaction scores, and scalability metrics. For example, Komax managed over 20,000 product variations across 40+ markets via a single CMS. For more KPIs, see the CMS KPIs blog.
If you have an online shop, you might want to consider using AI to generate your product descriptions. With the Hygraph headless CMS, you can easily create and fill custom fields with ChatGPT-generated text, saving you significant time and creative energy.
Apps are environment specific. This means their configuration is applied per environment. Take this into consideration if you're working with a project using more than one environment.
#Setting up Hygraph for AI-generated product descriptions
You can access the code for this project on GitHub.
Log into your Hygraph account and create a new project using the Commerce Shop starter. Give it a name - this tutorial uses My Clothing Shop - and add a description.
Keep the Include Template Content checkbox selected, use the dropdown to select a region to host the project, and click Add Project.
Once your project is built, navigate to Project settings > Access > Endpoints, and make note of the content endpoint; you'll use it to retrieve data.
As mentioned earlier, this tutorial uses a custom field element to generate a product description. While field elements can have various extension types — String, Integer, Float, JSON, or complex types that combine several fields into one component — this tutorial uses a String field element, shown as a text box with a Generate Description button.
We'll use Hygraph's boilerplate project to develop a simple custom field that will allow the user to store and get a String.
Run the following command to generate a Next.js project containing a starter field element and sidebar element:
This is what the created directory structure looks like:
Directory structure of project
Pro Tip
The pages/setup.tsx file includes the code that runs when this app is installed for a project.
The basic field element code is located in pages/field.tsx.
The sidebar element code is located in pages/sidebar.tsx.
A standard pages/api/hello.ts file implements an API.
Hygraph offers three node modules for use in the app framework code:
@graphcms/app-sdk: This contains SDK components like AppProps, FieldExtensionProps, and FormSidebarExtensionProps that give access to often-requested properties for the app, such installation status or access to the form data.
@graphcms/app-sdk-react: This module exposes the SDK components as custom React hooks.
@hygraph/baukasten: The node modules under @hygraph have to do with UI and rendering. They include layouts, rendering components like Input and TextArea, icons, and themes, among others.
We'll use the boilerplate setup code for this tutorial, but you can change it to suit your needs. For instance, you could change it so that the OpenAI secret key is configured rather than hardcoded.
Here's the boilerplate code in field.tsx:
<Flex>
<Input
placeholder="Type something here"
value={value ||""}
onChange={(e: any)=>onChange(e.target.value)}
/>
</Flex>
Flex is a layout and Input is a rendering component provided by Hygraph in the @hygraph/baukasten package. The rendering components shown in the following screenshot are also provided by Hygraph:
hygraph/baukasten package
The FieldExtensionProps offered by @graphcms/app-sdk allows you to access the form data and events like onChange and onBlur. When the data in the input field is changed, the boilerplate code calls the API's onChange method, which stores the modified data in the form.
As you can see, the boilerplate only provides a button that displays an alert after clicking. For now, let's just run the server with the boilerplate as is and configure the app.
Run npm install, then npm run dev in the autofill description directory to launch the server on port 3000 by default.
When you access the URL directly in the web browser (eg. http://localhost:3000/setup), you'll encounter the SDK connection error, check logs error. You must use Hygraph for access.
To create the app, select the ecommerce project you created from your Hygraph dashboard. Select Apps from the sidebar, then click Add new app.
Note that after your app is created, you can't alter the permissions. For this tutorial, select read/write access for all options.
In the General tab, add the field element providing the following details:
Name: Auto Fill Description
Description: A String field element to generate descriptions using ChatGPT
Click on the install icon next to the app. A dialogue displays where you need to select the project you created previously (My Clothing Shop), then select Master Environment. Finally, click on Install app.
App install
A dialogue will appear, where you need to provide the app with the permissions you selected when you created it.
The setup page from the boilerplate code displays after authorization, with the Install component code first. Click Install App, then the Configure component code will appear.
Setup page
Click Save to install the app on your project.
The custom field element included in the boilerplate code is now available for use in this project.
Navigate to the Schema builder, then select the Product model. You will find the custom field on the Add fields right sidebar, listed as Generate Description under STRING. Click on it to add it to the Product model.
Add description field
As soon as the field is successfully added to the Product model, it will be available in the Content editor.
You want a click on Generate Description to build a prompt based on information from the other product fields. ChatGPT's gpt-3.5-turbo model will then call OpenAI's completion API to generate a description. The additional product field values will pass to this API using Next.js's dynamic routing feature.
A hypothetical URL to call the API might be http://localhost:3000/api/gpt/backpack/back-pack/, which includes the product name and slug. This tutorial will design the API to accept product name, slug, description, price, and variants.
First, register and create an OpenAI API key. Copy the generated key to use later.
OpenAI API Key
Create a directory called gpt under pages/api, then create a file called [...product].ts under this directory. You can refer to OpenAI's chat completion API for the code to call OpenAI.
Use npm install openai --save to install the OpenAI node module. Edit your [...product].ts file and add this function to call OpenAI for a given prompt and return the completion as a String:
Edit pages/fields.tsx to invoke the API you just developed with the appropriate parameters.
The form variable is available in FieldExtensionProps, which you can use to access the other values in the form. Declare the form variable in the custom hook together with value and onChange (const value, form, onChange = useFieldExtension();). The async function getState() returns all of the values in the form.
Use these values to access additional fields in the Product object and build the API URL.
let api ="/api/gpt/"+ values.values.localization_en.name+"/"+ values.values.localization_en.slug;
api +="/"+ values.values.localization_en.description;
api +="/"+ values.values.localization_en.price;
fetch(api).then((res)=>{
const data = res.json();
data.then((content)=>{
console.log(content);
onChange(content);
});
});
});
}
The values are stored based on localization. In this instance, you've used localization_en values. You can change the function to accommodate other requirements, like using unsaved values and other locale data. Following that, the code calls fetch to invoke the API and retrieve a description. The onChange method sets this as the content of the text area in the custom field element.
Now refresh the Product's content creation screen and click Generate Description. ChatGPT should generate a description and populate it into the text box.
Generated description
Click on Save and then publish the product to save and publish the AI description.
You can now change the ecommerce React.js app you created earlier to show aiProductDescription instead of description—modify the GraphQL in App.js to use aiProductDescription instead of description, and modify Product.js to use product.aiProductDescription instead of product.description.
Load your app page, and it should show the description generated.
Pro Tip
Keep in mind that this tutorial uses your local machine to test the custom
field element. This has to be productionalized (ie. installed, configured,
secured) and then deployed onto a production server. After that, you can
change the app details as necessary to service all users.