Let’s see how to classify the customer queries into user-defined categories and sub-categories using Azure OpenAI.
Text classification is a fundamental NLP task that involves assigning predefined categories to textual input. In the provided code, a customer support system utilizes text classification to categorize customer queries related to their orders. The system employs user-defined primary and secondary categories, each with specific sub-categories.
The system message serves as a guide for the classification task, outlining the primary categories (Order Status, Product Inquiries, Shipping and Delivery, and Payment Assistance) and their corresponding secondary categories. The primary and secondary categories are structured to capture various aspects of customer queries, such as tracking information, product availability, and payment confirmation.
For example, when a user submits a query to cancel an order, the code uses the OpenAI ChatCompletion API to generate a response. The output includes a JSON-formatted response indicating the primary and secondary categories assigned to the user’s query. In this case, the primary category is Order Status, and the secondary category is Order Modification or Cancellation.
This example demonstrates how text classification can be applied in a customer support context, allowing for the efficient handling and categorization of customer queries based on predefined categories. The system provides a structured approach to address diverse aspects of order-related inquiries, enhancing the overall customer support experience:
system_message = f”””
Welcome to Customer Order Support!
You will receive customer queries related to their orders, each delimited by {delimiter} characters.
Your task is to classify each query into a primary and secondary category.
Provide your response in JSON format with the keys: “primary” and “secondary.”
Primary Categories:
1.
Order Status
2.
Product Inquiries
3.
Shipping and Delivery
4.
Payment Assistance
Order Status Secondary Categories:
– Tracking Information
– Order Confirmation
– Order Modification or Cancellation
– Refund Status
Product Inquiries Secondary Categories:
– Product Availability
– Size and Color Options
– Product Specifications
– Return and Exchange Policies
Shipping and Delivery Secondary Categories:
– Delivery Timeframe
– Shipping Methods
– Address Changes
– Lost or Delayed Shipments
Payment Assistance Secondary Categories:
– Payment Confirmation
– Refund Process
– Payment Errors
– Billing Inquiries
Please review each query and provide the appropriate primary and secondary category in your response.
Thank you for assisting our customers with their orders!
“””
user_message=f”””\
I want to cancel my order “””
response = openai.ChatCompletion.create(
engine=deployment_name, # engine = “deployment_name”.
messages=[
{“role”: “system”, “content”: system_message},
{“role”: “user”, “content”: f”{delimiter}{user_message}
{delimiter}”},],
temperature=0,
max_tokens=60,
top_p=1,
frequency_penalty=0,
presence_penalty=0,
stop=None
)
print(response)
print(response[‘choices’][0][‘message’][‘content’])
Here’s the output:
{ “id”: “chatcmpl-8eEc86GxAO4BePuRepvve9XhTQZfa”, “object”: “chat.completion”, “created”: 1704599988, “model”: “gpt-35-turbo”, “choices”: [ { “finish_reason”: “stop”, “index”: 0, “message”: { “role”: “assistant”, “content”: “{\n \”primary\”: \”Order Status\”,\n \”secondary\”: \”Order Modification or Cancellation\”\n}” } } ], “usage”: { “prompt_tokens”: 232, “completion_tokens”: 21, “total_tokens”: 253 } } { “primary”: “Order Status”, “secondary”: “Order Modification or Cancellation” }