Customer Sentiment Analysis¶
openaivec.task.customer_support.customer_sentiment ¶
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-4.1-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. |
Classes¶
Functions¶
customer_sentiment ¶
customer_sentiment(
business_context: str = "general customer support",
**api_kwargs,
) -> PreparedTask
Create a configurable customer sentiment analysis task.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
business_context
|
str
|
Business context for sentiment analysis. |
'general customer support'
|
**api_kwargs
|
Additional OpenAI API parameters (temperature, top_p, etc.). |
{}
|
Returns:
Type | Description |
---|---|
PreparedTask
|
PreparedTask configured for customer sentiment analysis. |