Urgency Analysis¶
Urgency analysis task for customer support.
This module provides a configurable task for analyzing the urgency level of customer inquiries to help prioritize support queue and response times.
Example
Basic usage with default settings:
from openai import OpenAI
from openaivec.responses import BatchResponses
from openaivec.task import customer_support
client = OpenAI()
analyzer = BatchResponses.of_task(
client=client,
model_name="gpt-4o-mini",
task=customer_support.urgency_analysis()
)
inquiries = [
"URGENT: My website is down and I'm losing customers!",
"Can you help me understand how to use the new feature?",
"I haven't received my order from last week"
]
analyses = analyzer.parse(inquiries)
for analysis in analyses:
print(f"Urgency Level: {analysis.urgency_level}")
print(f"Score: {analysis.urgency_score}")
print(f"Response Time: {analysis.response_time}")
print(f"Escalation: {analysis.escalation_required}")
Customized for SaaS platform with business hours:
from openaivec.task import customer_support
# SaaS-specific urgency levels
saas_urgency_levels = {
"critical": "Service outages, security breaches, data loss",
"high": "Login issues, payment failures, API errors",
"medium": "Feature bugs, performance issues, billing questions",
"low": "Feature requests, documentation questions, general feedback"
}
# Custom response times based on SLA
saas_response_times = {
"critical": "immediate",
"high": "within_1_hour",
"medium": "within_4_hours",
"low": "within_24_hours"
}
# Enterprise customer tier gets priority
enterprise_customer_tiers = {
"enterprise": "Priority support, dedicated account manager",
"business": "Standard business support",
"professional": "Professional plan support",
"starter": "Basic support"
}
task = customer_support.urgency_analysis(
urgency_levels=saas_urgency_levels,
response_times=saas_response_times,
customer_tiers=enterprise_customer_tiers,
business_context="SaaS platform",
business_hours="9 AM - 5 PM EST, Monday-Friday"
)
analyzer = BatchResponses.of_task(
client=client,
model_name="gpt-4o-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": [
"URGENT: My website is down and I'm losing customers!",
"Can you help me understand how to use the new feature?",
"I haven't received my order from last week"
]})
df["urgency"] = df["inquiry"].ai.task(customer_support.urgency_analysis())
# Extract urgency components
extracted_df = df.ai.extract("urgency")
print(extracted_df[["inquiry", "urgency_urgency_level", "urgency_urgency_score", "urgency_response_time"]])
urgency_analysis(urgency_levels=None, response_times=None, customer_tiers=None, escalation_rules=None, urgency_keywords=None, business_context='general customer support', business_hours='24/7 support', sla_rules=None, temperature=0.0, top_p=1.0)
¶
Create a configurable urgency analysis task.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
urgency_levels
|
Optional[Dict[str, str]]
|
Dictionary mapping urgency levels to descriptions. |
None
|
response_times
|
Optional[Dict[str, str]]
|
Dictionary mapping urgency levels to response times. |
None
|
customer_tiers
|
Optional[Dict[str, str]]
|
Dictionary mapping tier names to descriptions. |
None
|
escalation_rules
|
Optional[Dict[str, str]]
|
Dictionary mapping conditions to escalation actions. |
None
|
urgency_keywords
|
Optional[Dict[str, List[str]]]
|
Dictionary mapping urgency levels to indicator keywords. |
None
|
business_context
|
str
|
Description of the business context. |
'general customer support'
|
business_hours
|
str
|
Description of business hours for response time calculation. |
'24/7 support'
|
sla_rules
|
Optional[Dict[str, str]]
|
Dictionary mapping customer tiers to SLA requirements. |
None
|
temperature
|
float
|
Sampling temperature (0.0-1.0). |
0.0
|
top_p
|
float
|
Nucleus sampling parameter (0.0-1.0). |
1.0
|
Returns:
Type | Description |
---|---|
PreparedTask
|
PreparedTask configured for urgency analysis. |
Source code in src/openaivec/task/customer_support/urgency_analysis.py
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 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 |
|