Loading...

Build intelligence in your eCommerce applications using Azure Open AI

Build intelligence in your eCommerce applications using Azure Open AI

Whenever I shop online, checking the reviews of the products is a tedious task. Sometimes the low-rated reviews are based on delivery, packaging... whereas a few high-rated reviews might be on cost but not on quality. Generally, reviews/ratings are displayed without any context which results in customers needing additional time and effort to get the most value out of it. Hence, we built this prototype using Azure Open AI to present the consolidated information from all the reviews of a product.

 

Azure-Open-AI.png

 

We fed all the reviews of a specific product to GPT-3 text-davinci-003 model with a prompt to classify the text based on the three categories – Cost, Quality, and Delivery. Prompt is where user provide the English text command which the API endpoint of the model will use to generate the completions. 

 

classify_prompt = f'Classify the following review into 1 of the following categories: categories: [Cost, Quality, Delivery]\n\unreview: {s}\n\nClassified category:' response = openai.Completion.create( engine="text-davinci-003", prompt=classify_prompt, temperature=0, max_tokens=100, top_p=1, frequency_penalty=0, presence_penalty=0, best_of=1, stop=None)

 

 

Similarly, we classified the sentiment of the text using the same model on three categories - Positive, Neutral, and Negative.

 

sentiment_prompt = f'Identify the sentiment in the following review into 1 of the following categories: categories: [Positive, Neutral, Negative]\n\nreview: {s}\n\nClassified category:' response = openai.Completion.create( engine="text-davinci-003", prompt=sentiment_prompt, temperature=0, max_tokens=100, top_p=1, frequency_penalty=0, presence_penalty=0, best_of=1, stop=None)

 

 

Here is the sample result after the category classification and sentiment detection of the review text.

 

ReviewSummarizationDF.png

 

As you notice, we are using the pre-trained model available in Azure Open AI service as is above. There are three main approaches for in-context learning: Few-shot, one-shot and zero-shot. In this case, we didn’t provide any examples to the model and only the task request is provided hence it’s zero-shot learning. Based on your requirement or pilot testing, you shall consider fine tuning the model using one of the available models for fine tuning.

 

Above category classification and sentiment detection job needs execution only once per review text and store the results for future use. Existing data shall be analyzed using one of the batch processing design options and real time events shall be analyzed using one of the real-time processing design options in Azure Architecture Center.

 

Now when a user requests for review intelligence, make an API call to Azure Open AI service to summarize the reviews per category as shown in the following command.

 

response = openai.Completion.create( engine="text-davinci-003", prompt=review_text, temperature=0.7, max_tokens=100, top_p=1, frequency_penalty=0, presence_penalty=0, best_of=1, stop=None)

 

 

Also consolidate the results from sentiment column per category to show the review intelligence summary below.

 

ReviewIntelligenceOutput.png

 

Another use case where Open AI service can bring value is on product search. First, get the embeddings of the product description text using get_embedding API with test-davinci-search-doc-001 model and store the result in a separate column named davinci_search.

 

df['davinci_search'] = df['product_description'].apply( lambda x : get_embedding(x, engine = 'text-davinci-search-doc-1'))

 

 

Below is the sample data frame after including the embeddings.

 

SearchEmbeddingsDF.png

 

Now using ordinary questions like text and using cosine similarity and text-search-davinci-query-001 model, we will retrieve the top four most relevant items as shown below.

 

def search_docs(df, user_query, top_n=3, to_print=True): embedding = get_embedding( user_query, engine='text-davinci-search-1' ) df['similarities'] = df.davinci_search.apply(lambda x: cosine_similarity(x, embedding)) res = ( df.sort_values('similarities', ascending=False) .head(top_n) ) return res res = search_docs(df, "feel good ear phone with good sound quality", top_n=4)

 

 

The above search request will return the results like the one shown below.

 

SearchOutput.png

 

Jupyter Notebook for this demo is available in this GitHub repo.

 

Below is an approach to extract data from your own knowledge base, create embeddings and use prompts to find the best answer to your customers.

Search-OpenAI.png

 

Conclusion:

In this post we have seen a demo of how easy it is to use Azure Open AI service to bring intelligence to your eCommerce Portal and provide better experience to your customers.

 

Citation:

In this demo, we used the dataset published as part of the following paper.

Justifying recommendations using distantly-labeled reviews and fined-grained aspects
Jianmo Ni, Jiacheng Li, Julian McAuley
Empirical Methods in Natural Language Processing (EMNLP), 2019

 

Published on:

Learn more
Azure Developer Community Blog articles
Azure Developer Community Blog articles

Azure Developer Community Blog articles

Share post:

Related posts

Azure Developer CLI (azd) – January 2026: Configuration & Performance

This post announces the January 2026 release of the Azure Developer CLI (`azd`). The post Azure Developer CLI (azd) – January 2026: Conf...

16 hours ago

Azure SDK Release (January 2026)

Azure SDK releases every month. In this post, you'll find this month's highlights and release notes. The post Azure SDK Release (January 2026)...

1 day ago

Azure Cosmos DB TV Recap – From Burger to Bots – Agentic Apps with Cosmos DB and LangChain.js | Ep. 111

In Episode 111 of Azure Cosmos DB TV, host Mark Brown is joined by Yohan Lasorsa to explore how developers can build agent-powered application...

1 day ago

Accelerate Your Cosmos DB Infrastructure with GitHub Copilot CLI and Azure Cosmos DB Agent Kit

Modern infrastructure work is increasingly agent driven, but only if your AI actually understands the platform you’re deploying. This guide sh...

2 days ago

Accelerate Your Cosmos DB Infrastructure with GitHub Copilot CLI and Azure Cosmos DB Agent Kit

Modern infrastructure work is increasingly agent driven, but only if your AI actually understands the platform you’re deploying. This guide sh...

2 days ago

SharePoint: Migrate the Maps web part to Azure Maps

The SharePoint Maps web part will migrate from Bing Maps to Azure Maps starting March 2026, completing by mid-April. Key changes include renam...

2 days ago

Azure Cosmos DB TV Recap: Supercharging AI Agents with the Azure Cosmos DB MCP Toolkit (Ep. 110)

In Episode 110 of Azure Cosmos DB TV, host Mark Brown is joined by Sajeetharan Sinnathurai to explore how the Azure Cosmos DB MCP Toolkit is c...

7 days ago

Introducing the Azure Cosmos DB Agent Kit: Your AI Pair Programmer Just Got Smarter

The Azure Cosmos DB Agent Kit is an open-source collection of skills that teaches your AI coding assistant (GitHub Copilot, Claude Code, Gemin...

8 days ago
Stay up to date with latest Microsoft Dynamics 365 and Power Platform news!
* Yes, I agree to the privacy policy