Skip to content

Instantly share code, notes, and snippets.

@Hehehe421
Last active March 27, 2024 16:39
Show Gist options
  • Save Hehehe421/1af94feb452e7415cf13787d97eda584 to your computer and use it in GitHub Desktop.
Save Hehehe421/1af94feb452e7415cf13787d97eda584 to your computer and use it in GitHub Desktop.
import openai
# Replace with your actual OpenAI API key
openai.api_key = 'your_api_key_here'
def categorize_feedback(feedback: str):
"""
Categorizes customer feedback into predefined themes using zero-shot learning.
Parameters:
- feedback (str): The customer feedback text to be categorized.
"""
categories = ["Product Quality",
"Customer Service",
"Pricing",
"Technical Support",
"Delivery"]
prompt = f"Feedback: \"{feedback}\"\n\nCategories: {', '.join(categories)}\n\nThis feedback is most likely about:"
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": prompt},
{"role": "user", "content": " "}
],
max_tokens=60,
stop=["\n"]
)
# Extract and print the predicted category from the response
predicted_category = response.choices[0].message.content.strip()
print(f"Predicted Category: {predicted_category}")
# Example usage
feedback_examples = [
"I'm really disappointed with the late delivery of my order. It was supposed to arrive last week!",
"Your support team did a fantastic job helping me resolve an issue with my account.",
"I found the pricing to be quite competitive compared to other brands."
]
for feedback in feedback_examples:
categorize_feedback(feedback)
print("-----")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment