Create automated product descriptions using ChatGPT, React and Node.js (2023)

Create automated product descriptions using ChatGPT, React and Node.js (1)

In today's fast-paced e-commerce world, it's more important than ever to have compelling product descriptions that clearly and accurately convey the value of your offerings. However, creating effective descriptions can be time-consuming, especially if you have a large product catalog. this and whereChatGPTadvance

With ChatGPT, you can easily automate the writing of your product descriptions, saving time and effort while providing top-notch content to your customers. What if I told you that the paragraph above was written by ChatGPT? Did you see how ChatGPT generated human text that is indistinguishable?

In this tutorial you will learn how to use ChatGPT to automate the writing of your product descriptionsMedusa. jellyfish is aE-commerce that can be composedPlatform that can be integrated with all third-party services, including ChatGPT.

Tutorial code can be found atthis deposit.

Here is a demo of the final result.

Create automated product descriptions using ChatGPT, React and Node.js (2)

Medusait is open sourcecomposableCommerce engine for developers who want to take charge of their ecommerce stack. The platform is highly extensible and easy to customize, making it the #1 JavaScript eCommerce platform on Github with over 16,000 stars in record time.

Medusa consists of three components: the headless backend, the admin panel, and theshowcase. You can set up an entire eCommerce store in minutes just by running a few commands.

As Medusa is very extensible, it allows developers to create custom functions or integrate third-party services like ChatGPT into Medusa very easily. You can learn more about official and community plugins.on here.

open AIdeveloped a revolutionary long-form Q&A AI called ChatGPT; Is able to answer complex questions in a conversation. This technology is innovative because it has been trained to understand the intended meaning behind human issues.

ChatGPT (Generative Pretrained Transformer) is a powerful artificial intelligence tool that leverages the capabilities of the OpenAI GPT 3.5 family of large language models. It has been tuned using a combination of reinforcement and supervised learning techniques for optimal performance.

(Video) How To Use ChatGPT With JavaScript (NodeJS & Express)

Various models offered by GPT-3

DieGPT-3 Language Templateshave the ability to understand and produce natural language. There are four main language models available, each with different levels of performance and features to suit different tasks.

  • text-davinci-003: It is the most advanced and powerful language model in the GPT-3 family. It is capable of performing any task that other models can perform, often with higher quality, longer life and better ability to follow instructions. In addition, you have the possibility to insert conclusions within the text
  • text-curie-001: It is very powerful, but faster and cheaper than Davinci.
  • text-babbage-001: You can perform simple tasks efficiently and at a lower cost compared to other models.
  • text-ada-001: Capable of performing simple tasks quickly and economically. It is generally the fastest model in the GPT-3 family.

Of the four above, use thetext-davinci-003to complete the text in this tutorial as it gives the best results.

OpenAI offers several APIs to interact with your AI models. It gives you $18 of free credit to try for the first three months.

Follow the steps below to get your free OpenAI API key:

  • Go toOpenAI-APIand sign up for a free account. Follow the instructions and you will be redirected to the API dashboard.
  • Click on your profile picture to reveal the menu bar, then click onView API Keyto takeAPI da KeyPage.
Create automated product descriptions using ChatGPT, React and Node.js (3)
  • click inCreate a new secret keyto create a new API key.
Create automated product descriptions using ChatGPT, React and Node.js (4)
  • Copy the API key and save it safely for later use in the tutorial.
Create automated product descriptions using ChatGPT, React and Node.js (5)

Before starting the tutorial, you must have the following installed:

In this section, you will create a Medusa server on which you will integrate ChatGPT in the next step.

Configuring your Medusa server

  • Create a new Medusa store with the namemy-jellyfish-shopand seed the test data with the following command:
new jellyfish my-jellyfish-store --seed
  • Start your Medusa server with the following command:
cd mein-medusa-store
develop jellyfish

The two steps above will take a few minutes to get your server up and running on port 9000. You can test your server by going tohttp://localhost:9000/store/productsin your browser or by running the following command:

curl localhost:9000/store/products

If you get a list of products, your server is configured correctly.

(Video) How I Used Chat GPT to Write Good Product Descriptions That SELL

