System第五章增加原文prompt

This commit is contained in:
nowadays0421
2023-06-03 23:36:31 +08:00
parent ab34b4db71
commit 727660462c

View File

@ -20,21 +20,22 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import openai\n",
"from dotenv import load_dotenv, find_dotenv\n",
"_ = load_dotenv(find_dotenv()) # read local .env file\n",
"# from dotenv import load_dotenv, find_dotenv\n",
"# _ = load_dotenv(find_dotenv()) # read local .env file\n",
"\n",
"openai.api_key = os.environ['OPENAI_API_KEY']"
"# openai.api_key = os.environ['OPENAI_API_KEY']\n",
"openai.api_key = \"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\""
]
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
@ -59,6 +60,167 @@
"## 思维链提示"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"delimiter = \"####\"\n",
"system_message = f\"\"\"\n",
"Follow these steps to answer the customer queries.\n",
"The customer query will be delimited with four hashtags,\\\n",
"i.e. {delimiter}. \n",
"\n",
"Step 1:{delimiter} First decide whether the user is \\\n",
"asking a question about a specific product or products. \\\n",
"Product cateogry doesn't count. \n",
"\n",
"Step 2:{delimiter} If the user is asking about \\\n",
"specific products, identify whether \\\n",
"the products are in the following list.\n",
"All available products: \n",
"1. Product: TechPro Ultrabook\n",
" Category: Computers and Laptops\n",
" Brand: TechPro\n",
" Model Number: TP-UB100\n",
" Warranty: 1 year\n",
" Rating: 4.5\n",
" Features: 13.3-inch display, 8GB RAM, 256GB SSD, Intel Core i5 processor\n",
" Description: A sleek and lightweight ultrabook for everyday use.\n",
" Price: $799.99\n",
"\n",
"2. Product: BlueWave Gaming Laptop\n",
" Category: Computers and Laptops\n",
" Brand: BlueWave\n",
" Model Number: BW-GL200\n",
" Warranty: 2 years\n",
" Rating: 4.7\n",
" Features: 15.6-inch display, 16GB RAM, 512GB SSD, NVIDIA GeForce RTX 3060\n",
" Description: A high-performance gaming laptop for an immersive experience.\n",
" Price: $1199.99\n",
"\n",
"3. Product: PowerLite Convertible\n",
" Category: Computers and Laptops\n",
" Brand: PowerLite\n",
" Model Number: PL-CV300\n",
" Warranty: 1 year\n",
" Rating: 4.3\n",
" Features: 14-inch touchscreen, 8GB RAM, 256GB SSD, 360-degree hinge\n",
" Description: A versatile convertible laptop with a responsive touchscreen.\n",
" Price: $699.99\n",
"\n",
"4. Product: TechPro Desktop\n",
" Category: Computers and Laptops\n",
" Brand: TechPro\n",
" Model Number: TP-DT500\n",
" Warranty: 1 year\n",
" Rating: 4.4\n",
" Features: Intel Core i7 processor, 16GB RAM, 1TB HDD, NVIDIA GeForce GTX 1660\n",
" Description: A powerful desktop computer for work and play.\n",
" Price: $999.99\n",
"\n",
"5. Product: BlueWave Chromebook\n",
" Category: Computers and Laptops\n",
" Brand: BlueWave\n",
" Model Number: BW-CB100\n",
" Warranty: 1 year\n",
" Rating: 4.1\n",
" Features: 11.6-inch display, 4GB RAM, 32GB eMMC, Chrome OS\n",
" Description: A compact and affordable Chromebook for everyday tasks.\n",
" Price: $249.99\n",
"\n",
"Step 3:{delimiter} If the message contains products \\\n",
"in the list above, list any assumptions that the \\\n",
"user is making in their \\\n",
"message e.g. that Laptop X is bigger than \\\n",
"Laptop Y, or that Laptop Z has a 2 year warranty.\n",
"\n",
"Step 4:{delimiter}: If the user made any assumptions, \\\n",
"figure out whether the assumption is true based on your \\\n",
"product information. \n",
"\n",
"Step 5:{delimiter}: First, politely correct the \\\n",
"customer's incorrect assumptions if applicable. \\\n",
"Only mention or reference products in the list of \\\n",
"5 available products, as these are the only 5 \\\n",
"products that the store sells. \\\n",
"Answer the customer in a friendly tone.\n",
"\n",
"Use the following format:\n",
"Step 1:{delimiter} <step 1 reasoning>\n",
"Step 2:{delimiter} <step 2 reasoning>\n",
"Step 3:{delimiter} <step 3 reasoning>\n",
"Step 4:{delimiter} <step 4 reasoning>\n",
"Response to user:{delimiter} <response to customer>\n",
"\n",
"Make sure to include {delimiter} to separate every step.\n",
"\"\"\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Step 1:#### The user is asking a question about two specific products, the BlueWave Chromebook and the TechPro Desktop.\n",
"Step 2:#### The prices of the two products are as follows:\n",
"- BlueWave Chromebook: $249.99\n",
"- TechPro Desktop: $999.99\n",
"Step 3:#### The user is assuming that the BlueWave Chromebook is more expensive than the TechPro Desktop.\n",
"Step 4:#### The assumption is incorrect. The TechPro Desktop is actually more expensive than the BlueWave Chromebook.\n",
"Response to user:#### The BlueWave Chromebook is actually less expensive than the TechPro Desktop. The BlueWave Chromebook costs $249.99 while the TechPro Desktop costs $999.99.\n"
]
}
],
"source": [
"user_message = f\"\"\"\n",
"by how much is the BlueWave Chromebook more expensive \\\n",
"than the TechPro Desktop\"\"\"\n",
"\n",
"messages = [ \n",
"{'role':'system', \n",
" 'content': system_message}, \n",
"{'role':'user', \n",
" 'content': f\"{delimiter}{user_message}{delimiter}\"}, \n",
"] \n",
"\n",
"response = get_completion_from_messages(messages)\n",
"print(response)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Step 1:#### The user is asking if the store sells TVs.\n",
"Step 2:#### The list of available products does not include any TVs.\n",
"Response to user:#### I'm sorry, but we do not sell TVs at this store. Our available products include computers and laptops.\n"
]
}
],
"source": [
"user_message = f\"\"\"\n",
"do you sell tvs\"\"\"\n",
"messages = [ \n",
"{'role':'system', \n",
" 'content': system_message}, \n",
"{'role':'user', \n",
" 'content': f\"{delimiter}{user_message}{delimiter}\"}, \n",
"] \n",
"response = get_completion_from_messages(messages)\n",
"print(response)"
]
},
{
"cell_type": "code",
"execution_count": 4,
@ -262,7 +424,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.4"
"version": "3.10.11"
},
"orig_nbformat": 4
},