Fix the user intent extraction prompt for GPT. Clean up chatbot test

This commit is contained in:
Debanjum Singh Solanky
2022-01-12 10:36:01 -05:00
parent ea28897cdd
commit 2e53fbc844
2 changed files with 5 additions and 5 deletions

View File

@@ -42,7 +42,7 @@ def understand(text, api_key=None, temperature=0.5, max_tokens=100, verbose=0):
"""
# Initialize Variables
openai.api_key = api_key or os.getenv("OPENAI_API_KEY")
understand_primer = "Objective: Extract intent and trigger emotion information as JSON from each chat message\n\nPotential intent types and valid argument values are listed below:\n- intent\n - remember(memory-type, query);\n - memory-type=[\"companion\", \"notes\", \"ledger\", \"image\", \"music\"]\n - search(search-type, query);\n - search-type=[\"google\"]\n - generate(activity, query);\n - activity=[\"paint\",\"write\", \"chat\"]\n- trigger-emotion(emotion)\n - emotion=[\"happy\",\"confidence\",\"fear\",\"surprise\",\"sadness\",\"disgust\",\"anger\", \"shy\", \"curiosity\", \"calm\"]\n\nSome examples are given below for reference:\nQ: How are you doing?\nA: { \"intent\": {\"type\": \"generate\", \"activity\": \"chat\", \"query\": \"How are you doing?\"}, \"trigger-emotion\": \"happy\" }\nQ: Do you remember what I told you about my brother Antoine when we were at the beach?\nA: { \"intent\": {\"type\": \"remember\", \"memory-type\": \"companion\", \"query\": \"Brother Antoine when we were at the beach\"}, \"trigger-emotion\": \"curiosity\" }\nQ: what was that fantasy story you told me last time?\nA: { \"intent\": {\"type\": \"remember\", \"memory-type\": \"companion\", \"query\": \"fantasy story told last time\"}, \"trigger-emotion\": \"curiosity\" }\nQ: Let's make some drawings about the stars on a clear full moon night!\nA: { \"intent\": {\"type\": \"generate\", \"activity\": \"paint\", \"query\": \"stars on a clear full moon night\"}, \"trigger-emotion: \"happy\" }\nQ: Do you know anything about Lebanon cuisine in the 18th century?\nA: { \"intent\": [\"search\", \"google\", \"lebanon cusine in the 18th century\"], \"trigger-emotion; \"confidence\" }\nQ: Tell me a scary story\nA: { \"intent\": {\"type\": \"generate\", \"activity\": \"write\", \"query\": \"A scary story\"}, \"trigger-emotion\": \"fear\" }\nQ: What fiction book was I reading last week about AI starship?\nA: { \"intent\": {\"type\": \"remember\", \"memory-type\": \"notes\", \"query\": \"fiction book about AI starship last week\"}, \"trigger-emotion\": \"curiosity\" }\nQ: How much did I spend at Subway for dinner last time?\nA: { \"intent\": {\"type\": \"remember\", \"memory-type\": \"ledger\", \"query\": \"last Subway dinner\"}, \"trigger-emotion\": \"calm\" }\nQ: I'm feeling sleepy\nA: { \"intent\": {\"type\": \"generate\", \"activity\": \"chat\", \"query\": \"I'm feeling sleepy\"}, \"trigger-emotion\": \"calm\" }\nQ: What was that popular Sri lankan song that Alex had mentioned?\nA: { \"intent\": {\"type\": \"remember\", \"memory-type\": \"music\", \"query\": \"popular Sri lankan song mentioned by Alex\"], \"trigger-emotion\": \"curiosity\" } \nQ: You're pretty funny!\nA: { \"intent\": {\"type\": \"generate\", \"activity\": \"chat\", \"query\": \"You're pretty funny!\"}, \"trigger-emotion\": \"shy\" }\nQ: Can you recommend a movie to watch from my notes?\nA: { \"intent\": {\"type\": \"remember\", \"memory-type\": \"notes\", \"query\": \"recommend movie to watch\"], \"trigger-emotion\": \"curiosity\" }\nQ: When did I go surfing last?\nA: { \"intent\": {\"type\": \"remember\", \"memory-type\": \"notes\", \"query\": \"went surfing last\"], \"trigger-emotion\": \"calm\" }\nQ: Can you dance for me?\nA: { \"intent\": null, \"trigger-emotion\": \"sad\" }"
understand_primer = "Objective: Extract intent and trigger emotion information as JSON from each chat message\n\nPotential intent types and valid argument values are listed below:\n- intent\n - remember(memory-type, query);\n - memory-type=[\"companion\",\"notes\",\"ledger\",\"image\",\"music\"]\n - search(search-type, query);\n - search-type=[\"google\"]\n - generate(activity, query);\n - activity=[\"paint\",\"write\",\"chat\"]\n- trigger-emotion(emotion)\n - emotion=[\"happy\",\"confidence\",\"fear\",\"surprise\",\"sadness\",\"disgust\",\"anger\",\"shy\",\"curiosity\",\"calm\"]\n\nSome examples are given below for reference:\nQ: How are you doing?\nA: { \"intent\": {\"type\": \"generate\", \"activity\": \"chat\", \"query\": \"How are you doing?\"}, \"trigger-emotion\": \"happy\" }\nQ: Do you remember what I told you about my brother Antoine when we were at the beach?\nA: { \"intent\": {\"type\": \"remember\", \"memory-type\": \"companion\", \"query\": \"Brother Antoine when we were at the beach\"}, \"trigger-emotion\": \"curiosity\" }\nQ: what was that fantasy story you told me last time?\nA: { \"intent\": {\"type\": \"remember\", \"memory-type\": \"companion\", \"query\": \"fantasy story told last time\"}, \"trigger-emotion\": \"curiosity\" }\nQ: Let's make some drawings about the stars on a clear full moon night!\nA: { \"intent\": {\"type\": \"generate\", \"activity\": \"paint\", \"query\": \"stars on a clear full moon night\"}, \"trigger-emotion: \"happy\" }\nQ: Do you know anything about Lebanon cuisine in the 18th century?\nA: { \"intent\": {\"type\": \"search\", \"search-type\": \"google\", \"query\": \"lebanon cusine in the 18th century\"}, \"trigger-emotion; \"confidence\" }\nQ: Tell me a scary story\nA: { \"intent\": {\"type\": \"generate\", \"activity\": \"write\", \"query\": \"A scary story\"}, \"trigger-emotion\": \"fear\" }\nQ: What fiction book was I reading last week about AI starship?\nA: { \"intent\": {\"type\": \"remember\", \"memory-type\": \"notes\", \"query\": \"fiction book about AI starship last week\"}, \"trigger-emotion\": \"curiosity\" }\nQ: How much did I spend at Subway for dinner last time?\nA: { \"intent\": {\"type\": \"remember\", \"memory-type\": \"ledger\", \"query\": \"last Subway dinner\"}, \"trigger-emotion\": \"calm\" }\nQ: I'm feeling sleepy\nA: { \"intent\": {\"type\": \"generate\", \"activity\": \"chat\", \"query\": \"I'm feeling sleepy\"}, \"trigger-emotion\": \"calm\" }\nQ: What was that popular Sri lankan song that Alex had mentioned?\nA: { \"intent\": {\"type\": \"remember\", \"memory-type\": \"music\", \"query\": \"popular Sri lankan song mentioned by Alex\"], \"trigger-emotion\": \"curiosity\" } \nQ: You're pretty funny!\nA: { \"intent\": {\"type\": \"generate\", \"activity\": \"chat\", \"query\": \"You're pretty funny!\"}, \"trigger-emotion\": \"shy\" }\nQ: Can you recommend a movie to watch from my notes?\nA: { \"intent\": {\"type\": \"remember\", \"memory-type\": \"notes\", \"query\": \"recommend movie to watch\"], \"trigger-emotion\": \"curiosity\" }\nQ: When did I go surfing last?\nA: { \"intent\": {\"type\": \"remember\", \"memory-type\": \"notes\", \"query\": \"When did I go surfing last\"], \"trigger-emotion\": \"calm\" }\nQ: Can you dance for me?\nA: { \"intent\": {\"type\": \"generate\", \"activity\": \"chat\", \"query\": \"Can you dance for me?\"}, \"trigger-emotion\": \"sad\" }"
# Setup Prompt with Understand Primer
prompt = message_to_prompt(text, understand_primer, start_sequence="\nA:", restart_sequence="\nQ:")