Generating Product Descriptions Using TextCortex API

Ceyhun Derinbogaz
March 14, 2022

We are eager to add new features to our API. Our newest API solution is advanced product descriptions.

There are multiple ways to use the TextCortex API. At the core of interaction is the "prompt" that gives instruction to our AI models about what it should create.

Generating Product Description using the advanced API

What is the advanced product description API:

Our users need a tool that is reliable in it's output and serves them in what they need. While in the past we used only "product titles" to generate descriptions. We have now added "product features" which can be added to make more accurate descriptions and keep a high input to output relevancy for our users.

At the core of every API call is the "prompt" which tells our AI models what they should write about. In general, more information helps the AI to create better and more relevant text to your needs.

If you have created your "prompt", you just need send it to our API endpoint with the API key.

Let's say your product details are like the following:

Product Name: Gucci Skinny women jeans

Brand: Gucci

Category: 'Clothing, Shoes & Jewelry', 'Women'

Features: 'Size: Medium', 'Color: Pink', 'Style:Slim Fit', 'Materials:Cotton 98%, Elastane 2%'

in this case you need to build a complete string like the below to send to our API. Complete Prompt for that would be:

Product name: 'Gucci Skinny women jeans' Brand: 'Gucci' Category: ['Clothing, Shoes & Jewelry', 'Women'] Features: ['Size: Medium', 'Color: Pink', 'Style:Slim Fit', 'Materials:Cotton 98%, Elastane 2%'] Product Description:


# An example about how to build the prompt programatically using python

product_name = 'Gucci Skinny women jeans'
brand = 'Gucci'
features = ['Size: Medium', 'Color: Pink', 'Style:Slim Fit', 'Materials:Cotton 98%, Elastane 2%']
category = ['Clothing, Shoes & Jewelry', 'Women']

prompt = 'Product name: "' + product_name + '" Brand: "' + brand + \
						 '" Category: ' + str(category) + \
             ' Features: ' + str(features) + ' Product Description:'

# You can use our python package to directly generate text
from textcortex import TextCortex

hemingwai = TextCortex(api_key='YOUR_API_KEY')
generate_content = hemingwai.generate(prompt=prompt, target_segment='', character_count=1152,
                                      source_language='en', creativity=0.7)

print(generate_content)
'''
Output:
[{'generated_text': "  This pair of women's jeans from Gucci is perfect for the modern woman who wants to look great while still being comfortable. The classic slim-fit design is made of high quality fabric that feels soft to the touch. The pink color is perfect for any outfit and can be paired with everything from a simple white shirt to a pair of heels.", 'rank': 0.7143, 'text_length': 336, 'word_frequency': [], 'word_count': 62}]
'''

Method 1: Request-Response with product features:

In order to achieve high input to output relevancy it

As mentioned earlier it is important to keep the general prompt structure and add the product information within the pipeline accordingly from your data management system into our API.

In the below Request-Response example, you can see that within the call's "prompt" there is a defined structure of features that must be kept and send as a string to our API.

For example, if you have detailed product features at your disposal, you can send a prompt like the following:


curl -XPOST -H "Content-type: application/json" -d 
'{ 
"prompt": "Product name: 'Gucci Skinny women jeans' 
Brand: 'Gucci' Category: ['Clothing, Shoes & Jewelry', 'Women'] 
Features: ['Size: Medium', 'Color: Pink', 'Style:Slim Fit', 'Materials:Cotton 98%, Elastane 2%'] 
Product Description:",

"category": "Product Description",
"target_segment": "",
"source_language": "auto",
"creativity": 0.7,
"character_count": 512,
"api_key": "YOUR_API_KEY"
}' 
"https://api.textcortex.com/hemingwai/generate_text"

Response


{
    "status": "success",
    "ai_results": [
        {
            "generated_text": "  The Gucci jeans are the perfect combination of comfort and style. Made from soft and supple cotton with a slim fit, these women’s jeans will ensure you look and feel your best.",
            "rank": 0.6757,
            "text_length": 178,
            "word_frequency": [],
            "word_count": 32
        }
    ],
    "error": 200
}

Method 2: Request-response working with sparse data aka. what if you do not have all product features:

In case you don't have enough product data, you can send only the "product title" to get product description.

As the AI does not have instructions on product features it might include or use common characteristics related to the product.

In order to control and maintain a high input to output relevancy add as much information to the model as possible. Similar to a human the more instruction and onboarding somebody has to a task, the better and faster they can operate.

Request:


curl -XPOST -H "Content-type: application/json" -d 
'{ 
"prompt": "Product name: 'Balenciaga Mens Sports Shoes - Black'",
"category": "Auto Complete",
"target_segment": "",
"source_language": "auto",
"creativity": 0.7,
"character_count": 512,
"api_key": "YOUR_API_KEY"
}' 
"https://api.textcortex.com/hemingwai/generate_text"

Response:


{
    "status": "success",
    "ai_results": [
        {
            "generated_text": "  The Gucci jeans are the perfect combination of comfort and style. Made from soft and supple cotton with a slim fit, these women’s jeans will ensure you look and feel your best.",
            "rank": 0.6757,
            "text_length": 178,
            "word_frequency": [],
            "word_count": 32
        }
    ],
    "error": 200
}

That's it! You made it :) If you like to work on an easier way of generating content programatically, check out our Python and Javascript packages:

TextCortex Text Generator Python Package

TextCortex Text Generator Javascript Package

Your AI partner is ready to write content.

Save time and grow business using TextCortex. Generate marketing and website content in seconds using AI today.

Start writing with AI