Inquiry Classification¶
openaivec.task.customer_support.inquiry_classification ¶
Inquiry classification task for customer support.
This module provides a configurable task for classifying customer inquiries into different categories to help route them to the appropriate support team.
Example
Basic usage with default settings:
from openai import OpenAI
from openaivec._responses import BatchResponses
from openaivec.task import customer_support
client = OpenAI()
classifier = BatchResponses.of_task(
client=client,
model_name="gpt-4.1-mini",
task=customer_support.inquiry_classification()
)
inquiries = [
"I can't log into my account",
"When will my order arrive?",
"I want to cancel my subscription"
]
classifications = classifier.parse(inquiries)
for classification in classifications:
print(f"Category: {classification.category}")
print(f"Subcategory: {classification.subcategory}")
print(f"Confidence: {classification.confidence}")
print(f"Routing: {classification.routing}")
Customized for e-commerce:
from openaivec.task import customer_support
# E-commerce specific categories
ecommerce_categories = {
"order_management": ["order_status", "order_cancellation", "order_modification", "returns"],
"payment": ["payment_failed", "refund_request", "payment_methods", "billing_inquiry"],
"product": ["product_info", "size_guide", "availability", "recommendations"],
"shipping": ["delivery_status", "shipping_cost", "delivery_options", "tracking"],
"account": ["login_issues", "account_settings", "profile_updates", "password_reset"],
"general": ["complaints", "compliments", "feedback", "other"]
}
ecommerce_routing = {
"order_management": "order_team",
"payment": "billing_team",
"product": "product_team",
"shipping": "logistics_team",
"account": "account_support",
"general": "general_support"
}
task = customer_support.inquiry_classification(
categories=ecommerce_categories,
routing_rules=ecommerce_routing,
business_context="e-commerce platform"
)
classifier = BatchResponses.of_task(
client=client,
model_name="gpt-4.1-mini",
task=task
)
With pandas integration:
import pandas as pd
from openaivec import pandas_ext # Required for .ai accessor
from openaivec.task import customer_support
df = pd.DataFrame({"inquiry": [
"I can't log into my account",
"When will my order arrive?",
"I want to cancel my subscription"
]})
df["classification"] = df["inquiry"].ai.task(customer_support.inquiry_classification())
# Extract classification components
extracted_df = df.ai.extract("classification")
print(extracted_df[[
"inquiry", "classification_category",
"classification_subcategory", "classification_confidence"
]])
Classes¶
Functions¶
inquiry_classification ¶
inquiry_classification(
categories: Dict[str, list[str]] | None = None,
routing_rules: Dict[str, str] | None = None,
priority_rules: Dict[str, str] | None = None,
business_context: str = "general customer support",
custom_keywords: Dict[str, list[str]] | None = None,
**api_kwargs,
) -> PreparedTask
Create a configurable inquiry classification task.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
categories
|
dict[str, list[str]] | None
|
Dictionary mapping category names to lists of subcategories. Default provides standard support categories. |
None
|
routing_rules
|
dict[str, str] | None
|
Dictionary mapping categories to routing destinations. Default provides standard routing options. |
None
|
priority_rules
|
dict[str, str] | None
|
Dictionary mapping keywords/patterns to priority levels. Default uses standard priority indicators. |
None
|
business_context
|
str
|
Description of the business context to help with classification. |
'general customer support'
|
custom_keywords
|
dict[str, list[str]] | None
|
Dictionary mapping categories to relevant keywords. |
None
|
**api_kwargs
|
Additional keyword arguments to pass to the OpenAI API, such as temperature, top_p, etc. |
{}
|
Returns:
Type | Description |
---|---|
PreparedTask
|
PreparedTask configured for inquiry classification. |
Source code in src/openaivec/task/customer_support/inquiry_classification.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
|