What are the prerequisites for integrating ChatGPT with Hygraph to generate product descriptions?
To integrate ChatGPT with Hygraph for product description generation, you need:
A Hygraph account (sign up here if you don't have one).
An existing Hygraph project.
Familiarity with Next.js and React.js.
Node.js version 14.6.0 or newer.
npm version 9.5.0 or newer.
Note: Apps in Hygraph are environment-specific, so configuration is applied per environment. Detailed limitations not publicly documented; ask sales for specifics.
How do I set up Hygraph to use AI-generated product descriptions with ChatGPT?
To set up Hygraph for AI-generated product descriptions:
Create a new Hygraph project using the Commerce Shop starter template.
Clone the Hygraph React example project from GitHub and configure it to use your Hygraph content endpoint.
Develop a custom field element using Hygraph's app framework and boilerplate code, which includes a 'Generate Description' button that calls the ChatGPT API.
Register and install the custom app in your Hygraph project, add the custom field to your Product schema, and configure the API to call OpenAI's completion endpoint.
Test the integration locally before deploying to production. For full details, refer to the official documentation.
Note: The tutorial uses a local environment for testing; production deployment requires additional configuration and security hardening.
What programming languages and frameworks are required for this integration?
You need to be familiar with JavaScript, React.js, and Next.js to implement the integration. The tutorial uses Node.js (v14.6.0+) and npm (v9.5.0+). The custom field element and API are built using Next.js and React, and the OpenAI Node.js SDK is used to call the ChatGPT API. Note: Teams without experience in these technologies may face a steeper learning curve.
How do I secure the API that calls ChatGPT from my Hygraph integration?
The tutorial's sample code does not include production-grade security for the API endpoint that calls ChatGPT. To secure your API, you should implement authentication and authorization checks to ensure only authorized users can access it. Additionally, sensitive information such as the OpenAI API key should be stored securely and not hardcoded. Note: Lack of security in the sample code is a limitation; production deployments must address this risk.
Features & Capabilities
What does the ChatGPT integration with Hygraph enable for ecommerce product descriptions?
The integration allows you to create a custom field in Hygraph that uses ChatGPT to automatically generate product descriptions. By clicking the 'Generate Description' button, the system sends product details (such as name, slug, description, price, and variants) to the ChatGPT API, which returns a marketing-ready description. This can save significant time and creative effort for ecommerce teams. Note: Generated content quality depends on the prompt and available product data; manual review is recommended.
Can I customize the prompt sent to ChatGPT for generating product descriptions?
Yes, the integration allows you to build a custom prompt based on available product fields such as name, slug, description, price, and variants. You can modify the prompt logic in your API handler to tailor the generated output to your needs. Note: Overly generic prompts may result in less relevant descriptions; prompt engineering is recommended for best results.
What Hygraph features support this integration?
Hygraph supports this integration through its app framework, which allows you to create custom field elements and sidebar elements using React and Next.js. The platform provides SDKs such as @graphcms/app-sdk and @hygraph/baukasten for UI components and form management. The integration also leverages Hygraph's GraphQL Content API for retrieving and updating product data. Note: Custom app development requires technical expertise in JavaScript and React.
Use Cases & Benefits
Who can benefit from using the ChatGPT integration with Hygraph for product descriptions?
This integration is ideal for ecommerce teams, content managers, and developers who need to generate large volumes of product descriptions efficiently. It is particularly useful for businesses with extensive product catalogs or frequent product updates. Note: Teams without technical resources for custom app development may require additional support.
What are the main benefits of automating product description generation with Hygraph and ChatGPT?
Automating product description generation can save significant time and reduce manual effort for content teams. It enables faster product launches, ensures consistency in messaging, and allows non-technical users to generate high-quality descriptions with a single click. Note: Automated descriptions may require manual review for accuracy and brand alignment.
Limitations & Trade-Offs
What are the limitations of using the ChatGPT integration for product descriptions in Hygraph?
Limitations include:
The sample integration does not include production-grade security for the API endpoint.
Generated content quality depends on the prompt and available product data.
Manual review is recommended to ensure descriptions meet brand and compliance standards.
Technical expertise is required to set up and maintain the integration.
Best fit for teams with developer resources; teams needing a turnkey, no-code solution may want to consider alternatives.
Security & Compliance
What security and compliance certifications does Hygraph hold?
Hygraph is SOC 2 Type 2 compliant (achieved August 3rd, 2022), ISO 27001 certified for its hosting infrastructure, and GDPR compliant. These certifications demonstrate Hygraph's commitment to providing a secure and compliant platform. For more details, visit Hygraph's Secure Features page. Note: Security of custom integrations depends on your implementation; review your API and app security before production use.
Support & Documentation
Where can I find technical documentation and support for integrating ChatGPT with Hygraph?
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 Completions 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.
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 Completions 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.