@@ -20,6 +20,12 @@ Create and activate a [virtual environment](https://realpython.com/python-virtua
2020(venv) $ python -m pip install openai
2121```
2222
23+ Or, to make sure that you're using the same versions as shown in the tutorial, you can install from ` requirements.txt ` instead:
24+
25+ ``` bash
26+ (venv) $ python -m pip install -r requirements.txt
27+ ```
28+
2329## Usage
2430
2531Read support chat conversations from a file, sanitize the text, classify by sentiment, and format the output as JSON:
@@ -399,20 +405,34 @@ instruction_prompt = """
399405Classify the sentiment of each conversation in >>>>>CONTENT<<<<<
400406with "🔥" for negative and "✅" for positive.
401407
408+ Follow these steps when classifying the conversations:
409+ 1. Does the customer use swear words or 😤?
410+ 2. Does the customer seem aggravated or angry?
411+
412+ If you answer "Yes" to one of the above questions,
413+ then classify the conversation as negative with "🔥".
414+ Otherwise classify the conversation as positive with "✅".
415+
416+ Let's think step by step
417+
402418#### START EXAMPLES
403419
404420------ Example Inputs ------
405421[Agent] 2023-07-24 : What can I help you with?
406422[Customer] 2023-07-24 : I CAN'T CONNECT TO MY 😤 ACCOUNT
407423[Agent] 2023-07-24 : Are you sure it's not your caps lock?
408424[Customer] 2023-07-24 : 😤! You're right!
409- The customer uses the 😤 emoji and seems aggravated, so the sentiment is negative. 🔥
425+ - Does the customer use swear words or 😤? Yes
426+ - Does the customer seem aggravated or angry? Yes
427+ - Sentiment: 🔥
410428
411429[Agent] 2023-06-15 : Hello! How can I assist you today?
412430[Customer] 2023-06-15 : I can't seem to find the download link for my purchased software.
413- [Agent] 2023-06-15 : No problem, ********. Let me find that for you. Can you please provide your order number?
414- [Customer] 2023-06-15 : It's ********. Thanks for helping me out!
415- The customer does not use any swear words or 😤 emoji and does not seem aggravated or angry, so the sentiment is positive. ✅
431+ [Agent] 2023-06-15 : No problem, ****. Let me find that for you. Can you please provide your order number?
432+ [Customer] 2023-06-15 : It's ****. Thanks for helping me out!
433+ - Does the customer use swear words or 😤? No
434+ - Does the customer seem aggravated or angry? No
435+ - Sentiment: ✅
416436
417437------ Example Outputs ------
418438🔥
@@ -424,8 +444,8 @@ The customer does not use any swear words or 😤 emoji and does not seem aggrav
424444✅
425445[Agent] 2023-06-15 : Hello! How can I assist you today?
426446[Customer] 2023-06-15 : I can't seem to find the download link for my purchased software.
427- [Agent] 2023-06-15 : No problem, ******** . Let me find that for you. Can you please provide your order number?
428- [Customer] 2023-06-15 : It's ******** . Thanks for helping me out!
447+ [Agent] 2023-06-15 : No problem, ****. Let me find that for you. Can you please provide your order number?
448+ [Customer] 2023-06-15 : It's ****. Thanks for helping me out!
429449
430450#### END EXAMPLES
431451"""
@@ -444,21 +464,34 @@ Classify the sentiment of each conversation in >>>>>CONTENT<<<<<
444464as "negative" and "positive".
445465Return the output as valid JSON.
446466
447- #### START EXAMPLES
467+ Follow these steps when classifying the conversations:
468+ 1. Does the customer use swear words or 😤?
469+ 2. Does the customer seem aggravated or angry?
448470
449- ------ Example Input ------
471+ If you answer "Yes" to one of the above questions,
472+ then classify the conversation as "negative".
473+ Otherwise classify the conversation as "positive".
450474
475+ Let's think step by step
476+
477+ #### START EXAMPLES
478+
479+ ------ Example Inputs ------
451480[Agent] 2023-07-24 : What can I help you with?
452481[Customer] 2023-07-24 : I CAN'T CONNECT TO MY 😤 ACCOUNT
453482[Agent] 2023-07-24 : Are you sure it's not your caps lock?
454483[Customer] 2023-07-24 : 😤! You're right!
455- The customer uses the 😤 emoji and seems aggravated, so the sentiment is negative.
484+ - Does the customer use swear words or 😤? Yes
485+ - Does the customer seem aggravated or angry? Yes
486+ - Sentiment: "negative"
456487
457488[Agent] 2023-06-15 : Hello! How can I assist you today?
458489[Customer] 2023-06-15 : I can't seem to find the download link for my purchased software.
459- [Agent] 2023-06-15 : No problem, ********. Let me find that for you. Can you please provide your order number?
460- [Customer] 2023-06-15 : It's ********. Thanks for helping me out!
461- The customer does not use any swear words or 😤 emoji and does not seem aggravated or angry, so the sentiment is positive.
490+ [Agent] 2023-06-15 : No problem, ****. Let me find that for you. Can you please provide your order number?
491+ [Customer] 2023-06-15 : It's ****. Thanks for helping me out!
492+ - Does the customer use swear words or 😤? No
493+ - Does the customer seem aggravated or angry? No
494+ - Sentiment: "positive"
462495
463496------ Example Output ------
464497
@@ -480,8 +513,8 @@ The customer does not use any swear words or 😤 emoji and does not seem aggrav
480513 "conversation": [
481514 "A: Hello! How can I assist you today?",
482515 "C: I can't seem to find the download link for my purchased software.",
483- "A: No problem, ******** . Let me find that for you. Can you please provide your order number?",
484- "C: It's ******** . Thanks for helping me out!"
516+ "A: No problem, ****. Let me find that for you. Can you please provide your order number?",
517+ "C: It's ****. Thanks for helping me out!"
485518 ]
486519 }
487520 ]
@@ -504,54 +537,56 @@ Classify the sentiment of each conversation in >>>>>CONTENT<<<<<
504537as "negative" and "positive".
505538Return the output as valid JSON.
506539"""
507- role_prompt = """ You are a thoroughly trained machine learning model
508- that is an expert at sentiment classification.
540+ role_prompt = """ You are a thoroughly trained machine learning
541+ model that is an expert at sentiment classification.
509542You diligently complete tasks as instructed.
510543You never make up any information that isn't there."""
511544positive_example = """
512545[Agent] 2023-06-15 : Hello! How can I assist you today?
513546[Customer] 2023-06-15 : I can't seem to find the download link for my purchased software.
514- [Agent] 2023-06-15 : No problem, ********. Let me find that for you. Can you please provide your order number?
515- [Customer] 2023-06-15 : It's ********. Thanks for helping me out!
547+ [Agent] 2023-06-15 : No problem, ****. Let me find that for you. Can you please provide your order number?
548+ [Customer] 2023-06-15 : It's ****. Thanks for helping me out!
549+ """
550+ positive_reasoning = """
551+ - Does the customer use swear words or 😤? No
552+ - Does the customer seem aggravated or angry? No
553+ - Sentiment: "positive"
516554"""
517- positive_reasoning = """ The customer does not use any swear words or 😤 emoji
518- and does not seem aggravated or angry, so the sentiment is positive."""
519555positive_output = """
520- {
521- "positive": [
522- {
523- "date": "2023-06-15",
524- "conversation": [
525- "A: Hello! How can I assist you today?",
526- "C: I can't seem to find the download link for my purchased software.",
527- "A: No problem, ********. Let me find that for you. Can you please provide your order number?",
528- "C: It's ********. Thanks for helping me out!"
529- ]
530- }
531- ]
532- }
556+ "positive": [
557+ {
558+ "date": "2023-06-15",
559+ "conversation": [
560+ "A: Hello! How can I assist you today?",
561+ "C: I can't seem to find the download link for my purchased software.",
562+ "A: No problem, ****. Let me find that for you. Can you please provide your order number?",
563+ "C: It's ****. Thanks for helping me out!"
564+ ]
565+ }
566+ ]
533567"""
534568negative_example = """
535569[Agent] 2023-07-24 : What can I help you with?
536570[Customer] 2023-07-24 : I CAN'T CONNECT TO MY 😤 ACCOUNT
537571[Agent] 2023-07-24 : Are you sure it's not your caps lock?
538572[Customer] 2023-07-24 : 😤! You're right!
539573"""
540- negative_reasoning = """ The customer uses the 😤 emoji and seems aggravated,
541- so the sentiment is negative."""
574+ negative_reasoning = """
575+ - Does the customer use swear words or 😤? Yes
576+ - Does the customer seem aggravated or angry? Yes
577+ - Sentiment: "negative"
578+ """
542579negative_output = """
543- {
544- "negative": [
545- {
546- "date": "2023-07-24",
547- "conversation": [
548- "A: What can I help you with?",
549- "C: I CAN'T CONNECT TO MY 😤 ACCOUNT",
550- "A: Are you sure it's not your caps lock?",
551- "C: 😤! You're right!"
552- ]
553- }
554- ]
555- }
580+ "negative": [
581+ {
582+ "date": "2023-07-24",
583+ "conversation": [
584+ "A: What can I help you with?",
585+ "C: I CAN'T CONNECT TO MY 😤 ACCOUNT",
586+ "A: Are you sure it's not your caps lock?",
587+ "C: 😤! You're right!"
588+ ]
589+ }
590+ ]
556591"""
557592```
0 commit comments