{ "cells": [ { "cell_type": "markdown", "id": "f14c4442-3fc5-4070-9ef2-bb33d30e6b38", "metadata": {}, "source": [ "# L2: Evaluate Inputs: Classification" ] }, { "cell_type": "markdown", "id": "26fd0696-18e6-4029-8738-fecba92851db", "metadata": {}, "source": [ "## Setup\n", "#### Load the API key and relevant Python libaries.\n", "In this course, we've provided some code that loads the OpenAI API key for you." ] }, { "cell_type": "code", "execution_count": null, "id": "87f647e2", "metadata": { "height": 115 }, "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", "\n", "openai.api_key = os.environ['OPENAI_API_KEY']" ] }, { "cell_type": "code", "execution_count": null, "id": "101624a2", "metadata": { "height": 200 }, "outputs": [], "source": [ "def get_completion_from_messages(messages, \n", " model=\"gpt-3.5-turbo\", \n", " temperature=0, \n", " max_tokens=500):\n", " response = openai.ChatCompletion.create(\n", " model=model,\n", " messages=messages,\n", " temperature=temperature, \n", " max_tokens=max_tokens,\n", " )\n", " return response.choices[0].message[\"content\"]" ] }, { "cell_type": "markdown", "id": "d3db09d1-6253-4c9e-9ad1-5a6134df3e6c", "metadata": {}, "source": [ "#### Classify customer queries to handle different cases" ] }, { "cell_type": "code", "execution_count": null, "id": "8db30f42", "metadata": { "height": 812 }, "outputs": [], "source": [ "delimiter = \"####\"\n", "system_message = f\"\"\"\n", "You will be provided with customer service queries. \\\n", "The customer service query will be delimited with \\\n", "{delimiter} characters.\n", "Classify each query into a primary category \\\n", "and a secondary category. \n", "Provide your output in json format with the \\\n", "keys: primary and secondary.\n", "\n", "Primary categories: Billing, Technical Support, \\\n", "Account Management, or General Inquiry.\n", "\n", "Billing secondary categories:\n", "Unsubscribe or upgrade\n", "Add a payment method\n", "Explanation for charge\n", "Dispute a charge\n", "\n", "Technical Support secondary categories:\n", "General troubleshooting\n", "Device compatibility\n", "Software updates\n", "\n", "Account Management secondary categories:\n", "Password reset\n", "Update personal information\n", "Close account\n", "Account security\n", "\n", "General Inquiry secondary categories:\n", "Product information\n", "Pricing\n", "Feedback\n", "Speak to a human\n", "\n", "\"\"\"\n", "user_message = f\"\"\"\\\n", "I want you to delete my profile and all of my user data\"\"\"\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": null, "id": "f9a5a790", "metadata": { "height": 183 }, "outputs": [], "source": [ "user_message = f\"\"\"\\\n", "Tell me more about your flat screen 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": null, "id": "5cfd2fae", "metadata": { "height": 30 }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.16" } }, "nbformat": 4, "nbformat_minor": 5 }