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.
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.
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 texttext-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-003
to 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.
- click inCreate a new secret keyto create a new API key.
- Copy the API key and save it safely for later use in the tutorial.
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 name
my-jellyfish-shop
and 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/products
in 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.
In this section, you will create a subscriber on your Medusa server that will listen to theproduct.created
Event. 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-003
Sprachmodell.
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_KEY
on them.env
File on your Medusa server:
OPENAI_API_KEY=Your API-key-here
Note: Substitute the value of
Your-API-key-here
with 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.js
file insideOrigin/subscribers
directory 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 theBuilding
class ofopen
module and then create a new oneBuilding
object with theBuilding
Class. TheBuilding
-The object is initialized with an API key for the OpenAI API.
It also defines a part calledSubscriber Description
containing a constructor and two methods:handle description
yDescription of preparation
.
Dieconstructor
The method subscribes to an event calledproduct.created
Use ofeventBusService
and claims that thehandle description
method must be called when this event is emitted.
Diehandle description
The method is an asynchronous function called with aData
Dispute. as mentionedin the documentation, the event data payload, i. h thereData
The argument contains only theI would like to
of the created product. This method obtains a product ofproduct / service
Use ofI would like to
Property ofData
Object.
If hedesignation
of the product isNull
, the method generates a description usingDescription of preparation
and update the product with the new description.
Description of preparation
is 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 theOpenAIApi
Class used to communicate with the OpenAI API and then callscompletion of creation
in 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:
- 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:7000
in your browser to open the admin panel.
Since you've already seeded the data on your Medusa server, you're ready to use email.admin@medusa-test.com
and passwordSupergeheim
Begin session.
- click no
products
tab on the left and then click the buttonNew product
Knopf.
- Enter the product details, including at least the title, subtitle and material, and click Publish Product.
After publishing a product without a description, your product will initially be created with an empty description. Theproduct.created
The event is then emitted and theSubscriber Description
it triggers.
Since the description is empty, the subscriber uses theDescription of preparation
Function 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.
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.
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