Customer Sentiment Analysis¶
Customer sentiment analysis task for support interactions.
This module provides a predefined task for analyzing customer sentiment specifically in support contexts, including satisfaction levels and emotional states that affect customer experience and support strategy.
Example
Basic usage with BatchResponses:
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.CUSTOMER_SENTIMENT
)
inquiries = [
"I'm really disappointed with your service. This is the third time I've had this issue.",
"Thank you so much for your help! You've been incredibly patient.",
"I need to cancel my subscription. It's not working for me."
]
sentiments = analyzer.parse(inquiries)
for sentiment in sentiments:
print(f"Sentiment: {sentiment.sentiment}")
print(f"Satisfaction: {sentiment.satisfaction_level}")
print(f"Churn Risk: {sentiment.churn_risk}")
print(f"Emotional State: {sentiment.emotional_state}")
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'm really disappointed with your service. This is the third time I've had this issue.",
"Thank you so much for your help! You've been incredibly patient.",
"I need to cancel my subscription. It's not working for me."
]})
df["sentiment"] = df["inquiry"].ai.task(customer_support.CUSTOMER_SENTIMENT)
# Extract sentiment components
extracted_df = df.ai.extract("sentiment")
print(extracted_df[["inquiry", "sentiment_satisfaction_level", "sentiment_churn_risk", "sentiment_emotional_state"]])
Attributes:
Name | Type | Description |
---|---|---|
CUSTOMER_SENTIMENT |
PreparedTask
|
A prepared task instance configured for customer sentiment analysis with temperature=0.0 and top_p=1.0 for deterministic output. |
customer_sentiment(business_context='general customer support', temperature=0.0, top_p=1.0)
¶
Create a configurable customer sentiment analysis task.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
business_context
|
str
|
Business context for sentiment analysis. |
'general customer support'
|
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 customer sentiment analysis. |