In this section, you will create a subscriber on your Medusa server that will listen to theproduct.createdEvent. The subscriber then calls a function to handle the product description field. If the description field is empty, another function will be called to interact with the ChatGPTs.text-davinci-003Sprachmodell.

While you can directly interact with the models through its APIs, OpenAI also offers severalofficiallyycommunity librariesfor different languages.

Install the official OpenAI library on your Medusa server:

npm install openai

addOPENAI_API_KEYon them.envFile on your Medusa server:

OPENAI_API_KEY=Your API-key-here

Note: Substitute the value of Your-API-key-herewith a valid API key obtained from OpenAI earlier in the tutorial.

Since you will be creating a subscriber on your Medusa server, make sure you have Redis onmedusa-config.js:

module.exports = {
project configuration: {
redis_url: REDIS_URL, // Enable Redis here
//...
},
complements,
};

To... createDescription.jsfile insideOrigin/subscribersdirectory on the Medusa server and add the following content:

import {config, OpenAIApi} from "openai";

constant configuration = new configuration ({
apiKey: process.env.OPENAI_API_KEY, // Reemplace con su clave API
});

Class DescriptionSuscriptor {
Construtor ({ productService, eventBusService }) {
this.productService_ = productService;
eventBusService.subscribe("product.created", this.handleDescription);
}
handleDescription = async(data) => {
let ProductDescription = "";

produto const = espera this.productService_.retrieve(data.id);
if (product.description == null) {
Try {
const productName = product.title;
const productFeatures = [product.subtitle, product.material];
const prompt = `Write a product description for ${productName} that has the following features: ${productFeatures.join(
", "
)}.`;

productDescription = esperar esto.prepareDescription(prompt);
} catch (error) {
const errorMessage = error.response.data.error.message;
console.error("Error: " + error message);
Return;
}

product.description = product description;
Aguardando this.productService_.update(product.id, producto);
}
};

PrepareDescription = async(
opportune,
model = "text-davinci-003",
Temperature = 0.7,
max tokens = 256,
upper P = 1,
Frequency penalty = 0,
Assist Penalty = 0
) => {
const openai = new OpenAIApi(configuration);

constant response = waiting for openai.createCompletion({
Model,
opportune,
at temperature,
max_tokens: maxtokens,
arrive_p: arriveP,
frequency_penal: frequency penalty,
Presence Penalty: Presence Penalty,
});

(Video) Let's Build ChatGPT 2.0 with React JS and OpenAI on your PC!

return response.data.options[0].text.trim();
};
}

Export Standard Description Subscriber;

In the code above you import theBuildingclass ofopenmodule and then create a new oneBuildingobject with theBuildingClass. TheBuilding-The object is initialized with an API key for the OpenAI API.

It also defines a part calledSubscriber Descriptioncontaining a constructor and two methods:handle descriptionyDescription of preparation.

DieconstructorThe method subscribes to an event calledproduct.createdUse ofeventBusServiceand claims that thehandle descriptionmethod must be called when this event is emitted.

Diehandle descriptionThe method is an asynchronous function called with aDataDispute. as mentionedin the documentation, the event data payload, i. h thereDataThe argument contains only theI would like toof the created product. This method obtains a product ofproduct / serviceUse ofI would like toProperty ofDataObject.

If hedesignationof the product isNull, the method generates a description usingDescription of preparationand update the product with the new description.

Description of preparationis an asynchronous function used to generate product descriptions with OpenAIText Completion API. The function takes several parameters as inputs:

  • opportune: a string that specifies the text message that the API should use as a starting point for text generation. In this case, the text that appears after the description of a product due to its characteristics such as name, material, etc.
  • model: (optional, Default:"text-davinci-003") a string that specifies the ID of the template that will be used to generate the text.
  • At temperature: (optional, Default:0,7) a float that specifies the sample temperature to use when generating the text.
  • maxTokens: (optional, Default:256) an integer specifying the maximum number ofSymbolic(i.e. words or word fragments) to be generated.
  • topP: (optional, Default:1) a floating point value that specifies the "top-p" value to use when generating text. Higher values ​​produce more conservative and deterministic output, while lower values ​​allow for more randomness and variety in the output.
  • Frequency Penalty: (optional, Default:0) a floating point value that specifies the frequency penalty to use when generating text. Higher values ​​produce more diverse outputs, while lower values ​​allow the model to reuse tokens more frequently.
  • assist penalty: (optional, Default:0) a floating point value that specifies the presence penalty to use when generating text.

The function creates an instance of theOpenAIApiClass used to communicate with the OpenAI API and then callscompletion of creationin this case, to generate text.

After making the necessary changes to your Medusa server, you need to create your project with the following command:

npm-Run-Create

You can then restart your server with the following command:

develop jellyfish

You can test the process in Medusa Admin as well as inmanagement API. In that case, try Medusa Admin.

Medusa Admin is an intuitively designed admin panel for your Medusa eCommerce server. Medusa Admin is based on Vite 3 and React. It allows merchants to manage their data such as products, orders, discounts, regions and much more.

Follow the steps to configure your Medusa Admin and create products:

(Video) A Beginner’s Guide to Integrating ChatGPT with Node.js

  • Clone the Medusa Admin GitHub repository and change its path to the cloned directory:
Git-Klon https://github.com/medusajs/admin mi-medusa-admin cd mi-medusa-admin
  • Install the dependencies with the following command:
install npm
  • Once all dependencies are installed, run the management server with the following command:
Start running npm

Medusa Admin runs on port 7000 so go tohttp://localhost:7000in your browser to open the admin panel.

Create automated product descriptions using ChatGPT, React and Node.js (6)

Since you've already seeded the data on your Medusa server, you're ready to use email.admin@medusa-test.comand passwordSupergeheimBegin session.

  • click noproductstab on the left and then click the buttonNew productKnopf.
Create automated product descriptions using ChatGPT, React and Node.js (7)
  • Enter the product details, including at least the title, subtitle and material, and click Publish Product.
Create automated product descriptions using ChatGPT, React and Node.js (8)

After publishing a product without a description, your product will initially be created with an empty description. Theproduct.createdThe event is then emitted and theSubscriber Descriptionit triggers.

Since the description is empty, the subscriber uses theDescription of preparationFunction to generate a description and update the product description.

Since the admin is configured to get the products immediately after product creation, before the subscriber runs, you must refresh the page to see the changes. You can customize the manager to refetch the product after creation to resolve this issue.

Create automated product descriptions using ChatGPT, React and Node.js (9)

In this tutorial, you learned how to use ChatGPT to automate your product description writing. You can add more product features like price, variants and more to create a more unique description.

(Video) Build and Deploy Your Own ChatGPT AI App in JavaScript | OpenAI, Machine Learning

This integration was facilitated by Medusa's composable architecture. You can learn more about Medusa from her.documentation. Here are some documents to get you started:

If you have any problems or questions about Medusa, please email the Medusa team discord

Videos

1. ChatGPT Tutorial for Developers - 38 Ways to 10x Your Productivity
(Programming with Mosh)
2. How to Use ChatGPT to Automate Writing your Product Description in Medusa
(Ashutosh Krishna)
3. I sold my OpenAI GPT Website for $30,000
(Adrian Twarog)
4. ChatGPT for developers: Develop Nodejs API
(🌴 i-novotek Academy 🌹)
5. Building an AI App with ChatGPT, React Native, and NextJS (tutorial)
(notJust․dev)
6. ChatGPT Clone with React - OpenAI API and React Tutorial
(Cybernatico)
Top Articles
Latest Posts
Article information

Author: Van Hayes

Last Updated: 14/03/2023

Views: 6866

Rating: 4.6 / 5 (66 voted)

Reviews: 89% of readers found this page helpful

Author information

Name: Van Hayes

Birthday: 1994-06-07

Address: 2004 Kling Rapid, New Destiny, MT 64658-2367

Phone: +512425013758

Job: National Farming Director

Hobby: Reading, Polo, Genealogy, amateur radio, Scouting, Stand-up comedy, Cryptography

Introduction: My name is Van Hayes, I am a thankful, friendly, smiling, calm, powerful, fine, enthusiastic person who loves writing and wants to share my knowledge and understanding with you.