Files
prompt-engineering-for-deve…/content/LangChain for LLM Application Development/6.评估 Evaluation.ipynb
2023-07-13 22:55:45 +08:00

1 line
185 KiB
Plaintext

{"cells": [{"cell_type": "markdown", "id": "52824b89-532a-4e54-87e9-1410813cd39e", "metadata": {}, "source": ["# \u7b2c\u516d\u7ae0 \u8bc4\u4f30\n", "\n", " - [\u4e00\u3001\u8bbe\u7f6eOpenAI API Key](#\u4e00\u3001\u8bbe\u7f6eOpenAI-API-Key)\n", " - [\u4e8c\u3001 \u521b\u5efaLLM\u5e94\u7528](#\u4e8c\u3001-\u521b\u5efaLLM\u5e94\u7528)\n", " - [2.1 \u521b\u5efa\u8bc4\u4f30\u6570\u636e\u70b9](#2.1-\u521b\u5efa\u8bc4\u4f30\u6570\u636e\u70b9)\n", " - [2.2 \u521b\u5efa\u6d4b\u8bd5\u7528\u4f8b\u6570\u636e](#2.2-\u521b\u5efa\u6d4b\u8bd5\u7528\u4f8b\u6570\u636e)\n", " - [2.3 \u901a\u8fc7LLM\u751f\u6210\u6d4b\u8bd5\u7528\u4f8b](#2.3-\u901a\u8fc7LLM\u751f\u6210\u6d4b\u8bd5\u7528\u4f8b)\n", " - [2.4 \u7ec4\u5408\u7528\u4f8b\u6570\u636e](#2.4-\u7ec4\u5408\u7528\u4f8b\u6570\u636e)\n", " - [\u4e09\u3001 \u4eba\u5de5\u8bc4\u4f30](#\u4e09\u3001-\u4eba\u5de5\u8bc4\u4f30)\n", " - [3.1 \u5982\u4f55\u8bc4\u4f30\u65b0\u521b\u5efa\u7684\u5b9e\u4f8b](#3.1-\u5982\u4f55\u8bc4\u4f30\u65b0\u521b\u5efa\u7684\u5b9e\u4f8b)\n", " - [3.2 \u4e2d\u6587\u7248](#3.2-\u4e2d\u6587\u7248)\n", " - [\u56db\u3001 \u901a\u8fc7LLM\u8fdb\u884c\u8bc4\u4f30\u5b9e\u4f8b](#\u56db\u3001-\u901a\u8fc7LLM\u8fdb\u884c\u8bc4\u4f30\u5b9e\u4f8b)\n", " - [4.1 \u8bc4\u4f30\u601d\u8def](#4.1--\u8bc4\u4f30\u601d\u8def)\n", " - [4.2 \u7ed3\u679c\u5206\u6790](#4.2-\u7ed3\u679c\u5206\u6790)\n", " - [3.3 \u901a\u8fc7LLM\u8fdb\u884c\u8bc4\u4f30\u5b9e\u4f8b](#3.3-\u901a\u8fc7LLM\u8fdb\u884c\u8bc4\u4f30\u5b9e\u4f8b)\n"]}, {"cell_type": "markdown", "id": "75dfe281-7c7a-43f7-9f8c-3de3a0139baa", "metadata": {"tags": []}, "source": ["## \u4e00\u3001\u8bbe\u7f6eOpenAI API Key\n", "\n", "\u767b\u9646 [OpenAI \u8d26\u6237](https://platform.openai.com/account/api-keys) \u83b7\u53d6API Key\uff0c\u7136\u540e\u5c06\u5176\u8bbe\u7f6e\u4e3a\u73af\u5883\u53d8\u91cf\u3002\n", "\n", "- \u5982\u679c\u4f60\u60f3\u8981\u8bbe\u7f6e\u4e3a\u5168\u5c40\u73af\u5883\u53d8\u91cf\uff0c\u53ef\u4ee5\u53c2\u8003[\u77e5\u4e4e\u6587\u7ae0](https://zhuanlan.zhihu.com/p/627665725)\u3002\n", "- \u5982\u679c\u4f60\u60f3\u8981\u8bbe\u7f6e\u4e3a\u672c\u5730/\u9879\u76ee\u73af\u5883\u53d8\u91cf\uff0c\u5728\u672c\u6587\u4ef6\u76ee\u5f55\u4e0b\u521b\u5efa`.env`\u6587\u4ef6, \u6253\u5f00\u6587\u4ef6\u8f93\u5165\u4ee5\u4e0b\u5185\u5bb9\u3002\n", "\n", " <p style=\"font-family:verdana; font-size:12px;color:green\">\n", " OPENAI_API_KEY=\"your_api_key\" \n", " </p>\n", " \n", " \u66ff\u6362\"your_api_key\"\u4e3a\u4f60\u81ea\u5df1\u7684 API Key"]}, {"cell_type": "code", "execution_count": 1, "id": "a8aa66fb-a33b-438f-81f5-0c6ff08035ad", "metadata": {}, "outputs": [], "source": ["# \u4e0b\u8f7d\u9700\u8981\u7684\u5305python-dotenv\u548copenai\n", "# \u5982\u679c\u4f60\u9700\u8981\u67e5\u770b\u5b89\u88c5\u8fc7\u7a0b\u65e5\u5fd7\uff0c\u53ef\u5220\u9664 -q \n", "!pip install -q python-dotenv\n", "!pip install -q openai"]}, {"cell_type": "code", "execution_count": 2, "id": "15a8c608-71bf-4a44-835f-0ff36cbc4533", "metadata": {"tags": []}, "outputs": [], "source": ["import os\n", "import openai\n", "from dotenv import load_dotenv, find_dotenv\n", "\n", "# \u8bfb\u53d6\u672c\u5730/\u9879\u76ee\u7684\u73af\u5883\u53d8\u91cf\u3002\n", "\n", "# find_dotenv()\u5bfb\u627e\u5e76\u5b9a\u4f4d.env\u6587\u4ef6\u7684\u8def\u5f84\n", "# load_dotenv()\u8bfb\u53d6\u8be5.env\u6587\u4ef6\uff0c\u5e76\u5c06\u5176\u4e2d\u7684\u73af\u5883\u53d8\u91cf\u52a0\u8f7d\u5230\u5f53\u524d\u7684\u8fd0\u884c\u73af\u5883\u4e2d \n", "# \u5982\u679c\u4f60\u8bbe\u7f6e\u7684\u662f\u5168\u5c40\u7684\u73af\u5883\u53d8\u91cf\uff0c\u8fd9\u884c\u4ee3\u7801\u5219\u6ca1\u6709\u4efb\u4f55\u4f5c\u7528\u3002\n", "_ = load_dotenv(find_dotenv())\n", "\n", "# \u83b7\u53d6\u73af\u5883\u53d8\u91cf OPENAI_API_KEY\n", "openai.api_key = os.environ['OPENAI_API_KEY'] "]}, {"cell_type": "markdown", "id": "28008949", "metadata": {"tags": []}, "source": ["## \u4e8c\u3001 \u521b\u5efaLLM\u5e94\u7528\n", "\u6309\u7167langchain\u94fe\u7684\u65b9\u5f0f\u8fdb\u884c\u6784\u5efa"]}, {"cell_type": "code", "execution_count": 2, "id": "974acf8e-8f88-42de-88f8-40a82cb58e8b", "metadata": {"height": 98}, "outputs": [], "source": ["from langchain.chains import RetrievalQA #\u68c0\u7d22QA\u94fe\uff0c\u5728\u6587\u6863\u4e0a\u8fdb\u884c\u68c0\u7d22\n", "from langchain.chat_models import ChatOpenAI #openai\u6a21\u578b\n", "from langchain.document_loaders import CSVLoader #\u6587\u6863\u52a0\u8f7d\u5668\uff0c\u91c7\u7528csv\u683c\u5f0f\u5b58\u50a8\n", "from langchain.indexes import VectorstoreIndexCreator #\u5bfc\u5165\u5411\u91cf\u5b58\u50a8\u7d22\u5f15\u521b\u5efa\u5668\n", "from langchain.vectorstores import DocArrayInMemorySearch #\u5411\u91cf\u5b58\u50a8\n"]}, {"cell_type": "code", "execution_count": 3, "id": "9ec1106d", "metadata": {"height": 64}, "outputs": [], "source": ["#\u52a0\u8f7d\u6570\u636e\n", "file = 'OutdoorClothingCatalog_1000.csv'\n", "loader = CSVLoader(file_path=file)\n", "data = loader.load()"]}, {"cell_type": "code", "execution_count": 4, "id": "06b1ffae", "metadata": {}, "outputs": [{"data": {"text/html": ["<div>\n", "<style scoped>\n", " .dataframe tbody tr th:only-of-type {\n", " vertical-align: middle;\n", " }\n", "\n", " .dataframe tbody tr th {\n", " vertical-align: top;\n", " }\n", "\n", " .dataframe thead th {\n", " text-align: right;\n", " }\n", "</style>\n", "<table border=\"1\" class=\"dataframe\">\n", " <thead>\n", " <tr style=\"text-align: right;\">\n", " <th></th>\n", " <th>0</th>\n", " <th>1</th>\n", " <th>2</th>\n", " </tr>\n", " </thead>\n", " <tbody>\n", " <tr>\n", " <th>0</th>\n", " <td>NaN</td>\n", " <td>name</td>\n", " <td>description</td>\n", " </tr>\n", " <tr>\n", " <th>1</th>\n", " <td>0.0</td>\n", " <td>Women's Campside Oxfords</td>\n", " <td>This ultracomfortable lace-to-toe Oxford boast...</td>\n", " </tr>\n", " <tr>\n", " <th>2</th>\n", " <td>1.0</td>\n", " <td>Recycled Waterhog Dog Mat, Chevron Weave</td>\n", " <td>Protect your floors from spills and splashing ...</td>\n", " </tr>\n", " <tr>\n", " <th>3</th>\n", " <td>2.0</td>\n", " <td>Infant and Toddler Girls' Coastal Chill Swimsu...</td>\n", " <td>She'll love the bright colors, ruffles and exc...</td>\n", " </tr>\n", " <tr>\n", " <th>4</th>\n", " <td>3.0</td>\n", " <td>Refresh Swimwear, V-Neck Tankini Contrasts</td>\n", " <td>Whether you're going for a swim or heading out...</td>\n", " </tr>\n", " <tr>\n", " <th>...</th>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " </tr>\n", " <tr>\n", " <th>996</th>\n", " <td>995.0</td>\n", " <td>Men's Classic Denim, Standard Fit</td>\n", " <td>Crafted from premium denim that will last wash...</td>\n", " </tr>\n", " <tr>\n", " <th>997</th>\n", " <td>996.0</td>\n", " <td>CozyPrint Sweater Fleece Pullover</td>\n", " <td>The ultimate sweater fleece - made from superi...</td>\n", " </tr>\n", " <tr>\n", " <th>998</th>\n", " <td>997.0</td>\n", " <td>Women's NRS Endurance Spray Paddling Pants</td>\n", " <td>These comfortable and affordable splash paddli...</td>\n", " </tr>\n", " <tr>\n", " <th>999</th>\n", " <td>998.0</td>\n", " <td>Women's Stop Flies Hoodie</td>\n", " <td>This great-looking hoodie uses No Fly Zone Tec...</td>\n", " </tr>\n", " <tr>\n", " <th>1000</th>\n", " <td>999.0</td>\n", " <td>Modern Utility Bag</td>\n", " <td>This US-made crossbody bag is built with the s...</td>\n", " </tr>\n", " </tbody>\n", "</table>\n", "<p>1001 rows \u00d7 3 columns</p>\n", "</div>"], "text/plain": [" 0 1 \\\n", "0 NaN name \n", "1 0.0 Women's Campside Oxfords \n", "2 1.0 Recycled Waterhog Dog Mat, Chevron Weave \n", "3 2.0 Infant and Toddler Girls' Coastal Chill Swimsu... \n", "4 3.0 Refresh Swimwear, V-Neck Tankini Contrasts \n", "... ... ... \n", "996 995.0 Men's Classic Denim, Standard Fit \n", "997 996.0 CozyPrint Sweater Fleece Pullover \n", "998 997.0 Women's NRS Endurance Spray Paddling Pants \n", "999 998.0 Women's Stop Flies Hoodie \n", "1000 999.0 Modern Utility Bag \n", "\n", " 2 \n", "0 description \n", "1 This ultracomfortable lace-to-toe Oxford boast... \n", "2 Protect your floors from spills and splashing ... \n", "3 She'll love the bright colors, ruffles and exc... \n", "4 Whether you're going for a swim or heading out... \n", "... ... \n", "996 Crafted from premium denim that will last wash... \n", "997 The ultimate sweater fleece - made from superi... \n", "998 These comfortable and affordable splash paddli... \n", "999 This great-looking hoodie uses No Fly Zone Tec... \n", "1000 This US-made crossbody bag is built with the s... \n", "\n", "[1001 rows x 3 columns]"]}, "execution_count": 4, "metadata": {}, "output_type": "execute_result"}], "source": ["#\u67e5\u770b\u6570\u636e\n", "import pandas as pd\n", "test_data = pd.read_csv(file,header=None)\n", "test_data"]}, {"cell_type": "code", "execution_count": 6, "id": "b31c218f", "metadata": {"height": 64}, "outputs": [{"name": "stderr", "output_type": "stream", "text": ["Retrying langchain.embeddings.openai.embed_with_retry.<locals>._embed_with_retry in 4.0 seconds as it raised RateLimitError: Rate limit reached for default-text-embedding-ada-002 in organization org-2YlJyPMl62f07XPJCAlXfDxj on tokens per min. Limit: 150000 / min. Current: 127135 / min. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n"]}], "source": ["'''\n", "\u5c06\u6307\u5b9a\u5411\u91cf\u5b58\u50a8\u7c7b,\u521b\u5efa\u5b8c\u6210\u540e\uff0c\u6211\u4eec\u5c06\u4ece\u52a0\u8f7d\u5668\u4e2d\u8c03\u7528,\u901a\u8fc7\u6587\u6863\u8bb0\u8f7d\u5668\u5217\u8868\u52a0\u8f7d\n", "'''\n", "index = VectorstoreIndexCreator(\n", " vectorstore_cls=DocArrayInMemorySearch\n", ").from_loaders([loader])"]}, {"cell_type": "code", "execution_count": 7, "id": "a2006054", "metadata": {"height": 183}, "outputs": [], "source": ["#\u901a\u8fc7\u6307\u5b9a\u8bed\u8a00\u6a21\u578b\u3001\u94fe\u7c7b\u578b\u3001\u68c0\u7d22\u5668\u548c\u6211\u4eec\u8981\u6253\u5370\u7684\u8be6\u7ec6\u7a0b\u5ea6\u6765\u521b\u5efa\u68c0\u7d22QA\u94fe\n", "llm = ChatOpenAI(temperature = 0.0)\n", "qa = RetrievalQA.from_chain_type(\n", " llm=llm, \n", " chain_type=\"stuff\", \n", " retriever=index.vectorstore.as_retriever(), \n", " verbose=True,\n", " chain_type_kwargs = {\n", " \"document_separator\": \"<<<<>>>>>\"\n", " }\n", ")"]}, {"cell_type": "markdown", "id": "791ebd73", "metadata": {}, "source": ["### 2.1 \u521b\u5efa\u8bc4\u4f30\u6570\u636e\u70b9\n", "\u6211\u4eec\u9700\u8981\u505a\u7684\u7b2c\u4e00\u4ef6\u4e8b\u662f\u771f\u6b63\u5f04\u6e05\u695a\u6211\u4eec\u60f3\u8981\u8bc4\u4f30\u5b83\u7684\u4e00\u4e9b\u6570\u636e\u70b9\uff0c\u6211\u4eec\u5c06\u4ecb\u7ecd\u51e0\u79cd\u4e0d\u540c\u7684\u65b9\u6cd5\u6765\u5b8c\u6210\u8fd9\u4e2a\u4efb\u52a1\n", "\n", "1\u3001\u5c06\u81ea\u5df1\u60f3\u51fa\u597d\u7684\u6570\u636e\u70b9\u4f5c\u4e3a\u4f8b\u5b50\uff0c\u67e5\u770b\u4e00\u4e9b\u6570\u636e\uff0c\u7136\u540e\u60f3\u51fa\u4f8b\u5b50\u95ee\u9898\u548c\u7b54\u6848\uff0c\u4ee5\u4fbf\u4ee5\u540e\u7528\u4e8e\u8bc4\u4f30"]}, {"cell_type": "code", "execution_count": 8, "id": "fb04a0f9", "metadata": {"height": 30}, "outputs": [{"data": {"text/plain": ["Document(page_content=\": 10\\nname: Cozy Comfort Pullover Set, Stripe\\ndescription: Perfect for lounging, this striped knit set lives up to its name. We used ultrasoft fabric and an easy design that's as comfortable at bedtime as it is when we have to make a quick run out.\\r\\n\\r\\nSize & Fit\\r\\n- Pants are Favorite Fit: Sits lower on the waist.\\r\\n- Relaxed Fit: Our most generous fit sits farthest from the body.\\r\\n\\r\\nFabric & Care\\r\\n- In the softest blend of 63% polyester, 35% rayon and 2% spandex.\\r\\n\\r\\nAdditional Features\\r\\n- Relaxed fit top with raglan sleeves and rounded hem.\\r\\n- Pull-on pants have a wide elastic waistband and drawstring, side pockets and a modern slim leg.\\r\\n\\r\\nImported.\", metadata={'source': 'OutdoorClothingCatalog_1000.csv', 'row': 10})"]}, "execution_count": 8, "metadata": {}, "output_type": "execute_result"}], "source": ["data[10]#\u67e5\u770b\u8fd9\u91cc\u7684\u4e00\u4e9b\u6587\u6863\uff0c\u6211\u4eec\u53ef\u4ee5\u5bf9\u5176\u4e2d\u53d1\u751f\u7684\u4e8b\u60c5\u6709\u6240\u4e86\u89e3"]}, {"cell_type": "code", "execution_count": 9, "id": "fe4a88c2", "metadata": {"height": 30}, "outputs": [{"data": {"text/plain": ["Document(page_content=': 11\\nname: Ultra-Lofty 850 Stretch Down Hooded Jacket\\ndescription: This technical stretch down jacket from our DownTek collection is sure to keep you warm and comfortable with its full-stretch construction providing exceptional range of motion. With a slightly fitted style that falls at the hip and best with a midweight layer, this jacket is suitable for light activity up to 20\u00b0 and moderate activity up to -30\u00b0. The soft and durable 100% polyester shell offers complete windproof protection and is insulated with warm, lofty goose down. Other features include welded baffles for a no-stitch construction and excellent stretch, an adjustable hood, an interior media port and mesh stash pocket and a hem drawcord. Machine wash and dry. Imported.', metadata={'source': 'OutdoorClothingCatalog_1000.csv', 'row': 11})"]}, "execution_count": 9, "metadata": {}, "output_type": "execute_result"}], "source": ["data[11]"]}, {"cell_type": "markdown", "id": "b9c52116", "metadata": {}, "source": ["\u770b\u8d77\u6765\u7b2c\u4e00\u4e2a\u6587\u6863\u4e2d\u6709\u8fd9\u4e2a\u5957\u5934\u886b\uff0c\u7b2c\u4e8c\u4e2a\u6587\u6863\u4e2d\u6709\u8fd9\u4e2a\u5939\u514b\uff0c\u4ece\u8fd9\u4e9b\u7ec6\u8282\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u521b\u5efa\u4e00\u4e9b\u4f8b\u5b50\u67e5\u8be2\u548c\u7b54\u6848"]}, {"cell_type": "markdown", "id": "8d548aef", "metadata": {}, "source": ["### 2.2 \u521b\u5efa\u6d4b\u8bd5\u7528\u4f8b\u6570\u636e\n"]}, {"cell_type": "code", "execution_count": 10, "id": "c2d59bf2", "metadata": {"height": 217}, "outputs": [], "source": ["examples = [\n", " {\n", " \"query\": \"Do the Cozy Comfort Pullover Set\\\n", " have side pockets?\",\n", " \"answer\": \"Yes\"\n", " },\n", " {\n", " \"query\": \"What collection is the Ultra-Lofty \\\n", " 850 Stretch Down Hooded Jacket from?\",\n", " \"answer\": \"The DownTek collection\"\n", " }\n", "]"]}, {"cell_type": "markdown", "id": "b73ce510", "metadata": {}, "source": ["\u56e0\u6b64\uff0c\u6211\u4eec\u53ef\u4ee5\u95ee\u4e00\u4e2a\u7b80\u5355\u7684\u95ee\u9898\uff0c\u8fd9\u4e2a\u8212\u9002\u7684\u5957\u5934\u886b\u5957\u88c5\u6709\u4fa7\u53e3\u888b\u5417\uff1f\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4e0a\u9762\u7684\u5185\u5bb9\u770b\u5230\uff0c\u5b83\u786e\u5b9e\u6709\u4e00\u4e9b\u4fa7\u53e3\u888b\uff0c\u7b54\u6848\u4e3a\u662f\n", "\u5bf9\u4e8e\u7b2c\u4e8c\u4e2a\u6587\u6863\uff0c\u6211\u4eec\u53ef\u4ee5\u770b\u5230\u8fd9\u4ef6\u5939\u514b\u6765\u81ea\u67d0\u4e2a\u7cfb\u5217\uff0c\u5373down tech\u7cfb\u5217\uff0c\u7b54\u6848\u662fdown tech\u7cfb\u5217\u3002"]}, {"cell_type": "markdown", "id": "c7ce3e4f", "metadata": {}, "source": ["### 2.3 \u901a\u8fc7LLM\u751f\u6210\u6d4b\u8bd5\u7528\u4f8b"]}, {"cell_type": "code", "execution_count": 11, "id": "d44f8376", "metadata": {"height": 47}, "outputs": [], "source": ["from langchain.evaluation.qa import QAGenerateChain #\u5bfc\u5165QA\u751f\u6210\u94fe\uff0c\u5b83\u5c06\u63a5\u6536\u6587\u6863\uff0c\u5e76\u4ece\u6bcf\u4e2a\u6587\u6863\u4e2d\u521b\u5efa\u4e00\u4e2a\u95ee\u9898\u7b54\u6848\u5bf9\n"]}, {"cell_type": "code", "execution_count": 12, "id": "34e87816", "metadata": {"height": 30}, "outputs": [], "source": ["example_gen_chain = QAGenerateChain.from_llm(ChatOpenAI())#\u901a\u8fc7\u4f20\u9012chat open AI\u8bed\u8a00\u6a21\u578b\u6765\u521b\u5efa\u8fd9\u4e2a\u94fe"]}, {"cell_type": "code", "execution_count": 13, "id": "b93e7a5d", "metadata": {}, "outputs": [{"data": {"text/plain": ["[Document(page_content=\": 0\\nname: Women's Campside Oxfords\\ndescription: This ultracomfortable lace-to-toe Oxford boasts a super-soft canvas, thick cushioning, and quality construction for a broken-in feel from the first time you put them on. \\r\\n\\r\\nSize & Fit: Order regular shoe size. For half sizes not offered, order up to next whole size. \\r\\n\\r\\nSpecs: Approx. weight: 1 lb.1 oz. per pair. \\r\\n\\r\\nConstruction: Soft canvas material for a broken-in feel and look. Comfortable EVA innersole with Cleansport NXT\u00ae antimicrobial odor control. Vintage hunt, fish and camping motif on innersole. Moderate arch contour of innersole. EVA foam midsole for cushioning and support. Chain-tread-inspired molded rubber outsole with modified chain-tread pattern. Imported. \\r\\n\\r\\nQuestions? Please contact us for any inquiries.\", metadata={'source': 'OutdoorClothingCatalog_1000.csv', 'row': 0}),\n", " Document(page_content=': 1\\nname: Recycled Waterhog Dog Mat, Chevron Weave\\ndescription: Protect your floors from spills and splashing with our ultradurable recycled Waterhog dog mat made right here in the USA. \\r\\n\\r\\nSpecs\\r\\nSmall - Dimensions: 18\" x 28\". \\r\\nMedium - Dimensions: 22.5\" x 34.5\".\\r\\n\\r\\nWhy We Love It\\r\\nMother nature, wet shoes and muddy paws have met their match with our Recycled Waterhog mats. Ruggedly constructed from recycled plastic materials, these ultratough mats help keep dirt and water off your floors and plastic out of landfills, trails and oceans. Now, that\\'s a win-win for everyone.\\r\\n\\r\\nFabric & Care\\r\\nVacuum or hose clean.\\r\\n\\r\\nConstruction\\r\\n24 oz. polyester fabric made from 94% recycled materials.\\r\\nRubber backing.\\r\\n\\r\\nAdditional Features\\r\\nFeatures an -exclusive design.\\r\\nFeatures thick and thin fibers for scraping dirt and absorbing water.\\r\\nDries quickly and resists fading, rotting, mildew and shedding.\\r\\nUse indoors or out.\\r\\nMade in the USA.\\r\\n\\r\\nHave questions? Reach out to our customer service team with any questions you may have.', metadata={'source': 'OutdoorClothingCatalog_1000.csv', 'row': 1}),\n", " Document(page_content=\": 2\\nname: Infant and Toddler Girls' Coastal Chill Swimsuit, Two-Piece\\ndescription: She'll love the bright colors, ruffles and exclusive whimsical prints of this toddler's two-piece swimsuit! Our four-way-stretch and chlorine-resistant fabric keeps its shape and resists snags. The UPF 50+ rated fabric provides the highest rated sun protection possible, blocking 98% of the sun's harmful rays. The crossover no-slip straps and fully lined bottom ensure a secure fit and maximum coverage. Machine wash and line dry for best results. Imported.\", metadata={'source': 'OutdoorClothingCatalog_1000.csv', 'row': 2}),\n", " Document(page_content=\": 3\\nname: Refresh Swimwear, V-Neck Tankini Contrasts\\ndescription: Whether you're going for a swim or heading out on an SUP, this watersport-ready tankini top is designed to move with you and stay comfortable. All while looking great in an eye-catching colorblock style. \\r\\n\\r\\nSize & Fit\\r\\nFitted: Sits close to the body.\\r\\n\\r\\nWhy We Love It\\r\\nNot only does this swimtop feel good to wear, its fabric is good for the earth too. In recycled nylon, with Lycra\u00ae spandex for the perfect amount of stretch. \\r\\n\\r\\nFabric & Care\\r\\nThe premium Italian-blend is breathable, quick drying and abrasion resistant. \\r\\nBody in 82% recycled nylon with 18% Lycra\u00ae spandex. \\r\\nLined in 90% recycled nylon with 10% Lycra\u00ae spandex. \\r\\nUPF 50+ rated \u2013 the highest rated sun protection possible. \\r\\nHandwash, line dry.\\r\\n\\r\\nAdditional Features\\r\\nLightweight racerback straps are easy to get on and off, and won't get in your way. \\r\\nFlattering V-neck silhouette. \\r\\nImported.\\r\\n\\r\\nSun Protection That Won't Wear Off\\r\\nOur high-performance fabric provides SPF\", metadata={'source': 'OutdoorClothingCatalog_1000.csv', 'row': 3}),\n", " Document(page_content=\": 4\\nname: EcoFlex 3L Storm Pants\\ndescription: Our new TEK O2 technology makes our four-season waterproof pants even more breathable. It's guaranteed to keep you dry and comfortable \u2013 whatever the activity and whatever the weather. Size & Fit: Slightly Fitted through hip and thigh. \\r\\n\\r\\nWhy We Love It: Our state-of-the-art TEK O2 technology offers the most breathability we've ever tested. Great as ski pants, they're ideal for a variety of outdoor activities year-round. Plus, they're loaded with features outdoor enthusiasts appreciate, including weather-blocking gaiters and handy side zips. Air In. Water Out. See how our air-permeable TEK O2 technology keeps you dry and comfortable. \\r\\n\\r\\nFabric & Care: 100% nylon, exclusive of trim. Machine wash and dry. \\r\\n\\r\\nAdditional Features: Three-layer shell delivers waterproof protection. Brand new TEK O2 technology provides enhanced breathability. Interior gaiters keep out rain and snow. Full side zips for easy on/off over boots. Two zippered hand pockets. Thigh pocket. Imported.\\r\\n\\r\\n \u2013 Official Supplier to the U.S. Ski Team\\r\\nTHEIR WILL\", metadata={'source': 'OutdoorClothingCatalog_1000.csv', 'row': 4})]"]}, "execution_count": 13, "metadata": {}, "output_type": "execute_result"}], "source": ["data[:5]"]}, {"cell_type": "code", "execution_count": 15, "id": "62abae09", "metadata": {"height": 64}, "outputs": [{"name": "stderr", "output_type": "stream", "text": ["Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 1.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 2.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 4.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 8.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 1.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 2.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 4.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 8.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n"]}], "source": ["new_examples = example_gen_chain.apply_and_parse(\n", " [{\"doc\": t} for t in data[:5]]\n", ") #\u6211\u4eec\u53ef\u4ee5\u521b\u5efa\u8bb8\u591a\u4f8b\u5b50"]}, {"cell_type": "code", "execution_count": 16, "id": "31c9f786", "metadata": {}, "outputs": [{"data": {"text/plain": ["[{'query': \"What is the description of the Women's Campside Oxfords?\",\n", " 'answer': \"The Women's Campside Oxfords are described as an ultracomfortable lace-to-toe Oxford made of soft canvas material, featuring thick cushioning, quality construction, and a broken-in feel from the first time they are worn.\"},\n", " {'query': 'What are the dimensions of the small and medium sizes of the Recycled Waterhog Dog Mat, Chevron Weave?',\n", " 'answer': 'The small size of the Recycled Waterhog Dog Mat, Chevron Weave has dimensions of 18\" x 28\", while the medium size has dimensions of 22.5\" x 34.5\".'},\n", " {'query': \"What are some features of the Infant and Toddler Girls' Coastal Chill Swimsuit, Two-Piece?\",\n", " 'answer': \"The swimsuit features bright colors, ruffles, and exclusive whimsical prints. It is made of a four-way-stretch and chlorine-resistant fabric that maintains its shape and resists snags. The fabric is also UPF 50+ rated, providing the highest rated sun protection possible by blocking 98% of the sun's harmful rays. The swimsuit has crossover no-slip straps and a fully lined bottom for a secure fit and maximum coverage.\"},\n", " {'query': 'What is the fabric composition of the Refresh Swimwear, V-Neck Tankini Contrasts?',\n", " 'answer': 'The Refresh Swimwear, V-Neck Tankini Contrasts is made of 82% recycled nylon with 18% Lycra\u00ae spandex for the body, and 90% recycled nylon with 10% Lycra\u00ae spandex for the lining.'},\n", " {'query': 'What is the technology used in the EcoFlex 3L Storm Pants that makes them more breathable?',\n", " 'answer': 'The EcoFlex 3L Storm Pants use TEK O2 technology to make them more breathable.'}]"]}, "execution_count": 16, "metadata": {}, "output_type": "execute_result"}], "source": ["new_examples #\u67e5\u770b\u7528\u4f8b\u6570\u636e"]}, {"cell_type": "code", "execution_count": 17, "id": "97ab28b5", "metadata": {"height": 30}, "outputs": [{"data": {"text/plain": ["{'query': \"What is the description of the Women's Campside Oxfords?\",\n", " 'answer': \"The Women's Campside Oxfords are described as an ultracomfortable lace-to-toe Oxford made of soft canvas material, featuring thick cushioning, quality construction, and a broken-in feel from the first time they are worn.\"}"]}, "execution_count": 17, "metadata": {}, "output_type": "execute_result"}], "source": ["new_examples[0]"]}, {"cell_type": "code", "execution_count": 18, "id": "0ebe4228", "metadata": {"height": 30}, "outputs": [{"data": {"text/plain": ["Document(page_content=\": 0\\nname: Women's Campside Oxfords\\ndescription: This ultracomfortable lace-to-toe Oxford boasts a super-soft canvas, thick cushioning, and quality construction for a broken-in feel from the first time you put them on. \\r\\n\\r\\nSize & Fit: Order regular shoe size. For half sizes not offered, order up to next whole size. \\r\\n\\r\\nSpecs: Approx. weight: 1 lb.1 oz. per pair. \\r\\n\\r\\nConstruction: Soft canvas material for a broken-in feel and look. Comfortable EVA innersole with Cleansport NXT\u00ae antimicrobial odor control. Vintage hunt, fish and camping motif on innersole. Moderate arch contour of innersole. EVA foam midsole for cushioning and support. Chain-tread-inspired molded rubber outsole with modified chain-tread pattern. Imported. \\r\\n\\r\\nQuestions? Please contact us for any inquiries.\", metadata={'source': 'OutdoorClothingCatalog_1000.csv', 'row': 0})"]}, "execution_count": 18, "metadata": {}, "output_type": "execute_result"}], "source": ["data[0]"]}, {"cell_type": "markdown", "id": "faf25f2f", "metadata": {}, "source": ["### 2.4 \u7ec4\u5408\u7528\u4f8b\u6570\u636e"]}, {"cell_type": "code", "execution_count": 19, "id": "ada2a3fc", "metadata": {"height": 30}, "outputs": [], "source": ["examples += new_examples"]}, {"cell_type": "code", "execution_count": 20, "id": "9cdf5cf5", "metadata": {"height": 30}, "outputs": [{"name": "stdout", "output_type": "stream", "text": ["\n", "\n", "\u001b[1m> Entering new chain...\u001b[0m\n", "\n", "\u001b[1m> Finished chain.\u001b[0m\n"]}, {"data": {"text/plain": ["'Yes, the Cozy Comfort Pullover Set does have side pockets.'"]}, "execution_count": 20, "metadata": {}, "output_type": "execute_result"}], "source": ["qa.run(examples[0][\"query\"])"]}, {"cell_type": "code", "execution_count": null, "id": "f3b8371c-f4ed-4f33-8bda-10f281e62e83", "metadata": {}, "outputs": [], "source": []}, {"cell_type": "markdown", "id": "6f596f04-012a-4fbd-8de1-d849dfa7a837", "metadata": {"tags": []}, "source": ["\n", "### 2.5 \u4e2d\u6587\u7248\n", "\u6309\u7167langchain\u94fe\u7684\u65b9\u5f0f\u8fdb\u884c\u6784\u5efa"]}, {"cell_type": "code", "execution_count": null, "id": "c045628e", "metadata": {}, "outputs": [], "source": ["from langchain.chains import RetrievalQA #\u68c0\u7d22QA\u94fe\uff0c\u5728\u6587\u6863\u4e0a\u8fdb\u884c\u68c0\u7d22\n", "from langchain.chat_models import ChatOpenAI #openai\u6a21\u578b\n", "from langchain.document_loaders import CSVLoader #\u6587\u6863\u52a0\u8f7d\u5668\uff0c\u91c7\u7528csv\u683c\u5f0f\u5b58\u50a8\n", "from langchain.indexes import VectorstoreIndexCreator #\u5bfc\u5165\u5411\u91cf\u5b58\u50a8\u7d22\u5f15\u521b\u5efa\u5668\n", "from langchain.vectorstores import DocArrayInMemorySearch #\u5411\u91cf\u5b58\u50a8\n"]}, {"cell_type": "code", "execution_count": null, "id": "bfd04e93", "metadata": {}, "outputs": [], "source": ["#\u52a0\u8f7d\u4e2d\u6587\u6570\u636e\n", "file = 'product_data.csv'\n", "loader = CSVLoader(file_path=file)\n", "data = loader.load()"]}, {"cell_type": "code", "execution_count": null, "id": "da8eb973", "metadata": {}, "outputs": [{"data": {"text/html": ["<div>\n", "<style scoped>\n", " .dataframe tbody tr th:only-of-type {\n", " vertical-align: middle;\n", " }\n", "\n", " .dataframe tbody tr th {\n", " vertical-align: top;\n", " }\n", "\n", " .dataframe thead th {\n", " text-align: right;\n", " }\n", "</style>\n", "<table border=\"1\" class=\"dataframe\">\n", " <thead>\n", " <tr style=\"text-align: right;\">\n", " <th></th>\n", " <th>0</th>\n", " <th>1</th>\n", " </tr>\n", " </thead>\n", " <tbody>\n", " <tr>\n", " <th>0</th>\n", " <td>product_name</td>\n", " <td>description</td>\n", " </tr>\n", " <tr>\n", " <th>1</th>\n", " <td>\u5168\u81ea\u52a8\u5496\u5561\u673a</td>\n", " <td>\u89c4\u683c:\\n\u5927\u578b - \u5c3a\u5bf8\uff1a13.8'' x 17.3''\u3002\\n\u4e2d\u578b - \u5c3a\u5bf8\uff1a11.5'' ...</td>\n", " </tr>\n", " <tr>\n", " <th>2</th>\n", " <td>\u7535\u52a8\u7259\u5237</td>\n", " <td>\u89c4\u683c:\\n\u4e00\u822c\u5927\u5c0f - \u9ad8\u5ea6\uff1a9.5''\uff0c\u5bbd\u5ea6\uff1a1''\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u6211\u4eec\u7684...</td>\n", " </tr>\n", " <tr>\n", " <th>3</th>\n", " <td>\u6a59\u5473\u7ef4\u751f\u7d20C\u6ce1\u817e\u7247</td>\n", " <td>\u89c4\u683c:\\n\u6bcf\u76d2\u542b\u670920\u7247\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u6211\u4eec\u7684\u6a59\u5473\u7ef4\u751f\u7d20C\u6ce1\u817e\u7247\u662f\u5feb\u901f\u8865\u5145\u7ef4...</td>\n", " </tr>\n", " <tr>\n", " <th>4</th>\n", " <td>\u65e0\u7ebf\u84dd\u7259\u8033\u673a</td>\n", " <td>\u89c4\u683c:\\n\u5355\u4e2a\u8033\u673a\u5c3a\u5bf8\uff1a1.5'' x 1.3''\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u8fd9\u6b3e\u65e0\u7ebf\u84dd...</td>\n", " </tr>\n", " <tr>\n", " <th>5</th>\n", " <td>\u745c\u4f3d\u57ab</td>\n", " <td>\u89c4\u683c:\\n\u5c3a\u5bf8\uff1a24'' x 68''\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u6211\u4eec\u7684\u745c\u4f3d\u57ab\u62e5\u6709\u51fa\u8272\u7684...</td>\n", " </tr>\n", " <tr>\n", " <th>6</th>\n", " <td>\u9632\u6c34\u8fd0\u52a8\u624b\u8868</td>\n", " <td>\u89c4\u683c:\\n\u8868\u76d8\u76f4\u5f84\uff1a40mm\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u8fd9\u6b3e\u9632\u6c34\u8fd0\u52a8\u624b\u8868\u914d\u5907\u4e86\u5fc3\u7387\u76d1\u6d4b\u548c...</td>\n", " </tr>\n", " <tr>\n", " <th>7</th>\n", " <td>\u4e66\u7c4d:\u300a\u673a\u5668\u5b66\u4e60\u57fa\u7840\u300b</td>\n", " <td>\u89c4\u683c:\\n\u9875\u6570\uff1a580\u9875\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u300a\u673a\u5668\u5b66\u4e60\u57fa\u7840\u300b\u4ee5\u6613\u61c2\u7684\u8bed\u8a00\u8bb2\u89e3\u4e86\u673a...</td>\n", " </tr>\n", " <tr>\n", " <th>8</th>\n", " <td>\u7a7a\u6c14\u51c0\u5316\u5668</td>\n", " <td>\u89c4\u683c:\\n\u5c3a\u5bf8\uff1a15'' x 15'' x 20''\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u6211\u4eec\u7684\u7a7a...</td>\n", " </tr>\n", " <tr>\n", " <th>9</th>\n", " <td>\u9676\u74f7\u4fdd\u6e29\u676f</td>\n", " <td>\u89c4\u683c:\\n\u5bb9\u91cf\uff1a350ml\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u6211\u4eec\u7684\u9676\u74f7\u4fdd\u6e29\u676f\u8bbe\u8ba1\u4f18\u96c5\uff0c\u4fdd\u6e29\u6548\u679c...</td>\n", " </tr>\n", " <tr>\n", " <th>10</th>\n", " <td>\u5ba0\u7269\u81ea\u52a8\u5582\u98df\u5668</td>\n", " <td>\u89c4\u683c:\\n\u5c3a\u5bf8\uff1a14'' x 9'' x 15''\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u6211\u4eec\u7684\u5ba0\u7269...</td>\n", " </tr>\n", " <tr>\n", " <th>11</th>\n", " <td>\u9ad8\u6e05\u7535\u89c6\u673a</td>\n", " <td>\u89c4\u683c:\\n\u5c3a\u5bf8\uff1a50''\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u6211\u4eec\u7684\u9ad8\u6e05\u7535\u89c6\u673a\u62e5\u6709\u51fa\u8272\u7684\u753b\u8d28\u548c\u5f3a\u5927...</td>\n", " </tr>\n", " <tr>\n", " <th>12</th>\n", " <td>\u65c5\u884c\u80cc\u5305</td>\n", " <td>\u89c4\u683c:\\n\u5c3a\u5bf8\uff1a18'' x 12'' x 6''\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u6211\u4eec\u7684\u65c5\u884c...</td>\n", " </tr>\n", " <tr>\n", " <th>13</th>\n", " <td>\u592a\u9633\u80fd\u5ead\u9662\u706f</td>\n", " <td>\u89c4\u683c:\\n\u9ad8\u5ea6\uff1a18''\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u6211\u4eec\u7684\u592a\u9633\u80fd\u5ead\u9662\u706f\u65e0\u9700\u7535\u6e90\uff0c\u53ea\u9700\u5c06\u5176...</td>\n", " </tr>\n", " <tr>\n", " <th>14</th>\n", " <td>\u53a8\u623f\u5200\u5177\u5957\u88c5</td>\n", " <td>\u89c4\u683c:\\n\u4e00\u5957\u5305\u62ec8\u628a\u5200\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u6211\u4eec\u7684\u53a8\u623f\u5200\u5177\u5957\u88c5\u7531\u4e13\u4e1a\u7ea7\u4e0d\u9508\u94a2\u5236\u6210...</td>\n", " </tr>\n", " <tr>\n", " <th>15</th>\n", " <td>\u8ff7\u4f60\u65e0\u7ebf\u84dd\u7259\u97f3\u7bb1</td>\n", " <td>\u89c4\u683c:\\n\u76f4\u5f84\uff1a3''\uff0c\u9ad8\u5ea6\uff1a2''\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u6211\u4eec\u7684\u8ff7\u4f60\u65e0\u7ebf\u84dd\u7259\u97f3\u7bb1\u4f53...</td>\n", " </tr>\n", " <tr>\n", " <th>16</th>\n", " <td>\u6297\u83cc\u6d17\u624b\u6db2</td>\n", " <td>\u89c4\u683c:\\n\u5bb9\u91cf\uff1a500ml\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u6211\u4eec\u7684\u6297\u83cc\u6d17\u624b\u6db2\u542b\u6709\u5929\u7136\u690d\u7269\u7cbe\u534e\uff0c...</td>\n", " </tr>\n", " <tr>\n", " <th>17</th>\n", " <td>\u7eaf\u68c9T\u6064</td>\n", " <td>\u89c4\u683c:\\n\u5c3a\u7801\uff1aS, M, L, XL, XXL\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u6211\u4eec\u7684\u7eaf\u68c9T...</td>\n", " </tr>\n", " <tr>\n", " <th>18</th>\n", " <td>\u81ea\u52a8\u5496\u5561\u673a</td>\n", " <td>\u89c4\u683c:\\n\u5c3a\u5bf8\uff1a12'' x 8'' x 14''\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u6211\u4eec\u7684\u81ea\u52a8...</td>\n", " </tr>\n", " <tr>\n", " <th>19</th>\n", " <td>\u6444\u50cf\u5934\u4fdd\u62a4\u5957</td>\n", " <td>\u89c4\u683c:\\n\u9002\u7528\u4e8e\u5404\u79cd\u54c1\u724c\u548c\u578b\u53f7\u7684\u6444\u50cf\u5934\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u6211\u4eec\u7684\u6444\u50cf\u5934\u4fdd\u62a4\u5957\u53ef\u4ee5...</td>\n", " </tr>\n", " <tr>\n", " <th>20</th>\n", " <td>\u73bb\u7483\u4fdd\u62a4\u819c</td>\n", " <td>\u89c4\u683c:\\n\u9002\u7528\u4e8e\u5404\u79cd\u5c3a\u5bf8\u7684\u624b\u673a\u5c4f\u5e55\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u6211\u4eec\u7684\u73bb\u7483\u4fdd\u62a4\u819c\u53ef\u4ee5\u6709\u6548\u9632...</td>\n", " </tr>\n", " <tr>\n", " <th>21</th>\n", " <td>\u513f\u7ae5\u76ca\u667a\u73a9\u5177</td>\n", " <td>\u89c4\u683c:\\n\u9002\u54083\u5c81\u4ee5\u4e0a\u7684\u513f\u7ae5\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u6211\u4eec\u7684\u513f\u7ae5\u76ca\u667a\u73a9\u5177\u8bbe\u8ba1\u72ec\u7279\uff0c\u8272\u5f69...</td>\n", " </tr>\n", " <tr>\n", " <th>22</th>\n", " <td>\u8ff7\u4f60\u4e66\u67b6</td>\n", " <td>\u89c4\u683c:\\n\u5c3a\u5bf8\uff1a20'' x 8'' x 24''\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u6211\u4eec\u7684\u8ff7\u4f60...</td>\n", " </tr>\n", " <tr>\n", " <th>23</th>\n", " <td>\u9632\u6ed1\u745c\u4f3d\u57ab</td>\n", " <td>\u89c4\u683c:\\n\u5c3a\u5bf8\uff1a72'' x 24''\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u6211\u4eec\u7684\u9632\u6ed1\u745c\u4f3d\u57ab\u91c7\u7528\u9ad8...</td>\n", " </tr>\n", " <tr>\n", " <th>24</th>\n", " <td>LED\u53f0\u706f</td>\n", " <td>\u89c4\u683c:\\n\u5c3a\u5bf8\uff1a6'' x 6'' x 18''\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u6211\u4eec\u7684LED...</td>\n", " </tr>\n", " <tr>\n", " <th>25</th>\n", " <td>\u6c34\u6676\u9152\u676f</td>\n", " <td>\u89c4\u683c:\\n\u5bb9\u91cf\uff1a250ml\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u6211\u4eec\u7684\u6c34\u6676\u9152\u676f\u91c7\u7528\u9ad8\u54c1\u8d28\u6c34\u6676\u73bb\u7483\u5236...</td>\n", " </tr>\n", " </tbody>\n", "</table>\n", "</div>"], "text/plain": [" 0 1\n", "0 product_name description\n", "1 \u5168\u81ea\u52a8\u5496\u5561\u673a \u89c4\u683c:\\n\u5927\u578b - \u5c3a\u5bf8\uff1a13.8'' x 17.3''\u3002\\n\u4e2d\u578b - \u5c3a\u5bf8\uff1a11.5'' ...\n", "2 \u7535\u52a8\u7259\u5237 \u89c4\u683c:\\n\u4e00\u822c\u5927\u5c0f - \u9ad8\u5ea6\uff1a9.5''\uff0c\u5bbd\u5ea6\uff1a1''\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u6211\u4eec\u7684...\n", "3 \u6a59\u5473\u7ef4\u751f\u7d20C\u6ce1\u817e\u7247 \u89c4\u683c:\\n\u6bcf\u76d2\u542b\u670920\u7247\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u6211\u4eec\u7684\u6a59\u5473\u7ef4\u751f\u7d20C\u6ce1\u817e\u7247\u662f\u5feb\u901f\u8865\u5145\u7ef4...\n", "4 \u65e0\u7ebf\u84dd\u7259\u8033\u673a \u89c4\u683c:\\n\u5355\u4e2a\u8033\u673a\u5c3a\u5bf8\uff1a1.5'' x 1.3''\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u8fd9\u6b3e\u65e0\u7ebf\u84dd...\n", "5 \u745c\u4f3d\u57ab \u89c4\u683c:\\n\u5c3a\u5bf8\uff1a24'' x 68''\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u6211\u4eec\u7684\u745c\u4f3d\u57ab\u62e5\u6709\u51fa\u8272\u7684...\n", "6 \u9632\u6c34\u8fd0\u52a8\u624b\u8868 \u89c4\u683c:\\n\u8868\u76d8\u76f4\u5f84\uff1a40mm\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u8fd9\u6b3e\u9632\u6c34\u8fd0\u52a8\u624b\u8868\u914d\u5907\u4e86\u5fc3\u7387\u76d1\u6d4b\u548c...\n", "7 \u4e66\u7c4d:\u300a\u673a\u5668\u5b66\u4e60\u57fa\u7840\u300b \u89c4\u683c:\\n\u9875\u6570\uff1a580\u9875\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u300a\u673a\u5668\u5b66\u4e60\u57fa\u7840\u300b\u4ee5\u6613\u61c2\u7684\u8bed\u8a00\u8bb2\u89e3\u4e86\u673a...\n", "8 \u7a7a\u6c14\u51c0\u5316\u5668 \u89c4\u683c:\\n\u5c3a\u5bf8\uff1a15'' x 15'' x 20''\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u6211\u4eec\u7684\u7a7a...\n", "9 \u9676\u74f7\u4fdd\u6e29\u676f \u89c4\u683c:\\n\u5bb9\u91cf\uff1a350ml\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u6211\u4eec\u7684\u9676\u74f7\u4fdd\u6e29\u676f\u8bbe\u8ba1\u4f18\u96c5\uff0c\u4fdd\u6e29\u6548\u679c...\n", "10 \u5ba0\u7269\u81ea\u52a8\u5582\u98df\u5668 \u89c4\u683c:\\n\u5c3a\u5bf8\uff1a14'' x 9'' x 15''\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u6211\u4eec\u7684\u5ba0\u7269...\n", "11 \u9ad8\u6e05\u7535\u89c6\u673a \u89c4\u683c:\\n\u5c3a\u5bf8\uff1a50''\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u6211\u4eec\u7684\u9ad8\u6e05\u7535\u89c6\u673a\u62e5\u6709\u51fa\u8272\u7684\u753b\u8d28\u548c\u5f3a\u5927...\n", "12 \u65c5\u884c\u80cc\u5305 \u89c4\u683c:\\n\u5c3a\u5bf8\uff1a18'' x 12'' x 6''\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u6211\u4eec\u7684\u65c5\u884c...\n", "13 \u592a\u9633\u80fd\u5ead\u9662\u706f \u89c4\u683c:\\n\u9ad8\u5ea6\uff1a18''\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u6211\u4eec\u7684\u592a\u9633\u80fd\u5ead\u9662\u706f\u65e0\u9700\u7535\u6e90\uff0c\u53ea\u9700\u5c06\u5176...\n", "14 \u53a8\u623f\u5200\u5177\u5957\u88c5 \u89c4\u683c:\\n\u4e00\u5957\u5305\u62ec8\u628a\u5200\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u6211\u4eec\u7684\u53a8\u623f\u5200\u5177\u5957\u88c5\u7531\u4e13\u4e1a\u7ea7\u4e0d\u9508\u94a2\u5236\u6210...\n", "15 \u8ff7\u4f60\u65e0\u7ebf\u84dd\u7259\u97f3\u7bb1 \u89c4\u683c:\\n\u76f4\u5f84\uff1a3''\uff0c\u9ad8\u5ea6\uff1a2''\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u6211\u4eec\u7684\u8ff7\u4f60\u65e0\u7ebf\u84dd\u7259\u97f3\u7bb1\u4f53...\n", "16 \u6297\u83cc\u6d17\u624b\u6db2 \u89c4\u683c:\\n\u5bb9\u91cf\uff1a500ml\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u6211\u4eec\u7684\u6297\u83cc\u6d17\u624b\u6db2\u542b\u6709\u5929\u7136\u690d\u7269\u7cbe\u534e\uff0c...\n", "17 \u7eaf\u68c9T\u6064 \u89c4\u683c:\\n\u5c3a\u7801\uff1aS, M, L, XL, XXL\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u6211\u4eec\u7684\u7eaf\u68c9T...\n", "18 \u81ea\u52a8\u5496\u5561\u673a \u89c4\u683c:\\n\u5c3a\u5bf8\uff1a12'' x 8'' x 14''\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u6211\u4eec\u7684\u81ea\u52a8...\n", "19 \u6444\u50cf\u5934\u4fdd\u62a4\u5957 \u89c4\u683c:\\n\u9002\u7528\u4e8e\u5404\u79cd\u54c1\u724c\u548c\u578b\u53f7\u7684\u6444\u50cf\u5934\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u6211\u4eec\u7684\u6444\u50cf\u5934\u4fdd\u62a4\u5957\u53ef\u4ee5...\n", "20 \u73bb\u7483\u4fdd\u62a4\u819c \u89c4\u683c:\\n\u9002\u7528\u4e8e\u5404\u79cd\u5c3a\u5bf8\u7684\u624b\u673a\u5c4f\u5e55\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u6211\u4eec\u7684\u73bb\u7483\u4fdd\u62a4\u819c\u53ef\u4ee5\u6709\u6548\u9632...\n", "21 \u513f\u7ae5\u76ca\u667a\u73a9\u5177 \u89c4\u683c:\\n\u9002\u54083\u5c81\u4ee5\u4e0a\u7684\u513f\u7ae5\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u6211\u4eec\u7684\u513f\u7ae5\u76ca\u667a\u73a9\u5177\u8bbe\u8ba1\u72ec\u7279\uff0c\u8272\u5f69...\n", "22 \u8ff7\u4f60\u4e66\u67b6 \u89c4\u683c:\\n\u5c3a\u5bf8\uff1a20'' x 8'' x 24''\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u6211\u4eec\u7684\u8ff7\u4f60...\n", "23 \u9632\u6ed1\u745c\u4f3d\u57ab \u89c4\u683c:\\n\u5c3a\u5bf8\uff1a72'' x 24''\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u6211\u4eec\u7684\u9632\u6ed1\u745c\u4f3d\u57ab\u91c7\u7528\u9ad8...\n", "24 LED\u53f0\u706f \u89c4\u683c:\\n\u5c3a\u5bf8\uff1a6'' x 6'' x 18''\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u6211\u4eec\u7684LED...\n", "25 \u6c34\u6676\u9152\u676f \u89c4\u683c:\\n\u5bb9\u91cf\uff1a250ml\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u6211\u4eec\u7684\u6c34\u6676\u9152\u676f\u91c7\u7528\u9ad8\u54c1\u8d28\u6c34\u6676\u73bb\u7483\u5236..."]}, "metadata": {}, "output_type": "display_data"}], "source": ["#\u67e5\u770b\u6570\u636e\n", "import pandas as pd\n", "test_data = pd.read_csv(file,header=None)\n", "test_data"]}, {"cell_type": "code", "execution_count": null, "id": "95890a3b", "metadata": {}, "outputs": [], "source": ["'''\n", "\u5c06\u6307\u5b9a\u5411\u91cf\u5b58\u50a8\u7c7b,\u521b\u5efa\u5b8c\u6210\u540e\uff0c\u6211\u4eec\u5c06\u4ece\u52a0\u8f7d\u5668\u4e2d\u8c03\u7528,\u901a\u8fc7\u6587\u6863\u8bb0\u8f7d\u5668\u5217\u8868\u52a0\u8f7d\n", "'''\n", "index = VectorstoreIndexCreator(\n", " vectorstore_cls=DocArrayInMemorySearch\n", ").from_loaders([loader])"]}, {"cell_type": "code", "execution_count": null, "id": "f5230594", "metadata": {}, "outputs": [], "source": ["#\u901a\u8fc7\u6307\u5b9a\u8bed\u8a00\u6a21\u578b\u3001\u94fe\u7c7b\u578b\u3001\u68c0\u7d22\u5668\u548c\u6211\u4eec\u8981\u6253\u5370\u7684\u8be6\u7ec6\u7a0b\u5ea6\u6765\u521b\u5efa\u68c0\u7d22QA\u94fe\n", "llm = ChatOpenAI(temperature = 0.0)\n", "qa = RetrievalQA.from_chain_type(\n", " llm=llm, \n", " chain_type=\"stuff\", \n", " retriever=index.vectorstore.as_retriever(), \n", " verbose=True,\n", " chain_type_kwargs = {\n", " \"document_separator\": \"<<<<>>>>>\"\n", " }\n", ")"]}, {"cell_type": "markdown", "id": "77e98983-3bf8-4a47-86ed-9eff5a52d1fd", "metadata": {}, "source": ["#### \u521b\u5efa\u8bc4\u4f30\u6570\u636e\u70b9\n", "\u6211\u4eec\u9700\u8981\u505a\u7684\u7b2c\u4e00\u4ef6\u4e8b\u662f\u771f\u6b63\u5f04\u6e05\u695a\u6211\u4eec\u60f3\u8981\u8bc4\u4f30\u5b83\u7684\u4e00\u4e9b\u6570\u636e\u70b9\uff0c\u6211\u4eec\u5c06\u4ecb\u7ecd\u51e0\u79cd\u4e0d\u540c\u7684\u65b9\u6cd5\u6765\u5b8c\u6210\u8fd9\u4e2a\u4efb\u52a1\n", "\n", "1\u3001\u5c06\u81ea\u5df1\u60f3\u51fa\u597d\u7684\u6570\u636e\u70b9\u4f5c\u4e3a\u4f8b\u5b50\uff0c\u67e5\u770b\u4e00\u4e9b\u6570\u636e\uff0c\u7136\u540e\u60f3\u51fa\u4f8b\u5b50\u95ee\u9898\u548c\u7b54\u6848\uff0c\u4ee5\u4fbf\u4ee5\u540e\u7528\u4e8e\u8bc4\u4f30"]}, {"cell_type": "code", "execution_count": null, "id": "eae9bd65", "metadata": {}, "outputs": [{"data": {"text/plain": ["Document(page_content=\"product_name: \u9ad8\u6e05\u7535\u89c6\u673a\\ndescription: \u89c4\u683c:\\n\u5c3a\u5bf8\uff1a50''\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u6211\u4eec\u7684\u9ad8\u6e05\u7535\u89c6\u673a\u62e5\u6709\u51fa\u8272\u7684\u753b\u8d28\u548c\u5f3a\u5927\u7684\u97f3\u6548\uff0c\u5e26\u6765\u6c89\u6d78\u5f0f\u7684\u89c2\u770b\u4f53\u9a8c\u3002\\n\\n\u6750\u8d28\u4e0e\u62a4\u7406:\\n\u4f7f\u7528\u5e72\u5e03\u6e05\u6d01\u3002\\n\\n\u6784\u9020:\\n\u7531\u5851\u6599\u3001\u91d1\u5c5e\u548c\u7535\u5b50\u5143\u4ef6\u5236\u6210\u3002\\n\\n\u5176\u4ed6\u7279\u6027:\\n\u652f\u6301\u7f51\u7edc\u8fde\u63a5\uff0c\u53ef\u4ee5\u5728\u7ebf\u89c2\u770b\u89c6\u9891\u3002\\n\u914d\u5907\u9065\u63a7\u5668\u3002\\n\u5728\u97e9\u56fd\u5236\u9020\u3002\\n\\n\u6709\u95ee\u9898\uff1f\u8bf7\u968f\u65f6\u8054\u7cfb\u6211\u4eec\u7684\u5ba2\u6237\u670d\u52a1\u56e2\u961f\uff0c\u4ed6\u4eec\u4f1a\u89e3\u7b54\u60a8\u7684\u6240\u6709\u95ee\u9898\u3002\", metadata={'source': 'product_data.csv', 'row': 10})"]}, "metadata": {}, "output_type": "display_data"}], "source": ["data[10]#\u67e5\u770b\u8fd9\u91cc\u7684\u4e00\u4e9b\u6587\u6863\uff0c\u6211\u4eec\u53ef\u4ee5\u5bf9\u5176\u4e2d\u53d1\u751f\u7684\u4e8b\u60c5\u6709\u6240\u4e86\u89e3"]}, {"cell_type": "code", "execution_count": null, "id": "5ef28a34", "metadata": {}, "outputs": [{"data": {"text/plain": ["Document(page_content=\"product_name: \u65c5\u884c\u80cc\u5305\\ndescription: \u89c4\u683c:\\n\u5c3a\u5bf8\uff1a18'' x 12'' x 6''\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u6211\u4eec\u7684\u65c5\u884c\u80cc\u5305\u62e5\u6709\u591a\u4e2a\u5b9e\u7528\u7684\u5185\u5916\u888b\uff0c\u8f7b\u677e\u88c5\u4e0b\u60a8\u7684\u5fc5\u9700\u54c1\uff0c\u662f\u77ed\u9014\u65c5\u884c\u7684\u7406\u60f3\u9009\u62e9\u3002\\n\\n\u6750\u8d28\u4e0e\u62a4\u7406:\\n\u53ef\u4ee5\u624b\u6d17\uff0c\u81ea\u7136\u667e\u5e72\u3002\\n\\n\u6784\u9020:\\n\u7531\u9632\u6c34\u5c3c\u9f99\u5236\u6210\u3002\\n\\n\u5176\u4ed6\u7279\u6027:\\n\u9644\u5e26\u53ef\u8c03\u8282\u80cc\u5e26\u548c\u5b89\u5168\u9501\u3002\\n\u5728\u4e2d\u56fd\u5236\u9020\u3002\\n\\n\u6709\u95ee\u9898\uff1f\u8bf7\u968f\u65f6\u8054\u7cfb\u6211\u4eec\u7684\u5ba2\u6237\u670d\u52a1\u56e2\u961f\uff0c\u4ed6\u4eec\u4f1a\u89e3\u7b54\u60a8\u7684\u6240\u6709\u95ee\u9898\u3002\", metadata={'source': 'product_data.csv', 'row': 11})"]}, "metadata": {}, "output_type": "display_data"}], "source": ["data[11]"]}, {"cell_type": "markdown", "id": "c6166702-b575-4fee-b7fa-270fe6cdeb0b", "metadata": {}, "source": ["\u770b\u4e0a\u9762\u7684\u7b2c\u4e00\u4e2a\u6587\u6863\u4e2d\u6709\u9ad8\u6e05\u7535\u89c6\u673a\uff0c\u7b2c\u4e8c\u4e2a\u6587\u6863\u4e2d\u6709\u65c5\u884c\u80cc\u5305\uff0c\u4ece\u8fd9\u4e9b\u7ec6\u8282\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u521b\u5efa\u4e00\u4e9b\u4f8b\u5b50\u67e5\u8be2\u548c\u7b54\u6848"]}, {"cell_type": "markdown", "id": "0889d24e-fa2d-4c53-baf0-c55ad1c46668", "metadata": {}, "source": ["#### \u521b\u5efa\u6d4b\u8bd5\u7528\u4f8b\u6570\u636e\n"]}, {"cell_type": "code", "execution_count": null, "id": "8936f72d", "metadata": {}, "outputs": [], "source": ["examples = [\n", " {\n", " \"query\": \"\u9ad8\u6e05\u7535\u89c6\u673a\u600e\u4e48\u8fdb\u884c\u62a4\u7406\uff1f\",\n", " \"answer\": \"\u4f7f\u7528\u5e72\u5e03\u6e05\u6d01\u3002\"\n", " },\n", " {\n", " \"query\": \"\u65c5\u884c\u80cc\u5305\u6709\u5185\u5916\u888b\u5417\uff1f\",\n", " \"answer\": \"\u6709\u3002\"\n", " }\n", "]"]}, {"cell_type": "markdown", "id": "0ff2e0fd-15e6-4502-930a-57ffb06c5723", "metadata": {}, "source": ["#### \u901a\u8fc7LLM\u751f\u6210\u6d4b\u8bd5\u7528\u4f8b"]}, {"cell_type": "code", "execution_count": null, "id": "d9c7342c", "metadata": {}, "outputs": [], "source": ["from langchain.evaluation.qa import QAGenerateChain #\u5bfc\u5165QA\u751f\u6210\u94fe\uff0c\u5b83\u5c06\u63a5\u6536\u6587\u6863\uff0c\u5e76\u4ece\u6bcf\u4e2a\u6587\u6863\u4e2d\u521b\u5efa\u4e00\u4e2a\u95ee\u9898\u7b54\u6848\u5bf9\n"]}, {"cell_type": "markdown", "id": "f654a5d3-fbc1-427c-b231-d8e93aa10a14", "metadata": {}, "source": ["\u7531\u4e8e`QAGenerateChain`\u7c7b\u4e2d\u4f7f\u7528\u7684`PROMPT`\u662f\u82f1\u6587\uff0c\u6545\u6211\u4eec\u7ee7\u627f`QAGenerateChain`\u7c7b\uff0c\u5c06`PROMPT`\u52a0\u4e0a\u201c\u8bf7\u4f7f\u7528\u4e2d\u6587\u8f93\u51fa\u201d\u3002"]}, {"cell_type": "markdown", "id": "63142d22-04fd-4bf3-b321-8da183c099b3", "metadata": {}, "source": ["\u4e0b\u9762\u662f`generate_chain.py`\u6587\u4ef6\u4e2d\u7684`QAGenerateChain`\u7c7b\u7684\u6e90\u7801"]}, {"cell_type": "code", "execution_count": 35, "id": "0401f602", "metadata": {}, "outputs": [], "source": ["\"\"\"LLM Chain specifically for generating examples for question answering.\"\"\"\n", "from __future__ import annotations\n", "\n", "from typing import Any\n", "\n", "from langchain.base_language import BaseLanguageModel\n", "from langchain.chains.llm import LLMChain\n", "from langchain.evaluation.qa.generate_prompt import PROMPT\n", "\n", "class QAGenerateChain(LLMChain):\n", " \"\"\"LLM Chain specifically for generating examples for question answering.\"\"\"\n", "\n", " @classmethod\n", " def from_llm(cls, llm: BaseLanguageModel, **kwargs: Any) -> QAGenerateChain:\n", " \"\"\"Load QA Generate Chain from LLM.\"\"\"\n", " return cls(llm=llm, prompt=PROMPT, **kwargs)"]}, {"cell_type": "code", "execution_count": 36, "id": "9fb1e63e", "metadata": {}, "outputs": [{"data": {"text/plain": ["PromptTemplate(input_variables=['doc'], output_parser=RegexParser(regex='QUESTION: (.*?)\\\\nANSWER: (.*)', output_keys=['query', 'answer'], default_output_key=None), partial_variables={}, template='You are a teacher coming up with questions to ask on a quiz. \\nGiven the following document, please generate a question and answer based on that document.\\n\\nExample Format:\\n<Begin Document>\\n...\\n<End Document>\\nQUESTION: question here\\nANSWER: answer here\\n\\nThese questions should be detailed and be based explicitly on information in the document. Begin!\\n\\n<Begin Document>\\n{doc}\\n<End Document>\\n\u8bf7\u7528\u4e2d\u6587\u3002', template_format='f-string', validate_template=True)"]}, "execution_count": 36, "metadata": {}, "output_type": "execute_result"}], "source": ["PROMPT"]}, {"cell_type": "markdown", "id": "be0ac6b7-0bc5-4f10-a160-a98fb69f1953", "metadata": {}, "source": ["\u6211\u4eec\u53ef\u4ee5\u770b\u5230`PROMPT`\u4e3a\u82f1\u6587\uff0c\u4e0b\u9762\u6211\u4eec\u5c06`PROMPT`\u6dfb\u52a0\u4e0a\u201c\u8bf7\u4f7f\u7528\u4e2d\u6587\u8f93\u51fa\u201d"]}, {"cell_type": "code", "execution_count": 43, "id": "a33dc3af", "metadata": {}, "outputs": [{"data": {"text/plain": ["PromptTemplate(input_variables=['doc'], output_parser=RegexParser(regex='QUESTION: (.*?)\\\\nANSWER: (.*)', output_keys=['query', 'answer'], default_output_key=None), partial_variables={}, template='You are a teacher coming up with questions to ask on a quiz. \\nGiven the following document, please generate a question and answer based on that document.\\n\\nExample Format:\\n<Begin Document>\\n...\\n<End Document>\\nQUESTION: question here\\nANSWER: answer here\\n\\nThese questions should be detailed and be based explicitly on information in the document. Begin!\\n\\n<Begin Document>\\n{doc}\\n<End Document>\\n\u8bf7\u4f7f\u7528\u4e2d\u6587\u8f93\u51fa\u3002\\n', template_format='f-string', validate_template=True)"]}, "execution_count": 43, "metadata": {}, "output_type": "execute_result"}], "source": ["# \u4e0b\u9762\u662flangchain.evaluation.qa.generate_prompt\u4e2d\u7684\u6e90\u7801\uff0c\u6211\u4eec\u5728template\u7684\u6700\u540e\u52a0\u4e0a\u201c\u8bf7\u4f7f\u7528\u4e2d\u6587\u8f93\u51fa\u201d\n", "# flake8: noqa\n", "from langchain.output_parsers.regex import RegexParser\n", "from langchain.prompts import PromptTemplate\n", "\n", "template = \"\"\"You are a teacher coming up with questions to ask on a quiz. \n", "Given the following document, please generate a question and answer based on that document.\n", "\n", "Example Format:\n", "<Begin Document>\n", "...\n", "<End Document>\n", "QUESTION: question here\n", "ANSWER: answer here\n", "\n", "These questions should be detailed and be based explicitly on information in the document. Begin!\n", "\n", "<Begin Document>\n", "{doc}\n", "<End Document>\n", "\u8bf7\u4f7f\u7528\u4e2d\u6587\u8f93\u51fa\u3002\n", "\"\"\"\n", "output_parser = RegexParser(\n", " regex=r\"QUESTION: (.*?)\\nANSWER: (.*)\", output_keys=[\"query\", \"answer\"]\n", ")\n", "PROMPT = PromptTemplate(\n", " input_variables=[\"doc\"], template=template, output_parser=output_parser\n", ")\n", "\n", "PROMPT\n"]}, {"cell_type": "code", "execution_count": 39, "id": "82ec0488", "metadata": {}, "outputs": [], "source": ["# \u7ee7\u627fQAGenerateChain\n", "class MyQAGenerateChain(QAGenerateChain):\n", " \"\"\"LLM Chain specifically for generating examples for question answering.\"\"\"\n", "\n", " @classmethod\n", " def from_llm(cls, llm: BaseLanguageModel, **kwargs: Any) -> QAGenerateChain:\n", " \"\"\"Load QA Generate Chain from LLM.\"\"\"\n", " return cls(llm=llm, prompt=PROMPT, **kwargs)"]}, {"cell_type": "code", "execution_count": 40, "id": "8dfc4372", "metadata": {}, "outputs": [], "source": ["example_gen_chain = MyQAGenerateChain.from_llm(ChatOpenAI())#\u901a\u8fc7\u4f20\u9012chat open AI\u8bed\u8a00\u6a21\u578b\u6765\u521b\u5efa\u8fd9\u4e2a\u94fe"]}, {"cell_type": "code", "execution_count": 41, "id": "d25c6a0e", "metadata": {}, "outputs": [{"data": {"text/plain": ["[Document(page_content=\"product_name: \u5168\u81ea\u52a8\u5496\u5561\u673a\\ndescription: \u89c4\u683c:\\n\u5927\u578b - \u5c3a\u5bf8\uff1a13.8'' x 17.3''\u3002\\n\u4e2d\u578b - \u5c3a\u5bf8\uff1a11.5'' x 15.2''\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u8fd9\u6b3e\u5168\u81ea\u52a8\u5496\u5561\u673a\u662f\u7231\u597d\u8005\u7684\u7406\u60f3\u9009\u62e9\u3002 \u4e00\u952e\u64cd\u4f5c\uff0c\u5373\u53ef\u7814\u78e8\u8c46\u5b50\u5e76\u6c8f\u5236\u51fa\u60a8\u559c\u7231\u7684\u5496\u5561\u3002\u5b83\u7684\u8010\u7528\u6027\u548c\u4e00\u81f4\u6027\u4f7f\u5b83\u6210\u4e3a\u5bb6\u5ead\u548c\u529e\u516c\u5ba4\u7684\u7406\u60f3\u9009\u62e9\u3002\\n\\n\u6750\u8d28\u4e0e\u62a4\u7406:\\n\u6e05\u6d01\u65f6\u53ea\u9700\u8f7b\u64e6\u3002\\n\\n\u6784\u9020:\\n\u7531\u9ad8\u54c1\u8d28\u4e0d\u9508\u94a2\u5236\u6210\u3002\\n\\n\u5176\u4ed6\u7279\u6027:\\n\u5185\u7f6e\u7814\u78e8\u5668\u548c\u6ee4\u7f51\u3002\\n\u9884\u8bbe\u591a\u79cd\u5496\u5561\u6a21\u5f0f\u3002\\n\u5728\u4e2d\u56fd\u5236\u9020\u3002\\n\\n\u6709\u95ee\u9898\uff1f \u8bf7\u968f\u65f6\u8054\u7cfb\u6211\u4eec\u7684\u5ba2\u6237\u670d\u52a1\u56e2\u961f\uff0c\u4ed6\u4eec\u4f1a\u89e3\u7b54\u60a8\u7684\u6240\u6709\u95ee\u9898\u3002\", metadata={'source': 'product_data.csv', 'row': 0}),\n", " Document(page_content=\"product_name: \u7535\u52a8\u7259\u5237\\ndescription: \u89c4\u683c:\\n\u4e00\u822c\u5927\u5c0f - \u9ad8\u5ea6\uff1a9.5''\uff0c\u5bbd\u5ea6\uff1a1''\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u6211\u4eec\u7684\u7535\u52a8\u7259\u5237\u91c7\u7528\u5148\u8fdb\u7684\u5237\u5934\u8bbe\u8ba1\u548c\u5f3a\u5927\u7684\u7535\u673a\uff0c\u4e3a\u60a8\u63d0\u4f9b\u8d85\u51e1\u7684\u6e05\u6d01\u529b\u548c\u8212\u9002\u7684\u5237\u7259\u4f53\u9a8c\u3002\\n\\n\u6750\u8d28\u4e0e\u62a4\u7406:\\n\u4e0d\u53ef\u6c34\u6d17\uff0c\u53ea\u9700\u7528\u6e7f\u5e03\u6e05\u6d01\u3002\\n\\n\u6784\u9020:\\n\u7531\u98df\u54c1\u7ea7\u5851\u6599\u548c\u5c3c\u9f99\u5237\u6bdb\u5236\u6210\u3002\\n\\n\u5176\u4ed6\u7279\u6027:\\n\u5177\u6709\u591a\u79cd\u6e05\u6d01\u6a21\u5f0f\u548c\u5b9a\u65f6\u529f\u80fd\u3002\\nUSB\u5145\u7535\u3002\\n\u5728\u65e5\u672c\u5236\u9020\u3002\\n\\n\u6709\u95ee\u9898\uff1f\u8bf7\u968f\u65f6\u8054\u7cfb\u6211\u4eec\u7684\u5ba2\u6237\u670d\u52a1\u56e2\u961f\uff0c\u4ed6\u4eec\u4f1a\u89e3\u7b54\u60a8\u7684\u6240\u6709\u95ee\u9898\u3002\", metadata={'source': 'product_data.csv', 'row': 1}),\n", " Document(page_content='product_name: \u6a59\u5473\u7ef4\u751f\u7d20C\u6ce1\u817e\u7247\\ndescription: \u89c4\u683c:\\n\u6bcf\u76d2\u542b\u670920\u7247\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u6211\u4eec\u7684\u6a59\u5473\u7ef4\u751f\u7d20C\u6ce1\u817e\u7247\u662f\u5feb\u901f\u8865\u5145\u7ef4\u751f\u7d20C\u7684\u7406\u60f3\u65b9\u5f0f\u3002\u6bcf\u7247\u542b\u6709500mg\u7684\u7ef4\u751f\u7d20C\uff0c\u53ef\u4ee5\u5e2e\u52a9\u63d0\u5347\u514d\u75ab\u529b\uff0c\u4fdd\u62a4\u60a8\u7684\u5065\u5eb7\u3002\\n\\n\u6750\u8d28\u4e0e\u62a4\u7406:\\n\u8bf7\u5b58\u653e\u5728\u9634\u51c9\u5e72\u71e5\u7684\u5730\u65b9\uff0c\u907f\u514d\u9633\u5149\u76f4\u5c04\u3002\\n\\n\u6784\u9020:\\n\u4e3b\u8981\u6210\u5206\u4e3a\u7ef4\u751f\u7d20C\u548c\u67e0\u6aac\u9178\u94a0\u3002\\n\\n\u5176\u4ed6\u7279\u6027:\\n\u542b\u6709\u5929\u7136\u6a59\u5473\u3002\\n\u6613\u4e8e\u643a\u5e26\u3002\\n\u5728\u7f8e\u56fd\u5236\u9020\u3002\\n\\n\u6709\u95ee\u9898\uff1f\u8bf7\u968f\u65f6\u8054\u7cfb\u6211\u4eec\u7684\u5ba2\u6237\u670d\u52a1\u56e2\u961f\uff0c\u4ed6\u4eec\u4f1a\u89e3\u7b54\u60a8\u7684\u6240\u6709\u95ee\u9898\u3002', metadata={'source': 'product_data.csv', 'row': 2}),\n", " Document(page_content=\"product_name: \u65e0\u7ebf\u84dd\u7259\u8033\u673a\\ndescription: \u89c4\u683c:\\n\u5355\u4e2a\u8033\u673a\u5c3a\u5bf8\uff1a1.5'' x 1.3''\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u8fd9\u6b3e\u65e0\u7ebf\u84dd\u7259\u8033\u673a\u914d\u5907\u4e86\u964d\u566a\u6280\u672f\u548c\u957f\u8fbe8\u5c0f\u65f6\u7684\u7535\u6c60\u7eed\u822a\u529b\uff0c\u8ba9\u60a8\u65e0\u8bba\u5728\u54ea\u91cc\u90fd\u53ef\u4ee5\u4eab\u53d7\u65e0\u969c\u788d\u7684\u97f3\u4e50\u4f53\u9a8c\u3002\\n\\n\u6750\u8d28\u4e0e\u62a4\u7406:\\n\u53ea\u9700\u7528\u6e7f\u5e03\u6e05\u6d01\u3002\\n\\n\u6784\u9020:\\n\u7531\u8010\u7528\u7684\u5851\u6599\u548c\u91d1\u5c5e\u6784\u6210\uff0c\u914d\u5907\u6709\u8f6f\u8d28\u8033\u585e\u3002\\n\\n\u5176\u4ed6\u7279\u6027:\\n\u5feb\u901f\u5145\u7535\u529f\u80fd\u3002\\n\u5185\u7f6e\u9ea6\u514b\u98ce\uff0c\u652f\u6301\u63a5\u542c\u7535\u8bdd\u3002\\n\u5728\u97e9\u56fd\u5236\u9020\u3002\\n\\n\u6709\u95ee\u9898\uff1f\u8bf7\u968f\u65f6\u8054\u7cfb\u6211\u4eec\u7684\u5ba2\u6237\u670d\u52a1\u56e2\u961f\uff0c\u4ed6\u4eec\u4f1a\u89e3\u7b54\u60a8\u7684\u6240\u6709\u95ee\u9898\u3002\", metadata={'source': 'product_data.csv', 'row': 3}),\n", " Document(page_content=\"product_name: \u745c\u4f3d\u57ab\\ndescription: \u89c4\u683c:\\n\u5c3a\u5bf8\uff1a24'' x 68''\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u6211\u4eec\u7684\u745c\u4f3d\u57ab\u62e5\u6709\u51fa\u8272\u7684\u6293\u5730\u529b\u548c\u8212\u9002\u5ea6\uff0c\u65e0\u8bba\u662f\u505a\u745c\u4f3d\u8fd8\u662f\u5065\u8eab\uff0c\u90fd\u662f\u7406\u60f3\u7684\u9009\u62e9\u3002\\n\\n\u6750\u8d28\u4e0e\u62a4\u7406:\\n\u53ef\u7528\u6e05\u6c34\u6e05\u6d01\uff0c\u81ea\u7136\u667e\u5e72\u3002\\n\\n\u6784\u9020:\\n\u7531\u73af\u4fddPVC\u6750\u6599\u5236\u6210\u3002\\n\\n\u5176\u4ed6\u7279\u6027:\\n\u9644\u5e26\u4fbf\u643a\u5305\u548c\u7ed1\u5e26\u3002\\n\u5728\u5370\u5ea6\u5236\u9020\u3002\\n\\n\u6709\u95ee\u9898\uff1f\u8bf7\u968f\u65f6\u8054\u7cfb\u6211\u4eec\u7684\u5ba2\u6237\u670d\u52a1\u56e2\u961f\uff0c\u4ed6\u4eec\u4f1a\u89e3\u7b54\u60a8\u7684\u6240\u6709\u95ee\u9898\u3002\", metadata={'source': 'product_data.csv', 'row': 4})]"]}, "execution_count": 41, "metadata": {}, "output_type": "execute_result"}], "source": ["data[:5]"]}, {"cell_type": "code", "execution_count": 42, "id": "ef0f5cad", "metadata": {}, "outputs": [{"name": "stderr", "output_type": "stream", "text": ["d:\\anaconda3\\envs\\gpt_flask\\lib\\site-packages\\langchain\\chains\\llm.py:303: UserWarning: The apply_and_parse method is deprecated, instead pass an output parser directly to LLMChain.\n", " warnings.warn(\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 1.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 2.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 4.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 8.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n"]}], "source": ["new_examples = example_gen_chain.apply_and_parse(\n", " [{\"doc\": t} for t in data[:5]]\n", ") #\u6211\u4eec\u53ef\u4ee5\u521b\u5efa\u8bb8\u591a\u4f8b\u5b50"]}, {"cell_type": "code", "execution_count": 44, "id": "7bc64a85", "metadata": {}, "outputs": [{"data": {"text/plain": ["[{'query': '\u8fd9\u6b3e\u5168\u81ea\u52a8\u5496\u5561\u673a\u7684\u89c4\u683c\u662f\u4ec0\u4e48\uff1f',\n", " 'answer': \"\u5927\u578b\u5c3a\u5bf8\u4e3a13.8'' x 17.3''\uff0c\u4e2d\u578b\u5c3a\u5bf8\u4e3a11.5'' x 15.2''\u3002\"},\n", " {'query': '\u8fd9\u6b3e\u7535\u52a8\u7259\u5237\u7684\u9ad8\u5ea6\u548c\u5bbd\u5ea6\u5206\u522b\u662f\u591a\u5c11\uff1f', 'answer': '\u8fd9\u6b3e\u7535\u52a8\u7259\u5237\u7684\u9ad8\u5ea6\u662f9.5\u82f1\u5bf8\uff0c\u5bbd\u5ea6\u662f1\u82f1\u5bf8\u3002'},\n", " {'query': '\u8fd9\u6b3e\u6a59\u5473\u7ef4\u751f\u7d20C\u6ce1\u817e\u7247\u7684\u89c4\u683c\u662f\u4ec0\u4e48\uff1f', 'answer': '\u6bcf\u76d2\u542b\u670920\u7247\u3002'},\n", " {'query': '\u8fd9\u6b3e\u65e0\u7ebf\u84dd\u7259\u8033\u673a\u7684\u5c3a\u5bf8\u662f\u591a\u5c11\uff1f', 'answer': \"\u8fd9\u6b3e\u65e0\u7ebf\u84dd\u7259\u8033\u673a\u7684\u5c3a\u5bf8\u662f1.5'' x 1.3''\u3002\"},\n", " {'query': '\u8fd9\u6b3e\u745c\u4f3d\u57ab\u7684\u5c3a\u5bf8\u662f\u591a\u5c11\uff1f', 'answer': \"\u8fd9\u6b3e\u745c\u4f3d\u57ab\u7684\u5c3a\u5bf8\u662f24'' x 68''\u3002\"}]"]}, "execution_count": 44, "metadata": {}, "output_type": "execute_result"}], "source": ["new_examples #\u67e5\u770b\u7528\u4f8b\u6570\u636e"]}, {"cell_type": "code", "execution_count": 46, "id": "1e6b2fe4", "metadata": {}, "outputs": [{"data": {"text/plain": ["{'query': '\u8fd9\u6b3e\u5168\u81ea\u52a8\u5496\u5561\u673a\u7684\u89c4\u683c\u662f\u4ec0\u4e48\uff1f',\n", " 'answer': \"\u5927\u578b\u5c3a\u5bf8\u4e3a13.8'' x 17.3''\uff0c\u4e2d\u578b\u5c3a\u5bf8\u4e3a11.5'' x 15.2''\u3002\"}"]}, "execution_count": 46, "metadata": {}, "output_type": "execute_result"}], "source": ["new_examples[0]"]}, {"cell_type": "code", "execution_count": 47, "id": "7ec72577", "metadata": {}, "outputs": [{"data": {"text/plain": ["Document(page_content=\"product_name: \u5168\u81ea\u52a8\u5496\u5561\u673a\\ndescription: \u89c4\u683c:\\n\u5927\u578b - \u5c3a\u5bf8\uff1a13.8'' x 17.3''\u3002\\n\u4e2d\u578b - \u5c3a\u5bf8\uff1a11.5'' x 15.2''\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u8fd9\u6b3e\u5168\u81ea\u52a8\u5496\u5561\u673a\u662f\u7231\u597d\u8005\u7684\u7406\u60f3\u9009\u62e9\u3002 \u4e00\u952e\u64cd\u4f5c\uff0c\u5373\u53ef\u7814\u78e8\u8c46\u5b50\u5e76\u6c8f\u5236\u51fa\u60a8\u559c\u7231\u7684\u5496\u5561\u3002\u5b83\u7684\u8010\u7528\u6027\u548c\u4e00\u81f4\u6027\u4f7f\u5b83\u6210\u4e3a\u5bb6\u5ead\u548c\u529e\u516c\u5ba4\u7684\u7406\u60f3\u9009\u62e9\u3002\\n\\n\u6750\u8d28\u4e0e\u62a4\u7406:\\n\u6e05\u6d01\u65f6\u53ea\u9700\u8f7b\u64e6\u3002\\n\\n\u6784\u9020:\\n\u7531\u9ad8\u54c1\u8d28\u4e0d\u9508\u94a2\u5236\u6210\u3002\\n\\n\u5176\u4ed6\u7279\u6027:\\n\u5185\u7f6e\u7814\u78e8\u5668\u548c\u6ee4\u7f51\u3002\\n\u9884\u8bbe\u591a\u79cd\u5496\u5561\u6a21\u5f0f\u3002\\n\u5728\u4e2d\u56fd\u5236\u9020\u3002\\n\\n\u6709\u95ee\u9898\uff1f \u8bf7\u968f\u65f6\u8054\u7cfb\u6211\u4eec\u7684\u5ba2\u6237\u670d\u52a1\u56e2\u961f\uff0c\u4ed6\u4eec\u4f1a\u89e3\u7b54\u60a8\u7684\u6240\u6709\u95ee\u9898\u3002\", metadata={'source': 'product_data.csv', 'row': 0})"]}, "execution_count": 47, "metadata": {}, "output_type": "execute_result"}], "source": ["data[0]"]}, {"cell_type": "markdown", "id": "e6cb8f71-4720-4d98-8921-1e25022d5375", "metadata": {}, "source": ["#### \u7ec4\u5408\u7528\u4f8b\u6570\u636e"]}, {"cell_type": "code", "execution_count": 48, "id": "c0636823", "metadata": {}, "outputs": [], "source": ["examples += new_examples"]}, {"cell_type": "code", "execution_count": 49, "id": "8d33b5de", "metadata": {}, "outputs": [{"name": "stdout", "output_type": "stream", "text": ["\n", "\n", "\u001b[1m> Entering new chain...\u001b[0m\n", "\n", "\u001b[1m> Finished chain.\u001b[0m\n"]}, {"data": {"text/plain": ["'\u9ad8\u6e05\u7535\u89c6\u673a\u7684\u62a4\u7406\u975e\u5e38\u7b80\u5355\u3002\u60a8\u53ea\u9700\u8981\u4f7f\u7528\u5e72\u5e03\u6e05\u6d01\u5373\u53ef\u3002\u907f\u514d\u4f7f\u7528\u6e7f\u5e03\u6216\u5316\u5b66\u6e05\u6d01\u5242\uff0c\u4ee5\u514d\u635f\u574f\u7535\u89c6\u673a\u7684\u8868\u9762\u3002'"]}, "execution_count": 49, "metadata": {}, "output_type": "execute_result"}], "source": ["qa.run(examples[0][\"query\"])"]}, {"cell_type": "markdown", "id": "63f3cb08", "metadata": {}, "source": ["## \u4e09\u3001 \u4eba\u5de5\u8bc4\u4f30\n", "\u73b0\u5728\u6709\u4e86\u8fd9\u4e9b\u793a\u4f8b\uff0c\u4f46\u662f\u6211\u4eec\u5982\u4f55\u8bc4\u4f30\u6b63\u5728\u53d1\u751f\u7684\u4e8b\u60c5\u5462\uff1f\n", "\u901a\u8fc7\u8fd0\u884c\u4e00\u4e2a\u793a\u4f8b\u901a\u8fc7\u94fe\uff0c\u5e76\u67e5\u770b\u5b83\u4ea7\u751f\u7684\u8f93\u51fa\n", "\u5728\u8fd9\u91cc\u6211\u4eec\u4f20\u9012\u4e00\u4e2a\u67e5\u8be2\uff0c\u7136\u540e\u6211\u4eec\u5f97\u5230\u4e00\u4e2a\u7b54\u6848\u3002\u5b9e\u9645\u4e0a\u6b63\u5728\u53d1\u751f\u7684\u4e8b\u60c5\uff0c\u8fdb\u5165\u8bed\u8a00\u6a21\u578b\u7684\u5b9e\u9645\u63d0\u793a\u662f\u4ec0\u4e48\uff1f \n", "\u5b83\u68c0\u7d22\u7684\u6587\u6863\u662f\u4ec0\u4e48\uff1f \n", "\u4e2d\u95f4\u7ed3\u679c\u662f\u4ec0\u4e48\uff1f \n", "\u4ec5\u4ec5\u67e5\u770b\u6700\u7ec8\u7b54\u6848\u901a\u5e38\u4e0d\u8db3\u4ee5\u4e86\u89e3\u94fe\u4e2d\u51fa\u73b0\u4e86\u4ec0\u4e48\u95ee\u9898\u6216\u53ef\u80fd\u51fa\u73b0\u4e86\u4ec0\u4e48\u95ee\u9898"]}, {"cell_type": "code", "execution_count": 21, "id": "fcaf622e", "metadata": {"height": 47}, "outputs": [], "source": ["''' \n", "LingChainDebug\u5de5\u5177\u53ef\u4ee5\u4e86\u89e3\u8fd0\u884c\u4e00\u4e2a\u5b9e\u4f8b\u901a\u8fc7\u94fe\u4e2d\u95f4\u6240\u7ecf\u5386\u7684\u6b65\u9aa4\n", "'''\n", "import langchain\n", "langchain.debug = True"]}, {"cell_type": "code", "execution_count": 22, "id": "1e1deab0", "metadata": {}, "outputs": [{"name": "stdout", "output_type": "stream", "text": ["\u001b[32;1m\u001b[1;3m[chain/start]\u001b[0m \u001b[1m[1:chain:RetrievalQA] Entering Chain run with input:\n", "\u001b[0m{\n", " \"query\": \"Do the Cozy Comfort Pullover Set have side pockets?\"\n", "}\n", "\u001b[32;1m\u001b[1;3m[chain/start]\u001b[0m \u001b[1m[1:chain:RetrievalQA > 2:chain:StuffDocumentsChain] Entering Chain run with input:\n", "\u001b[0m[inputs]\n", "\u001b[32;1m\u001b[1;3m[chain/start]\u001b[0m \u001b[1m[1:chain:RetrievalQA > 2:chain:StuffDocumentsChain > 3:chain:LLMChain] Entering Chain run with input:\n", "\u001b[0m{\n", " \"question\": \"Do the Cozy Comfort Pullover Set have side pockets?\",\n", " \"context\": \": 10\\nname: Cozy Comfort Pullover Set, Stripe\\ndescription: Perfect for lounging, this striped knit set lives up to its name. We used ultrasoft fabric and an easy design that's as comfortable at bedtime as it is when we have to make a quick run out.\\r\\n\\r\\nSize & Fit\\r\\n- Pants are Favorite Fit: Sits lower on the waist.\\r\\n- Relaxed Fit: Our most generous fit sits farthest from the body.\\r\\n\\r\\nFabric & Care\\r\\n- In the softest blend of 63% polyester, 35% rayon and 2% spandex.\\r\\n\\r\\nAdditional Features\\r\\n- Relaxed fit top with raglan sleeves and rounded hem.\\r\\n- Pull-on pants have a wide elastic waistband and drawstring, side pockets and a modern slim leg.\\r\\n\\r\\nImported.<<<<>>>>>: 73\\nname: Cozy Cuddles Knit Pullover Set\\ndescription: Perfect for lounging, this knit set lives up to its name. We used ultrasoft fabric and an easy design that's as comfortable at bedtime as it is when we have to make a quick run out. \\r\\n\\r\\nSize & Fit \\r\\nPants are Favorite Fit: Sits lower on the waist. \\r\\nRelaxed Fit: Our most generous fit sits farthest from the body. \\r\\n\\r\\nFabric & Care \\r\\nIn the softest blend of 63% polyester, 35% rayon and 2% spandex.\\r\\n\\r\\nAdditional Features \\r\\nRelaxed fit top with raglan sleeves and rounded hem. \\r\\nPull-on pants have a wide elastic waistband and drawstring, side pockets and a modern slim leg. \\r\\nImported.<<<<>>>>>: 632\\nname: Cozy Comfort Fleece Pullover\\ndescription: The ultimate sweater fleece \u2013 made from superior fabric and offered at an unbeatable price. \\r\\n\\r\\nSize & Fit\\r\\nSlightly Fitted: Softly shapes the body. Falls at hip. \\r\\n\\r\\nWhy We Love It\\r\\nOur customers (and employees) love the rugged construction and heritage-inspired styling of our popular Sweater Fleece Pullover and wear it for absolutely everything. From high-intensity activities to everyday tasks, you'll find yourself reaching for it every time.\\r\\n\\r\\nFabric & Care\\r\\nRugged sweater-knit exterior and soft brushed interior for exceptional warmth and comfort. Made from soft, 100% polyester. Machine wash and dry.\\r\\n\\r\\nAdditional Features\\r\\nFeatures our classic Mount Katahdin logo. Snap placket. Front princess seams create a feminine shape. Kangaroo handwarmer pockets. Cuffs and hem reinforced with jersey binding. Imported.\\r\\n\\r\\n \u2013 Official Supplier to the U.S. Ski Team\\r\\nTHEIR WILL TO WIN, WOVEN RIGHT IN. LEARN MORE<<<<>>>>>: 265\\nname: Cozy Workout Vest\\ndescription: For serious warmth that won't weigh you down, reach for this fleece-lined vest, which provides you with layering options whether you're inside or outdoors.\\r\\nSize & Fit\\r\\nRelaxed Fit. Falls at hip.\\r\\nFabric & Care\\r\\nSoft, textured fleece lining. Nylon shell. Machine wash and dry. \\r\\nAdditional Features \\r\\nTwo handwarmer pockets. Knit side panels stretch for a more flattering fit. Shell fabric is treated to resist water and stains. Imported.\"\n", "}\n", "\u001b[32;1m\u001b[1;3m[llm/start]\u001b[0m \u001b[1m[1:chain:RetrievalQA > 2:chain:StuffDocumentsChain > 3:chain:LLMChain > 4:llm:ChatOpenAI] Entering LLM run with input:\n", "\u001b[0m{\n", " \"prompts\": [\n", " \"System: Use the following pieces of context to answer the users question. \\nIf you don't know the answer, just say that you don't know, don't try to make up an answer.\\n----------------\\n: 10\\nname: Cozy Comfort Pullover Set, Stripe\\ndescription: Perfect for lounging, this striped knit set lives up to its name. We used ultrasoft fabric and an easy design that's as comfortable at bedtime as it is when we have to make a quick run out.\\r\\n\\r\\nSize & Fit\\r\\n- Pants are Favorite Fit: Sits lower on the waist.\\r\\n- Relaxed Fit: Our most generous fit sits farthest from the body.\\r\\n\\r\\nFabric & Care\\r\\n- In the softest blend of 63% polyester, 35% rayon and 2% spandex.\\r\\n\\r\\nAdditional Features\\r\\n- Relaxed fit top with raglan sleeves and rounded hem.\\r\\n- Pull-on pants have a wide elastic waistband and drawstring, side pockets and a modern slim leg.\\r\\n\\r\\nImported.<<<<>>>>>: 73\\nname: Cozy Cuddles Knit Pullover Set\\ndescription: Perfect for lounging, this knit set lives up to its name. We used ultrasoft fabric and an easy design that's as comfortable at bedtime as it is when we have to make a quick run out. \\r\\n\\r\\nSize & Fit \\r\\nPants are Favorite Fit: Sits lower on the waist. \\r\\nRelaxed Fit: Our most generous fit sits farthest from the body. \\r\\n\\r\\nFabric & Care \\r\\nIn the softest blend of 63% polyester, 35% rayon and 2% spandex.\\r\\n\\r\\nAdditional Features \\r\\nRelaxed fit top with raglan sleeves and rounded hem. \\r\\nPull-on pants have a wide elastic waistband and drawstring, side pockets and a modern slim leg. \\r\\nImported.<<<<>>>>>: 632\\nname: Cozy Comfort Fleece Pullover\\ndescription: The ultimate sweater fleece \u2013 made from superior fabric and offered at an unbeatable price. \\r\\n\\r\\nSize & Fit\\r\\nSlightly Fitted: Softly shapes the body. Falls at hip. \\r\\n\\r\\nWhy We Love It\\r\\nOur customers (and employees) love the rugged construction and heritage-inspired styling of our popular Sweater Fleece Pullover and wear it for absolutely everything. From high-intensity activities to everyday tasks, you'll find yourself reaching for it every time.\\r\\n\\r\\nFabric & Care\\r\\nRugged sweater-knit exterior and soft brushed interior for exceptional warmth and comfort. Made from soft, 100% polyester. Machine wash and dry.\\r\\n\\r\\nAdditional Features\\r\\nFeatures our classic Mount Katahdin logo. Snap placket. Front princess seams create a feminine shape. Kangaroo handwarmer pockets. Cuffs and hem reinforced with jersey binding. Imported.\\r\\n\\r\\n \u2013 Official Supplier to the U.S. Ski Team\\r\\nTHEIR WILL TO WIN, WOVEN RIGHT IN. LEARN MORE<<<<>>>>>: 265\\nname: Cozy Workout Vest\\ndescription: For serious warmth that won't weigh you down, reach for this fleece-lined vest, which provides you with layering options whether you're inside or outdoors.\\r\\nSize & Fit\\r\\nRelaxed Fit. Falls at hip.\\r\\nFabric & Care\\r\\nSoft, textured fleece lining. Nylon shell. Machine wash and dry. \\r\\nAdditional Features \\r\\nTwo handwarmer pockets. Knit side panels stretch for a more flattering fit. Shell fabric is treated to resist water and stains. Imported.\\nHuman: Do the Cozy Comfort Pullover Set have side pockets?\"\n", " ]\n", "}\n", "\u001b[36;1m\u001b[1;3m[llm/end]\u001b[0m \u001b[1m[1:chain:RetrievalQA > 2:chain:StuffDocumentsChain > 3:chain:LLMChain > 4:llm:ChatOpenAI] [2.29s] Exiting LLM run with output:\n", "\u001b[0m{\n", " \"generations\": [\n", " [\n", " {\n", " \"text\": \"Yes, the Cozy Comfort Pullover Set does have side pockets.\",\n", " \"generation_info\": null,\n", " \"message\": {\n", " \"content\": \"Yes, the Cozy Comfort Pullover Set does have side pockets.\",\n", " \"additional_kwargs\": {},\n", " \"example\": false\n", " }\n", " }\n", " ]\n", " ],\n", " \"llm_output\": {\n", " \"token_usage\": {\n", " \"prompt_tokens\": 717,\n", " \"completion_tokens\": 14,\n", " \"total_tokens\": 731\n", " },\n", " \"model_name\": \"gpt-3.5-turbo\"\n", " },\n", " \"run\": null\n", "}\n", "\u001b[36;1m\u001b[1;3m[chain/end]\u001b[0m \u001b[1m[1:chain:RetrievalQA > 2:chain:StuffDocumentsChain > 3:chain:LLMChain] [2.29s] Exiting Chain run with output:\n", "\u001b[0m{\n", " \"text\": \"Yes, the Cozy Comfort Pullover Set does have side pockets.\"\n", "}\n", "\u001b[36;1m\u001b[1;3m[chain/end]\u001b[0m \u001b[1m[1:chain:RetrievalQA > 2:chain:StuffDocumentsChain] [2.29s] Exiting Chain run with output:\n", "\u001b[0m{\n", " \"output_text\": \"Yes, the Cozy Comfort Pullover Set does have side pockets.\"\n", "}\n", "\u001b[36;1m\u001b[1;3m[chain/end]\u001b[0m \u001b[1m[1:chain:RetrievalQA] [2.93s] Exiting Chain run with output:\n", "\u001b[0m{\n", " \"result\": \"Yes, the Cozy Comfort Pullover Set does have side pockets.\"\n", "}\n"]}, {"data": {"text/plain": ["'Yes, the Cozy Comfort Pullover Set does have side pockets.'"]}, "execution_count": 22, "metadata": {}, "output_type": "execute_result"}], "source": ["qa.run(examples[0][\"query\"])#\u91cd\u65b0\u8fd0\u884c\u4e0e\u4e0a\u9762\u76f8\u540c\u7684\u793a\u4f8b\uff0c\u53ef\u4ee5\u770b\u5230\u5b83\u5f00\u59cb\u6253\u5370\u51fa\u66f4\u591a\u7684\u4fe1\u606f"]}, {"cell_type": "markdown", "id": "8dee0f24", "metadata": {}, "source": ["\u6211\u4eec\u53ef\u4ee5\u770b\u5230\u5b83\u9996\u5148\u6df1\u5165\u5230\u68c0\u7d22QA\u94fe\u4e2d\uff0c\u7136\u540e\u5b83\u8fdb\u5165\u4e86\u4e00\u4e9b\u6587\u6863\u94fe\u3002\u5982\u4e0a\u6240\u8ff0\uff0c\u6211\u4eec\u6b63\u5728\u4f7f\u7528stuff\u65b9\u6cd5\uff0c\u73b0\u5728\u6211\u4eec\u6b63\u5728\u4f20\u9012\u8fd9\u4e2a\u4e0a\u4e0b\u6587\uff0c\u53ef\u4ee5\u770b\u5230\uff0c\u8fd9\u4e2a\u4e0a\u4e0b\u6587\u662f\u7531\u6211\u4eec\u68c0\u7d22\u5230\u7684\u4e0d\u540c\u6587\u6863\u521b\u5efa\u7684\u3002\u56e0\u6b64\uff0c\u5728\u8fdb\u884c\u95ee\u7b54\u65f6\uff0c\u5f53\u8fd4\u56de\u9519\u8bef\u7ed3\u679c\u65f6\uff0c\u901a\u5e38\u4e0d\u662f\u8bed\u8a00\u6a21\u578b\u672c\u8eab\u51fa\u9519\u4e86\uff0c\u5b9e\u9645\u4e0a\u662f\u68c0\u7d22\u6b65\u9aa4\u51fa\u9519\u4e86\uff0c\u4ed4\u7ec6\u67e5\u770b\u95ee\u9898\u7684\u786e\u5207\u5185\u5bb9\u548c\u4e0a\u4e0b\u6587\u53ef\u4ee5\u5e2e\u52a9\u8c03\u8bd5\u51fa\u9519\u7684\u539f\u56e0\u3002 \n", "\u7136\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u518d\u5411\u4e0b\u4e00\u7ea7\uff0c\u770b\u770b\u8fdb\u5165\u8bed\u8a00\u6a21\u578b\u7684\u786e\u5207\u5185\u5bb9\uff0c\u4ee5\u53ca OpenAI \u81ea\u8eab\uff0c\u5728\u8fd9\u91cc\uff0c\u6211\u4eec\u53ef\u4ee5\u770b\u5230\u4f20\u9012\u7684\u5b8c\u6574\u63d0\u793a\uff0c\u6211\u4eec\u6709\u4e00\u4e2a\u7cfb\u7edf\u6d88\u606f\uff0c\u6709\u6240\u4f7f\u7528\u7684\u63d0\u793a\u7684\u63cf\u8ff0\uff0c\u8fd9\u662f\u95ee\u9898\u56de\u7b54\u94fe\u4f7f\u7528\u7684\u63d0\u793a\uff0c\u6211\u4eec\u53ef\u4ee5\u770b\u5230\u63d0\u793a\u6253\u5370\u51fa\u6765\uff0c\u4f7f\u7528\u4ee5\u4e0b\u4e0a\u4e0b\u6587\u7247\u6bb5\u56de\u7b54\u7528\u6237\u7684\u95ee\u9898\u3002\n", "\u5982\u679c\u60a8\u4e0d\u77e5\u9053\u7b54\u6848\uff0c\u53ea\u9700\u8bf4\u60a8\u4e0d\u77e5\u9053\u5373\u53ef\uff0c\u4e0d\u8981\u8bd5\u56fe\u7f16\u9020\u7b54\u6848\u3002\u7136\u540e\u6211\u4eec\u770b\u5230\u4e00\u5806\u4e4b\u524d\u63d2\u5165\u7684\u4e0a\u4e0b\u6587\uff0c\u6211\u4eec\u8fd8\u53ef\u4ee5\u770b\u5230\u6709\u5173\u5b9e\u9645\u8fd4\u56de\u7c7b\u578b\u7684\u66f4\u591a\u4fe1\u606f\u3002\u6211\u4eec\u4e0d\u4ec5\u4ec5\u8fd4\u56de\u4e00\u4e2a\u7b54\u6848\uff0c\u8fd8\u6709token\u7684\u4f7f\u7528\u60c5\u51b5\uff0c\u53ef\u4ee5\u4e86\u89e3\u5230token\u6570\u7684\u4f7f\u7528\u60c5\u51b5\n", "\n", "\n", "\u7531\u4e8e\u8fd9\u662f\u4e00\u4e2a\u76f8\u5bf9\u7b80\u5355\u7684\u94fe\uff0c\u6211\u4eec\u73b0\u5728\u53ef\u4ee5\u770b\u5230\u6700\u7ec8\u7684\u54cd\u5e94\uff0c\u8212\u9002\u7684\u6bdb\u8863\u5957\u88c5\uff0c\u6761\u7eb9\u6b3e\uff0c\u6709\u4fa7\u888b\uff0c\u6b63\u5728\u8d77\u6ce1\uff0c\u901a\u8fc7\u94fe\u8fd4\u56de\u7ed9\u7528\u6237\uff0c\u6211\u4eec\u521a\u521a\u8bb2\u89e3\u4e86\u5982\u4f55\u67e5\u770b\u548c\u8c03\u8bd5\u5355\u4e2a\u8f93\u5165\u5230\u8be5\u94fe\u7684\u60c5\u51b5\u3002\n", "\n", "\n"]}, {"cell_type": "markdown", "id": "7b37c7bc", "metadata": {}, "source": ["### 3.1 \u5982\u4f55\u8bc4\u4f30\u65b0\u521b\u5efa\u7684\u5b9e\u4f8b\n", "\u4e0e\u521b\u5efa\u5b83\u4eec\u7c7b\u4f3c\uff0c\u53ef\u4ee5\u8fd0\u884c\u94fe\u6761\u6765\u5904\u7406\u6240\u6709\u793a\u4f8b\uff0c\u7136\u540e\u67e5\u770b\u8f93\u51fa\u5e76\u5c1d\u8bd5\u5f04\u6e05\u695a\uff0c\u53d1\u751f\u4e86\u4ec0\u4e48\uff0c\u5b83\u662f\u5426\u6b63\u786e"]}, {"cell_type": "code", "execution_count": 23, "id": "b3d6bef0", "metadata": {"height": 47}, "outputs": [], "source": ["# \u6211\u4eec\u9700\u8981\u4e3a\u6240\u6709\u793a\u4f8b\u521b\u5efa\u9884\u6d4b\uff0c\u5173\u95ed\u8c03\u8bd5\u6a21\u5f0f\uff0c\u4ee5\u4fbf\u4e0d\u5c06\u6240\u6709\u5185\u5bb9\u6253\u5370\u5230\u5c4f\u5e55\u4e0a\n", "langchain.debug = False"]}, {"cell_type": "markdown", "id": "46af7edb-72ef-4858-9dcc-e6ba5769ca15", "metadata": {}, "source": ["### 3.2 \u4e2d\u6587\u7248\n", "\u73b0\u5728\u6709\u4e86\u8fd9\u4e9b\u793a\u4f8b\uff0c\u4f46\u662f\u6211\u4eec\u5982\u4f55\u8bc4\u4f30\u6b63\u5728\u53d1\u751f\u7684\u4e8b\u60c5\u5462\uff1f\n", "\u901a\u8fc7\u8fd0\u884c\u4e00\u4e2a\u793a\u4f8b\u901a\u8fc7\u94fe\uff0c\u5e76\u67e5\u770b\u5b83\u4ea7\u751f\u7684\u8f93\u51fa\n", "\u5728\u8fd9\u91cc\u6211\u4eec\u4f20\u9012\u4e00\u4e2a\u67e5\u8be2\uff0c\u7136\u540e\u6211\u4eec\u5f97\u5230\u4e00\u4e2a\u7b54\u6848\u3002\u5b9e\u9645\u4e0a\u6b63\u5728\u53d1\u751f\u7684\u4e8b\u60c5\uff0c\u8fdb\u5165\u8bed\u8a00\u6a21\u578b\u7684\u5b9e\u9645\u63d0\u793a\u662f\u4ec0\u4e48\uff1f \n", "\u5b83\u68c0\u7d22\u7684\u6587\u6863\u662f\u4ec0\u4e48\uff1f \n", "\u4e2d\u95f4\u7ed3\u679c\u662f\u4ec0\u4e48\uff1f \n", "\u4ec5\u4ec5\u67e5\u770b\u6700\u7ec8\u7b54\u6848\u901a\u5e38\u4e0d\u8db3\u4ee5\u4e86\u89e3\u94fe\u4e2d\u51fa\u73b0\u4e86\u4ec0\u4e48\u95ee\u9898\u6216\u53ef\u80fd\u51fa\u73b0\u4e86\u4ec0\u4e48\u95ee\u9898"]}, {"cell_type": "code", "execution_count": null, "id": "45f60c6e", "metadata": {}, "outputs": [], "source": ["''' \n", "LingChainDebug\u5de5\u5177\u53ef\u4ee5\u4e86\u89e3\u8fd0\u884c\u4e00\u4e2a\u5b9e\u4f8b\u901a\u8fc7\u94fe\u4e2d\u95f4\u6240\u7ecf\u5386\u7684\u6b65\u9aa4\n", "'''\n", "import langchain\n", "langchain.debug = True"]}, {"cell_type": "code", "execution_count": null, "id": "3f216f9a", "metadata": {}, "outputs": [{"name": "stdout", "output_type": "stream", "text": ["\u001b[32;1m\u001b[1;3m[chain/start]\u001b[0m \u001b[1m[1:chain:RetrievalQA] Entering Chain run with input:\n", "\u001b[0m{\n", " \"query\": \"\u9ad8\u6e05\u7535\u89c6\u673a\u600e\u4e48\u8fdb\u884c\u62a4\u7406\uff1f\"\n", "}\n", "\u001b[32;1m\u001b[1;3m[chain/start]\u001b[0m \u001b[1m[1:chain:RetrievalQA > 2:chain:StuffDocumentsChain] Entering Chain run with input:\n", "\u001b[0m[inputs]\n", "\u001b[32;1m\u001b[1;3m[chain/start]\u001b[0m \u001b[1m[1:chain:RetrievalQA > 2:chain:StuffDocumentsChain > 3:chain:LLMChain] Entering Chain run with input:\n", "\u001b[0m{\n", " \"question\": \"\u9ad8\u6e05\u7535\u89c6\u673a\u600e\u4e48\u8fdb\u884c\u62a4\u7406\uff1f\",\n", " \"context\": \"product_name: \u9ad8\u6e05\u7535\u89c6\u673a\\ndescription: \u89c4\u683c:\\n\u5c3a\u5bf8\uff1a50''\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u6211\u4eec\u7684\u9ad8\u6e05\u7535\u89c6\u673a\u62e5\u6709\u51fa\u8272\u7684\u753b\u8d28\u548c\u5f3a\u5927\u7684\u97f3\u6548\uff0c\u5e26\u6765\u6c89\u6d78\u5f0f\u7684\u89c2\u770b\u4f53\u9a8c\u3002\\n\\n\u6750\u8d28\u4e0e\u62a4\u7406:\\n\u4f7f\u7528\u5e72\u5e03\u6e05\u6d01\u3002\\n\\n\u6784\u9020:\\n\u7531\u5851\u6599\u3001\u91d1\u5c5e\u548c\u7535\u5b50\u5143\u4ef6\u5236\u6210\u3002\\n\\n\u5176\u4ed6\u7279\u6027:\\n\u652f\u6301\u7f51\u7edc\u8fde\u63a5\uff0c\u53ef\u4ee5\u5728\u7ebf\u89c2\u770b\u89c6\u9891\u3002\\n\u914d\u5907\u9065\u63a7\u5668\u3002\\n\u5728\u97e9\u56fd\u5236\u9020\u3002\\n\\n\u6709\u95ee\u9898\uff1f\u8bf7\u968f\u65f6\u8054\u7cfb\u6211\u4eec\u7684\u5ba2\u6237\u670d\u52a1\u56e2\u961f\uff0c\u4ed6\u4eec\u4f1a\u89e3\u7b54\u60a8\u7684\u6240\u6709\u95ee\u9898\u3002<<<<>>>>>product_name: \u7a7a\u6c14\u51c0\u5316\u5668\\ndescription: \u89c4\u683c:\\n\u5c3a\u5bf8\uff1a15'' x 15'' x 20''\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u6211\u4eec\u7684\u7a7a\u6c14\u51c0\u5316\u5668\u91c7\u7528\u4e86\u5148\u8fdb\u7684HEPA\u8fc7\u6ee4\u6280\u672f\uff0c\u80fd\u6709\u6548\u53bb\u9664\u7a7a\u6c14\u4e2d\u7684\u5fae\u7c92\u548c\u5f02\u5473\uff0c\u4e3a\u60a8\u63d0\u4f9b\u6e05\u65b0\u7684\u5ba4\u5185\u73af\u5883\u3002\\n\\n\u6750\u8d28\u4e0e\u62a4\u7406:\\n\u6e05\u6d01\u65f6\u4f7f\u7528\u5e72\u5e03\u64e6\u62ed\u3002\\n\\n\u6784\u9020:\\n\u7531\u5851\u6599\u548c\u7535\u5b50\u5143\u4ef6\u5236\u6210\u3002\\n\\n\u5176\u4ed6\u7279\u6027:\\n\u4e09\u6863\u98ce\u901f\uff0c\u9644\u5e26\u5b9a\u65f6\u529f\u80fd\u3002\\n\u5728\u5fb7\u56fd\u5236\u9020\u3002\\n\\n\u6709\u95ee\u9898\uff1f\u8bf7\u968f\u65f6\u8054\u7cfb\u6211\u4eec\u7684\u5ba2\u6237\u670d\u52a1\u56e2\u961f\uff0c\u4ed6\u4eec\u4f1a\u89e3\u7b54\u60a8\u7684\u6240\u6709\u95ee\u9898\u3002<<<<>>>>>product_name: \u5ba0\u7269\u81ea\u52a8\u5582\u98df\u5668\\ndescription: \u89c4\u683c:\\n\u5c3a\u5bf8\uff1a14'' x 9'' x 15''\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u6211\u4eec\u7684\u5ba0\u7269\u81ea\u52a8\u5582\u98df\u5668\u53ef\u4ee5\u5b9a\u65f6\u5b9a\u91cf\u6295\u653e\u98df\u7269\uff0c\u8ba9\u60a8\u65e0\u8bba\u5728\u5bb6\u6216\u5916\u51fa\u90fd\u80fd\u786e\u4fdd\u5ba0\u7269\u7684\u996e\u98df\u3002\\n\\n\u6750\u8d28\u4e0e\u62a4\u7406:\\n\u53ef\u7528\u6e7f\u5e03\u6e05\u6d01\u3002\\n\\n\u6784\u9020:\\n\u7531\u5851\u6599\u548c\u7535\u5b50\u5143\u4ef6\u5236\u6210\u3002\\n\\n\u5176\u4ed6\u7279\u6027:\\n\u914d\u5907LCD\u5c4f\u5e55\uff0c\u64cd\u4f5c\u7b80\u5355\u3002\\n\u53ef\u4ee5\u8bbe\u7f6e\u591a\u6b21\u6295\u98df\u3002\\n\u5728\u7f8e\u56fd\u5236\u9020\u3002\\n\\n\u6709\u95ee\u9898\uff1f\u8bf7\u968f\u65f6\u8054\u7cfb\u6211\u4eec\u7684\u5ba2\u6237\u670d\u52a1\u56e2\u961f\uff0c\u4ed6\u4eec\u4f1a\u89e3\u7b54\u60a8\u7684\u6240\u6709\u95ee\u9898\u3002<<<<>>>>>product_name: \u73bb\u7483\u4fdd\u62a4\u819c\\ndescription: \u89c4\u683c:\\n\u9002\u7528\u4e8e\u5404\u79cd\u5c3a\u5bf8\u7684\u624b\u673a\u5c4f\u5e55\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u6211\u4eec\u7684\u73bb\u7483\u4fdd\u62a4\u819c\u53ef\u4ee5\u6709\u6548\u9632\u6b62\u624b\u673a\u5c4f\u5e55\u522e\u4f24\u548c\u7834\u88c2\uff0c\u800c\u4e14\u4e0d\u5f71\u54cd\u89e6\u63a7\u7684\u7075\u654f\u5ea6\u3002\\n\\n\u6750\u8d28\u4e0e\u62a4\u7406:\\n\u4f7f\u7528\u5e72\u5e03\u64e6\u62ed\u3002\\n\\n\u6784\u9020:\\n\u7531\u9ad8\u5f3a\u5ea6\u7684\u73bb\u7483\u6750\u6599\u5236\u6210\u3002\\n\\n\u5176\u4ed6\u7279\u6027:\\n\u5b89\u88c5\u7b80\u5355\uff0c\u9002\u5408\u81ea\u884c\u5b89\u88c5\u3002\\n\u5728\u65e5\u672c\u5236\u9020\u3002\\n\\n\u6709\u95ee\u9898\uff1f\u8bf7\u968f\u65f6\u8054\u7cfb\u6211\u4eec\u7684\u5ba2\u6237\u670d\u52a1\u56e2\u961f\uff0c\u4ed6\u4eec\u4f1a\u89e3\u7b54\u60a8\u7684\u6240\u6709\u95ee\u9898\u3002\"\n", "}\n", "\u001b[32;1m\u001b[1;3m[llm/start]\u001b[0m \u001b[1m[1:chain:RetrievalQA > 2:chain:StuffDocumentsChain > 3:chain:LLMChain > 4:llm:ChatOpenAI] Entering LLM run with input:\n", "\u001b[0m{\n", " \"prompts\": [\n", " \"System: Use the following pieces of context to answer the users question. \\nIf you don't know the answer, just say that you don't know, don't try to make up an answer.\\n----------------\\nproduct_name: \u9ad8\u6e05\u7535\u89c6\u673a\\ndescription: \u89c4\u683c:\\n\u5c3a\u5bf8\uff1a50''\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u6211\u4eec\u7684\u9ad8\u6e05\u7535\u89c6\u673a\u62e5\u6709\u51fa\u8272\u7684\u753b\u8d28\u548c\u5f3a\u5927\u7684\u97f3\u6548\uff0c\u5e26\u6765\u6c89\u6d78\u5f0f\u7684\u89c2\u770b\u4f53\u9a8c\u3002\\n\\n\u6750\u8d28\u4e0e\u62a4\u7406:\\n\u4f7f\u7528\u5e72\u5e03\u6e05\u6d01\u3002\\n\\n\u6784\u9020:\\n\u7531\u5851\u6599\u3001\u91d1\u5c5e\u548c\u7535\u5b50\u5143\u4ef6\u5236\u6210\u3002\\n\\n\u5176\u4ed6\u7279\u6027:\\n\u652f\u6301\u7f51\u7edc\u8fde\u63a5\uff0c\u53ef\u4ee5\u5728\u7ebf\u89c2\u770b\u89c6\u9891\u3002\\n\u914d\u5907\u9065\u63a7\u5668\u3002\\n\u5728\u97e9\u56fd\u5236\u9020\u3002\\n\\n\u6709\u95ee\u9898\uff1f\u8bf7\u968f\u65f6\u8054\u7cfb\u6211\u4eec\u7684\u5ba2\u6237\u670d\u52a1\u56e2\u961f\uff0c\u4ed6\u4eec\u4f1a\u89e3\u7b54\u60a8\u7684\u6240\u6709\u95ee\u9898\u3002<<<<>>>>>product_name: \u7a7a\u6c14\u51c0\u5316\u5668\\ndescription: \u89c4\u683c:\\n\u5c3a\u5bf8\uff1a15'' x 15'' x 20''\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u6211\u4eec\u7684\u7a7a\u6c14\u51c0\u5316\u5668\u91c7\u7528\u4e86\u5148\u8fdb\u7684HEPA\u8fc7\u6ee4\u6280\u672f\uff0c\u80fd\u6709\u6548\u53bb\u9664\u7a7a\u6c14\u4e2d\u7684\u5fae\u7c92\u548c\u5f02\u5473\uff0c\u4e3a\u60a8\u63d0\u4f9b\u6e05\u65b0\u7684\u5ba4\u5185\u73af\u5883\u3002\\n\\n\u6750\u8d28\u4e0e\u62a4\u7406:\\n\u6e05\u6d01\u65f6\u4f7f\u7528\u5e72\u5e03\u64e6\u62ed\u3002\\n\\n\u6784\u9020:\\n\u7531\u5851\u6599\u548c\u7535\u5b50\u5143\u4ef6\u5236\u6210\u3002\\n\\n\u5176\u4ed6\u7279\u6027:\\n\u4e09\u6863\u98ce\u901f\uff0c\u9644\u5e26\u5b9a\u65f6\u529f\u80fd\u3002\\n\u5728\u5fb7\u56fd\u5236\u9020\u3002\\n\\n\u6709\u95ee\u9898\uff1f\u8bf7\u968f\u65f6\u8054\u7cfb\u6211\u4eec\u7684\u5ba2\u6237\u670d\u52a1\u56e2\u961f\uff0c\u4ed6\u4eec\u4f1a\u89e3\u7b54\u60a8\u7684\u6240\u6709\u95ee\u9898\u3002<<<<>>>>>product_name: \u5ba0\u7269\u81ea\u52a8\u5582\u98df\u5668\\ndescription: \u89c4\u683c:\\n\u5c3a\u5bf8\uff1a14'' x 9'' x 15''\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u6211\u4eec\u7684\u5ba0\u7269\u81ea\u52a8\u5582\u98df\u5668\u53ef\u4ee5\u5b9a\u65f6\u5b9a\u91cf\u6295\u653e\u98df\u7269\uff0c\u8ba9\u60a8\u65e0\u8bba\u5728\u5bb6\u6216\u5916\u51fa\u90fd\u80fd\u786e\u4fdd\u5ba0\u7269\u7684\u996e\u98df\u3002\\n\\n\u6750\u8d28\u4e0e\u62a4\u7406:\\n\u53ef\u7528\u6e7f\u5e03\u6e05\u6d01\u3002\\n\\n\u6784\u9020:\\n\u7531\u5851\u6599\u548c\u7535\u5b50\u5143\u4ef6\u5236\u6210\u3002\\n\\n\u5176\u4ed6\u7279\u6027:\\n\u914d\u5907LCD\u5c4f\u5e55\uff0c\u64cd\u4f5c\u7b80\u5355\u3002\\n\u53ef\u4ee5\u8bbe\u7f6e\u591a\u6b21\u6295\u98df\u3002\\n\u5728\u7f8e\u56fd\u5236\u9020\u3002\\n\\n\u6709\u95ee\u9898\uff1f\u8bf7\u968f\u65f6\u8054\u7cfb\u6211\u4eec\u7684\u5ba2\u6237\u670d\u52a1\u56e2\u961f\uff0c\u4ed6\u4eec\u4f1a\u89e3\u7b54\u60a8\u7684\u6240\u6709\u95ee\u9898\u3002<<<<>>>>>product_name: \u73bb\u7483\u4fdd\u62a4\u819c\\ndescription: \u89c4\u683c:\\n\u9002\u7528\u4e8e\u5404\u79cd\u5c3a\u5bf8\u7684\u624b\u673a\u5c4f\u5e55\u3002\\n\\n\u4e3a\u4ec0\u4e48\u6211\u4eec\u70ed\u7231\u5b83:\\n\u6211\u4eec\u7684\u73bb\u7483\u4fdd\u62a4\u819c\u53ef\u4ee5\u6709\u6548\u9632\u6b62\u624b\u673a\u5c4f\u5e55\u522e\u4f24\u548c\u7834\u88c2\uff0c\u800c\u4e14\u4e0d\u5f71\u54cd\u89e6\u63a7\u7684\u7075\u654f\u5ea6\u3002\\n\\n\u6750\u8d28\u4e0e\u62a4\u7406:\\n\u4f7f\u7528\u5e72\u5e03\u64e6\u62ed\u3002\\n\\n\u6784\u9020:\\n\u7531\u9ad8\u5f3a\u5ea6\u7684\u73bb\u7483\u6750\u6599\u5236\u6210\u3002\\n\\n\u5176\u4ed6\u7279\u6027:\\n\u5b89\u88c5\u7b80\u5355\uff0c\u9002\u5408\u81ea\u884c\u5b89\u88c5\u3002\\n\u5728\u65e5\u672c\u5236\u9020\u3002\\n\\n\u6709\u95ee\u9898\uff1f\u8bf7\u968f\u65f6\u8054\u7cfb\u6211\u4eec\u7684\u5ba2\u6237\u670d\u52a1\u56e2\u961f\uff0c\u4ed6\u4eec\u4f1a\u89e3\u7b54\u60a8\u7684\u6240\u6709\u95ee\u9898\u3002\\nHuman: \u9ad8\u6e05\u7535\u89c6\u673a\u600e\u4e48\u8fdb\u884c\u62a4\u7406\uff1f\"\n", " ]\n", "}\n"]}, {"name": "stderr", "output_type": "stream", "text": ["Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 1.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 2.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 4.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 8.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n"]}, {"name": "stdout", "output_type": "stream", "text": ["\u001b[36;1m\u001b[1;3m[llm/end]\u001b[0m \u001b[1m[1:chain:RetrievalQA > 2:chain:StuffDocumentsChain > 3:chain:LLMChain > 4:llm:ChatOpenAI] [21.02s] Exiting LLM run with output:\n", "\u001b[0m{\n", " \"generations\": [\n", " [\n", " {\n", " \"text\": \"\u9ad8\u6e05\u7535\u89c6\u673a\u7684\u62a4\u7406\u975e\u5e38\u7b80\u5355\u3002\u60a8\u53ea\u9700\u8981\u4f7f\u7528\u5e72\u5e03\u6e05\u6d01\u5373\u53ef\u3002\u907f\u514d\u4f7f\u7528\u6e7f\u5e03\u6216\u5316\u5b66\u6e05\u6d01\u5242\uff0c\u4ee5\u514d\u635f\u574f\u7535\u89c6\u673a\u7684\u8868\u9762\u3002\",\n", " \"generation_info\": null,\n", " \"message\": {\n", " \"content\": \"\u9ad8\u6e05\u7535\u89c6\u673a\u7684\u62a4\u7406\u975e\u5e38\u7b80\u5355\u3002\u60a8\u53ea\u9700\u8981\u4f7f\u7528\u5e72\u5e03\u6e05\u6d01\u5373\u53ef\u3002\u907f\u514d\u4f7f\u7528\u6e7f\u5e03\u6216\u5316\u5b66\u6e05\u6d01\u5242\uff0c\u4ee5\u514d\u635f\u574f\u7535\u89c6\u673a\u7684\u8868\u9762\u3002\",\n", " \"additional_kwargs\": {},\n", " \"example\": false\n", " }\n", " }\n", " ]\n", " ],\n", " \"llm_output\": {\n", " \"token_usage\": {\n", " \"prompt_tokens\": 823,\n", " \"completion_tokens\": 58,\n", " \"total_tokens\": 881\n", " },\n", " \"model_name\": \"gpt-3.5-turbo\"\n", " },\n", " \"run\": null\n", "}\n", "\u001b[36;1m\u001b[1;3m[chain/end]\u001b[0m \u001b[1m[1:chain:RetrievalQA > 2:chain:StuffDocumentsChain > 3:chain:LLMChain] [21.02s] Exiting Chain run with output:\n", "\u001b[0m{\n", " \"text\": \"\u9ad8\u6e05\u7535\u89c6\u673a\u7684\u62a4\u7406\u975e\u5e38\u7b80\u5355\u3002\u60a8\u53ea\u9700\u8981\u4f7f\u7528\u5e72\u5e03\u6e05\u6d01\u5373\u53ef\u3002\u907f\u514d\u4f7f\u7528\u6e7f\u5e03\u6216\u5316\u5b66\u6e05\u6d01\u5242\uff0c\u4ee5\u514d\u635f\u574f\u7535\u89c6\u673a\u7684\u8868\u9762\u3002\"\n", "}\n", "\u001b[36;1m\u001b[1;3m[chain/end]\u001b[0m \u001b[1m[1:chain:RetrievalQA > 2:chain:StuffDocumentsChain] [21.02s] Exiting Chain run with output:\n", "\u001b[0m{\n", " \"output_text\": \"\u9ad8\u6e05\u7535\u89c6\u673a\u7684\u62a4\u7406\u975e\u5e38\u7b80\u5355\u3002\u60a8\u53ea\u9700\u8981\u4f7f\u7528\u5e72\u5e03\u6e05\u6d01\u5373\u53ef\u3002\u907f\u514d\u4f7f\u7528\u6e7f\u5e03\u6216\u5316\u5b66\u6e05\u6d01\u5242\uff0c\u4ee5\u514d\u635f\u574f\u7535\u89c6\u673a\u7684\u8868\u9762\u3002\"\n", "}\n", "\u001b[36;1m\u001b[1;3m[chain/end]\u001b[0m \u001b[1m[1:chain:RetrievalQA] [21.81s] Exiting Chain run with output:\n", "\u001b[0m{\n", " \"result\": \"\u9ad8\u6e05\u7535\u89c6\u673a\u7684\u62a4\u7406\u975e\u5e38\u7b80\u5355\u3002\u60a8\u53ea\u9700\u8981\u4f7f\u7528\u5e72\u5e03\u6e05\u6d01\u5373\u53ef\u3002\u907f\u514d\u4f7f\u7528\u6e7f\u5e03\u6216\u5316\u5b66\u6e05\u6d01\u5242\uff0c\u4ee5\u514d\u635f\u574f\u7535\u89c6\u673a\u7684\u8868\u9762\u3002\"\n", "}\n"]}, {"data": {"text/plain": ["'\u9ad8\u6e05\u7535\u89c6\u673a\u7684\u62a4\u7406\u975e\u5e38\u7b80\u5355\u3002\u60a8\u53ea\u9700\u8981\u4f7f\u7528\u5e72\u5e03\u6e05\u6d01\u5373\u53ef\u3002\u907f\u514d\u4f7f\u7528\u6e7f\u5e03\u6216\u5316\u5b66\u6e05\u6d01\u5242\uff0c\u4ee5\u514d\u635f\u574f\u7535\u89c6\u673a\u7684\u8868\u9762\u3002'"]}, "metadata": {}, "output_type": "display_data"}], "source": ["qa.run(examples[0][\"query\"])#\u91cd\u65b0\u8fd0\u884c\u4e0e\u4e0a\u9762\u76f8\u540c\u7684\u793a\u4f8b\uff0c\u53ef\u4ee5\u770b\u5230\u5b83\u5f00\u59cb\u6253\u5370\u51fa\u66f4\u591a\u7684\u4fe1\u606f"]}, {"cell_type": "markdown", "id": "c645e0d7-a3bb-4a81-a3ec-eb76e6a2e94d", "metadata": {}, "source": ["\u6211\u4eec\u53ef\u4ee5\u770b\u5230\u5b83\u9996\u5148\u6df1\u5165\u5230\u68c0\u7d22QA\u94fe\u4e2d\uff0c\u7136\u540e\u5b83\u8fdb\u5165\u4e86\u4e00\u4e9b\u6587\u6863\u94fe\u3002\u5982\u4e0a\u6240\u8ff0\uff0c\u6211\u4eec\u6b63\u5728\u4f7f\u7528stuff\u65b9\u6cd5\uff0c\u73b0\u5728\u6211\u4eec\u6b63\u5728\u4f20\u9012\u8fd9\u4e2a\u4e0a\u4e0b\u6587\uff0c\u53ef\u4ee5\u770b\u5230\uff0c\u8fd9\u4e2a\u4e0a\u4e0b\u6587\u662f\u7531\u6211\u4eec\u68c0\u7d22\u5230\u7684\u4e0d\u540c\u6587\u6863\u521b\u5efa\u7684\u3002\u56e0\u6b64\uff0c\u5728\u8fdb\u884c\u95ee\u7b54\u65f6\uff0c\u5f53\u8fd4\u56de\u9519\u8bef\u7ed3\u679c\u65f6\uff0c\u901a\u5e38\u4e0d\u662f\u8bed\u8a00\u6a21\u578b\u672c\u8eab\u51fa\u9519\u4e86\uff0c\u5b9e\u9645\u4e0a\u662f\u68c0\u7d22\u6b65\u9aa4\u51fa\u9519\u4e86\uff0c\u4ed4\u7ec6\u67e5\u770b\u95ee\u9898\u7684\u786e\u5207\u5185\u5bb9\u548c\u4e0a\u4e0b\u6587\u53ef\u4ee5\u5e2e\u52a9\u8c03\u8bd5\u51fa\u9519\u7684\u539f\u56e0\u3002 \n", "\u7136\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u518d\u5411\u4e0b\u4e00\u7ea7\uff0c\u770b\u770b\u8fdb\u5165\u8bed\u8a00\u6a21\u578b\u7684\u786e\u5207\u5185\u5bb9\uff0c\u4ee5\u53ca OpenAI \u81ea\u8eab\uff0c\u5728\u8fd9\u91cc\uff0c\u6211\u4eec\u53ef\u4ee5\u770b\u5230\u4f20\u9012\u7684\u5b8c\u6574\u63d0\u793a\uff0c\u6211\u4eec\u6709\u4e00\u4e2a\u7cfb\u7edf\u6d88\u606f\uff0c\u6709\u6240\u4f7f\u7528\u7684\u63d0\u793a\u7684\u63cf\u8ff0\uff0c\u8fd9\u662f\u95ee\u9898\u56de\u7b54\u94fe\u4f7f\u7528\u7684\u63d0\u793a\uff0c\u6211\u4eec\u53ef\u4ee5\u770b\u5230\u63d0\u793a\u6253\u5370\u51fa\u6765\uff0c\u4f7f\u7528\u4ee5\u4e0b\u4e0a\u4e0b\u6587\u7247\u6bb5\u56de\u7b54\u7528\u6237\u7684\u95ee\u9898\u3002\n", "\u5982\u679c\u60a8\u4e0d\u77e5\u9053\u7b54\u6848\uff0c\u53ea\u9700\u8bf4\u60a8\u4e0d\u77e5\u9053\u5373\u53ef\uff0c\u4e0d\u8981\u8bd5\u56fe\u7f16\u9020\u7b54\u6848\u3002\u7136\u540e\u6211\u4eec\u770b\u5230\u4e00\u5806\u4e4b\u524d\u63d2\u5165\u7684\u4e0a\u4e0b\u6587\uff0c\u6211\u4eec\u8fd8\u53ef\u4ee5\u770b\u5230\u6709\u5173\u5b9e\u9645\u8fd4\u56de\u7c7b\u578b\u7684\u66f4\u591a\u4fe1\u606f\u3002\u6211\u4eec\u4e0d\u4ec5\u4ec5\u8fd4\u56de\u4e00\u4e2a\u7b54\u6848\uff0c\u8fd8\u6709token\u7684\u4f7f\u7528\u60c5\u51b5\uff0c\u53ef\u4ee5\u4e86\u89e3\u5230token\u6570\u7684\u4f7f\u7528\u60c5\u51b5\n", "\n", "\n", "\u7531\u4e8e\u8fd9\u662f\u4e00\u4e2a\u76f8\u5bf9\u7b80\u5355\u7684\u94fe\uff0c\u6211\u4eec\u73b0\u5728\u53ef\u4ee5\u770b\u5230\u6700\u7ec8\u7684\u54cd\u5e94\uff0c\u8212\u9002\u7684\u6bdb\u8863\u5957\u88c5\uff0c\u6761\u7eb9\u6b3e\uff0c\u6709\u4fa7\u888b\uff0c\u6b63\u5728\u8d77\u6ce1\uff0c\u901a\u8fc7\u94fe\u8fd4\u56de\u7ed9\u7528\u6237\uff0c\u6211\u4eec\u521a\u521a\u8bb2\u89e3\u4e86\u5982\u4f55\u67e5\u770b\u548c\u8c03\u8bd5\u5355\u4e2a\u8f93\u5165\u5230\u8be5\u94fe\u7684\u60c5\u51b5\u3002\n", "\n", "\n"]}, {"cell_type": "markdown", "id": "f78dc503-f283-4bb0-8c70-3eef992401b9", "metadata": {}, "source": ["#### \u5982\u4f55\u8bc4\u4f30\u65b0\u521b\u5efa\u7684\u5b9e\u4f8b\n", "\u4e0e\u521b\u5efa\u5b83\u4eec\u7c7b\u4f3c\uff0c\u53ef\u4ee5\u8fd0\u884c\u94fe\u6761\u6765\u5904\u7406\u6240\u6709\u793a\u4f8b\uff0c\u7136\u540e\u67e5\u770b\u8f93\u51fa\u5e76\u5c1d\u8bd5\u5f04\u6e05\u695a\uff0c\u53d1\u751f\u4e86\u4ec0\u4e48\uff0c\u5b83\u662f\u5426\u6b63\u786e"]}, {"cell_type": "code", "execution_count": null, "id": "a32fbb61", "metadata": {}, "outputs": [], "source": ["# \u6211\u4eec\u9700\u8981\u4e3a\u6240\u6709\u793a\u4f8b\u521b\u5efa\u9884\u6d4b\uff0c\u5173\u95ed\u8c03\u8bd5\u6a21\u5f0f\uff0c\u4ee5\u4fbf\u4e0d\u5c06\u6240\u6709\u5185\u5bb9\u6253\u5370\u5230\u5c4f\u5e55\u4e0a\n", "langchain.debug = False"]}, {"cell_type": "markdown", "id": "d5bdbdce", "metadata": {}, "source": ["## \u56db\u3001 \u901a\u8fc7LLM\u8fdb\u884c\u8bc4\u4f30\u5b9e\u4f8b"]}, {"cell_type": "code", "execution_count": 24, "id": "a4dca05a", "metadata": {"height": 30}, "outputs": [{"name": "stdout", "output_type": "stream", "text": ["\n", "\n", "\u001b[1m> Entering new chain...\u001b[0m\n", "\n", "\u001b[1m> Finished chain.\u001b[0m\n", "\n", "\n", "\u001b[1m> Entering new chain...\u001b[0m\n"]}, {"name": "stderr", "output_type": "stream", "text": ["Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 1.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 2.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 4.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n"]}, {"name": "stdout", "output_type": "stream", "text": ["\n", "\u001b[1m> Finished chain.\u001b[0m\n", "\n", "\n", "\u001b[1m> Entering new chain...\u001b[0m\n"]}, {"name": "stderr", "output_type": "stream", "text": ["Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 1.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 2.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 4.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 8.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n"]}, {"name": "stdout", "output_type": "stream", "text": ["\n", "\u001b[1m> Finished chain.\u001b[0m\n", "\n", "\n", "\u001b[1m> Entering new chain...\u001b[0m\n"]}, {"name": "stderr", "output_type": "stream", "text": ["Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 1.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 2.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 4.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 8.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n"]}, {"name": "stdout", "output_type": "stream", "text": ["\n", "\u001b[1m> Finished chain.\u001b[0m\n", "\n", "\n", "\u001b[1m> Entering new chain...\u001b[0m\n"]}, {"name": "stderr", "output_type": "stream", "text": ["Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 1.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 2.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 4.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 8.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n"]}, {"name": "stdout", "output_type": "stream", "text": ["\n", "\u001b[1m> Finished chain.\u001b[0m\n", "\n", "\n", "\u001b[1m> Entering new chain...\u001b[0m\n"]}, {"name": "stderr", "output_type": "stream", "text": ["Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 1.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 2.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 4.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 8.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n"]}, {"name": "stdout", "output_type": "stream", "text": ["\n", "\u001b[1m> Finished chain.\u001b[0m\n", "\n", "\n", "\u001b[1m> Entering new chain...\u001b[0m\n"]}, {"name": "stderr", "output_type": "stream", "text": ["Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 1.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 2.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 4.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 8.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n"]}, {"name": "stdout", "output_type": "stream", "text": ["\n", "\u001b[1m> Finished chain.\u001b[0m\n"]}], "source": ["predictions = qa.apply(examples) #\u4e3a\u6240\u6709\u4e0d\u540c\u7684\u793a\u4f8b\u521b\u5efa\u9884\u6d4b"]}, {"cell_type": "code", "execution_count": 25, "id": "6012a3e0", "metadata": {"height": 30}, "outputs": [], "source": ["''' \n", "\u5bf9\u9884\u6d4b\u7684\u7ed3\u679c\u8fdb\u884c\u8bc4\u4f30\uff0c\u5bfc\u5165QA\u95ee\u9898\u56de\u7b54\uff0c\u8bc4\u4f30\u94fe\uff0c\u901a\u8fc7\u8bed\u8a00\u6a21\u578b\u521b\u5efa\u6b64\u94fe\n", "'''\n", "from langchain.evaluation.qa import QAEvalChain #\u5bfc\u5165QA\u95ee\u9898\u56de\u7b54\uff0c\u8bc4\u4f30\u94fe"]}, {"cell_type": "code", "execution_count": 26, "id": "724b1c0b", "metadata": {"height": 47}, "outputs": [], "source": ["#\u901a\u8fc7\u8c03\u7528chatGPT\u8fdb\u884c\u8bc4\u4f30\n", "llm = ChatOpenAI(temperature=0)\n", "eval_chain = QAEvalChain.from_llm(llm)"]}, {"cell_type": "code", "execution_count": 27, "id": "8b46ae55", "metadata": {"height": 30}, "outputs": [{"name": "stderr", "output_type": "stream", "text": ["Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 1.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 2.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 4.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 8.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 1.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 2.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 4.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 8.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 1.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 2.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 4.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 8.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 1.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 2.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 4.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 8.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 16.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 1.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 2.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 1.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 2.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 4.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 8.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 16.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 1.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 2.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 4.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n"]}], "source": ["graded_outputs = eval_chain.evaluate(examples, predictions)#\u5728\u6b64\u94fe\u4e0a\u8c03\u7528evaluate\uff0c\u8fdb\u884c\u8bc4\u4f30"]}, {"cell_type": "markdown", "id": "9ad64f72", "metadata": {}, "source": ["### 4.1 \u8bc4\u4f30\u601d\u8def\n", "\u5f53\u5b83\u9762\u524d\u6709\u6574\u4e2a\u6587\u6863\u65f6\uff0c\u5b83\u53ef\u4ee5\u751f\u6210\u4e00\u4e2a\u771f\u5b9e\u7684\u7b54\u6848\uff0c\u6211\u4eec\u5c06\u6253\u5370\u51fa\u9884\u6d4b\u7684\u7b54\uff0c\u5f53\u5b83\u8fdb\u884cQA\u94fe\u65f6\uff0c\u4f7f\u7528embedding\u548c\u5411\u91cf\u6570\u636e\u5e93\u8fdb\u884c\u68c0\u7d22\u65f6\uff0c\u5c06\u5176\u4f20\u9012\u5230\u8bed\u8a00\u6a21\u578b\u4e2d\uff0c\u7136\u540e\u5c1d\u8bd5\u731c\u6d4b\u9884\u6d4b\u7684\u7b54\u6848\uff0c\u6211\u4eec\u8fd8\u5c06\u6253\u5370\u51fa\u6210\u7ee9\uff0c\u8fd9\u4e5f\u662f\u8bed\u8a00\u6a21\u578b\u751f\u6210\u7684\u3002\u5f53\u5b83\u8981\u6c42\u8bc4\u4f30\u94fe\u8bc4\u4f30\u6b63\u5728\u53d1\u751f\u7684\u4e8b\u60c5\u65f6\uff0c\u4ee5\u53ca\u5b83\u662f\u5426\u6b63\u786e\u6216\u4e0d\u6b63\u786e\u3002\u56e0\u6b64\uff0c\u5f53\u6211\u4eec\u5faa\u73af\u904d\u5386\u6240\u6709\u8fd9\u4e9b\u793a\u4f8b\u5e76\u5c06\u5b83\u4eec\u6253\u5370\u51fa\u6765\u65f6\uff0c\u53ef\u4ee5\u8be6\u7ec6\u4e86\u89e3\u6bcf\u4e2a\u793a\u4f8b"]}, {"cell_type": "code", "execution_count": 28, "id": "3437cfbe", "metadata": {"height": 132}, "outputs": [{"name": "stdout", "output_type": "stream", "text": ["Example 0:\n", "Question: Do the Cozy Comfort Pullover Set have side pockets?\n", "Real Answer: Yes\n", "Predicted Answer: Yes, the Cozy Comfort Pullover Set does have side pockets.\n", "Predicted Grade: CORRECT\n", "\n", "Example 1:\n", "Question: What collection is the Ultra-Lofty 850 Stretch Down Hooded Jacket from?\n", "Real Answer: The DownTek collection\n", "Predicted Answer: The Ultra-Lofty 850 Stretch Down Hooded Jacket is from the DownTek collection.\n", "Predicted Grade: CORRECT\n", "\n", "Example 2:\n", "Question: What is the description of the Women's Campside Oxfords?\n", "Real Answer: The Women's Campside Oxfords are described as an ultracomfortable lace-to-toe Oxford made of soft canvas material, featuring thick cushioning, quality construction, and a broken-in feel from the first time they are worn.\n", "Predicted Answer: The description of the Women's Campside Oxfords is: \"This ultracomfortable lace-to-toe Oxford boasts a super-soft canvas, thick cushioning, and quality construction for a broken-in feel from the first time you put them on.\"\n", "Predicted Grade: CORRECT\n", "\n", "Example 3:\n", "Question: What are the dimensions of the small and medium sizes of the Recycled Waterhog Dog Mat, Chevron Weave?\n", "Real Answer: The small size of the Recycled Waterhog Dog Mat, Chevron Weave has dimensions of 18\" x 28\", while the medium size has dimensions of 22.5\" x 34.5\".\n", "Predicted Answer: The dimensions of the small size of the Recycled Waterhog Dog Mat, Chevron Weave are 18\" x 28\". The dimensions of the medium size are 22.5\" x 34.5\".\n", "Predicted Grade: CORRECT\n", "\n", "Example 4:\n", "Question: What are some features of the Infant and Toddler Girls' Coastal Chill Swimsuit, Two-Piece?\n", "Real Answer: The swimsuit features bright colors, ruffles, and exclusive whimsical prints. It is made of a four-way-stretch and chlorine-resistant fabric that maintains its shape and resists snags. The fabric is also UPF 50+ rated, providing the highest rated sun protection possible by blocking 98% of the sun's harmful rays. The swimsuit has crossover no-slip straps and a fully lined bottom for a secure fit and maximum coverage.\n", "Predicted Answer: Some features of the Infant and Toddler Girls' Coastal Chill Swimsuit, Two-Piece are:\n", "- Bright colors and ruffles\n", "- Exclusive whimsical prints\n", "- Four-way-stretch and chlorine-resistant fabric\n", "- UPF 50+ rated fabric for sun protection\n", "- Crossover no-slip straps\n", "- Fully lined bottom for secure fit and maximum coverage\n", "- Machine washable and line dry for best results\n", "- Imported\n", "Predicted Grade: CORRECT\n", "\n", "Example 5:\n", "Question: What is the fabric composition of the Refresh Swimwear, V-Neck Tankini Contrasts?\n", "Real Answer: The Refresh Swimwear, V-Neck Tankini Contrasts is made of 82% recycled nylon with 18% Lycra\u00ae spandex for the body, and 90% recycled nylon with 10% Lycra\u00ae spandex for the lining.\n", "Predicted Answer: The fabric composition of the Refresh Swimwear, V-Neck Tankini Contrasts is 82% recycled nylon with 18% Lycra\u00ae spandex for the body, and 90% recycled nylon with 10% Lycra\u00ae spandex for the lining.\n", "Predicted Grade: CORRECT\n", "\n", "Example 6:\n", "Question: What is the technology used in the EcoFlex 3L Storm Pants that makes them more breathable?\n", "Real Answer: The EcoFlex 3L Storm Pants use TEK O2 technology to make them more breathable.\n", "Predicted Answer: The technology used in the EcoFlex 3L Storm Pants that makes them more breathable is called TEK O2 technology.\n", "Predicted Grade: CORRECT\n", "\n"]}], "source": ["#\u6211\u4eec\u5c06\u4f20\u5165\u793a\u4f8b\u548c\u9884\u6d4b\uff0c\u5f97\u5230\u4e00\u5806\u5206\u7ea7\u8f93\u51fa\uff0c\u5faa\u73af\u904d\u5386\u5b83\u4eec\u6253\u5370\u7b54\u6848\n", "for i, eg in enumerate(examples):\n", " print(f\"Example {i}:\")\n", " print(\"Question: \" + predictions[i]['query'])\n", " print(\"Real Answer: \" + predictions[i]['answer'])\n", " print(\"Predicted Answer: \" + predictions[i]['result'])\n", " print(\"Predicted Grade: \" + graded_outputs[i]['text'])\n", " print()"]}, {"cell_type": "markdown", "id": "87ecb476", "metadata": {}, "source": ["### 4.2 \u7ed3\u679c\u5206\u6790\n", "\u5bf9\u4e8e\u6bcf\u4e2a\u793a\u4f8b\uff0c\u5b83\u770b\u8d77\u6765\u90fd\u662f\u6b63\u786e\u7684\uff0c\u8ba9\u6211\u4eec\u770b\u770b\u7b2c\u4e00\u4e2a\u4f8b\u5b50\u3002\n", "\u8fd9\u91cc\u7684\u95ee\u9898\u662f\uff0c\u8212\u9002\u7684\u5957\u5934\u886b\u5957\u88c5\uff0c\u6709\u4fa7\u53e3\u888b\u5417\uff1f\u771f\u6b63\u7684\u7b54\u6848\uff0c\u6211\u4eec\u521b\u5efa\u4e86\u8fd9\u4e2a\uff0c\u662f\u80af\u5b9a\u7684\u3002\u6a21\u578b\u9884\u6d4b\u7684\u7b54\u6848\u662f\u8212\u9002\u7684\u5957\u5934\u886b\u5957\u88c5\u6761\u7eb9\uff0c\u786e\u5b9e\u6709\u4fa7\u53e3\u888b\u3002\u56e0\u6b64\uff0c\u6211\u4eec\u53ef\u4ee5\u7406\u89e3\u8fd9\u662f\u4e00\u4e2a\u6b63\u786e\u7684\u7b54\u6848\u3002\u5b83\u5c06\u5176\u8bc4\u4e3a\u6b63\u786e\u3002 \n", "#### \u4f7f\u7528\u6a21\u578b\u8bc4\u4f30\u7684\u4f18\u52bf\n", "\n", "\u4f60\u6709\u8fd9\u4e9b\u7b54\u6848\uff0c\u5b83\u4eec\u662f\u4efb\u610f\u7684\u5b57\u7b26\u4e32\u3002\u6ca1\u6709\u5355\u4e00\u7684\u771f\u5b9e\u5b57\u7b26\u4e32\u662f\u6700\u597d\u7684\u53ef\u80fd\u7b54\u6848\uff0c\u6709\u8bb8\u591a\u4e0d\u540c\u7684\u53d8\u4f53\uff0c\u53ea\u8981\u5b83\u4eec\u5177\u6709\u76f8\u540c\u7684\u8bed\u4e49\uff0c\u5b83\u4eec\u5e94\u8be5\u88ab\u8bc4\u4e3a\u76f8\u4f3c\u3002\u5982\u679c\u4f7f\u7528\u6b63\u5219\u8fdb\u884c\u7cbe\u51c6\u5339\u914d\u5c31\u4f1a\u4e22\u5931\u8bed\u4e49\u4fe1\u606f\uff0c\u5230\u76ee\u524d\u4e3a\u6b62\u5b58\u5728\u7684\u8bb8\u591a\u8bc4\u4f30\u6307\u6807\u90fd\u4e0d\u591f\u597d\u3002\u76ee\u524d\u6700\u6709\u8da3\u548c\u6700\u53d7\u6b22\u8fce\u7684\u4e4b\u4e00\u5c31\u662f\u4f7f\u7528\u8bed\u8a00\u6a21\u578b\u8fdb\u884c\u8bc4\u4f30\u3002"]}, {"cell_type": "markdown", "id": "dd57860a", "metadata": {}, "source": ["### 3.3 \u901a\u8fc7LLM\u8fdb\u884c\u8bc4\u4f30\u5b9e\u4f8b"]}, {"cell_type": "code", "execution_count": 50, "id": "40d908c9", "metadata": {}, "outputs": [{"name": "stdout", "output_type": "stream", "text": ["\n", "\n", "\u001b[1m> Entering new chain...\u001b[0m\n", "\n", "\u001b[1m> Finished chain.\u001b[0m\n", "\n", "\n", "\u001b[1m> Entering new chain...\u001b[0m\n", "\n", "\u001b[1m> Finished chain.\u001b[0m\n", "\n", "\n", "\u001b[1m> Entering new chain...\u001b[0m\n", "\n", "\u001b[1m> Finished chain.\u001b[0m\n", "\n", "\n", "\u001b[1m> Entering new chain...\u001b[0m\n"]}, {"name": "stderr", "output_type": "stream", "text": ["Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 1.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n"]}, {"name": "stdout", "output_type": "stream", "text": ["\n", "\u001b[1m> Finished chain.\u001b[0m\n", "\n", "\n", "\u001b[1m> Entering new chain...\u001b[0m\n"]}, {"name": "stderr", "output_type": "stream", "text": ["Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 1.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 2.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 4.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 8.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n"]}, {"name": "stdout", "output_type": "stream", "text": ["\n", "\u001b[1m> Finished chain.\u001b[0m\n", "\n", "\n", "\u001b[1m> Entering new chain...\u001b[0m\n"]}, {"name": "stderr", "output_type": "stream", "text": ["Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 1.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 2.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 4.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 8.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n"]}, {"name": "stdout", "output_type": "stream", "text": ["\n", "\u001b[1m> Finished chain.\u001b[0m\n", "\n", "\n", "\u001b[1m> Entering new chain...\u001b[0m\n"]}, {"name": "stderr", "output_type": "stream", "text": ["Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 1.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 2.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 4.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 8.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n"]}, {"name": "stdout", "output_type": "stream", "text": ["\n", "\u001b[1m> Finished chain.\u001b[0m\n", "\n", "\n", "\u001b[1m> Entering new chain...\u001b[0m\n"]}, {"name": "stderr", "output_type": "stream", "text": ["Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 1.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 2.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 4.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 8.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 16.0 seconds as it raised APIError: Bad gateway. {\"error\":{\"code\":502,\"message\":\"Bad gateway.\",\"param\":null,\"type\":\"cf_bad_gateway\"}} 502 {'error': {'code': 502, 'message': 'Bad gateway.', 'param': None, 'type': 'cf_bad_gateway'}} {'Date': 'Thu, 29 Jun 2023 02:20:57 GMT', 'Content-Type': 'application/json', 'Content-Length': '84', 'Connection': 'keep-alive', 'X-Frame-Options': 'SAMEORIGIN', 'Referrer-Policy': 'same-origin', 'Cache-Control': 'private, max-age=0, no-store, no-cache, must-revalidate, post-check=0, pre-check=0', 'Expires': 'Thu, 01 Jan 1970 00:00:01 GMT', 'Server': 'cloudflare', 'CF-RAY': '7deaa9d4cd2640da-SIN', 'alt-svc': 'h3=\":443\"; ma=86400'}.\n"]}, {"name": "stdout", "output_type": "stream", "text": ["\n", "\u001b[1m> Finished chain.\u001b[0m\n", "\n", "\n", "\u001b[1m> Entering new chain...\u001b[0m\n", "\n", "\u001b[1m> Finished chain.\u001b[0m\n", "\n", "\n", "\u001b[1m> Entering new chain...\u001b[0m\n", "\n", "\u001b[1m> Finished chain.\u001b[0m\n", "\n", "\n", "\u001b[1m> Entering new chain...\u001b[0m\n"]}, {"name": "stderr", "output_type": "stream", "text": ["Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 1.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 2.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 4.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 8.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n"]}, {"name": "stdout", "output_type": "stream", "text": ["\n", "\u001b[1m> Finished chain.\u001b[0m\n", "\n", "\n", "\u001b[1m> Entering new chain...\u001b[0m\n"]}, {"name": "stderr", "output_type": "stream", "text": ["Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 1.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 2.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 4.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 8.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n"]}, {"name": "stdout", "output_type": "stream", "text": ["\n", "\u001b[1m> Finished chain.\u001b[0m\n"]}], "source": ["predictions = qa.apply(examples) #\u4e3a\u6240\u6709\u4e0d\u540c\u7684\u793a\u4f8b\u521b\u5efa\u9884\u6d4b"]}, {"cell_type": "code", "execution_count": 51, "id": "c71d3d2f", "metadata": {}, "outputs": [], "source": ["''' \n", "\u5bf9\u9884\u6d4b\u7684\u7ed3\u679c\u8fdb\u884c\u8bc4\u4f30\uff0c\u5bfc\u5165QA\u95ee\u9898\u56de\u7b54\uff0c\u8bc4\u4f30\u94fe\uff0c\u901a\u8fc7\u8bed\u8a00\u6a21\u578b\u521b\u5efa\u6b64\u94fe\n", "'''\n", "from langchain.evaluation.qa import QAEvalChain #\u5bfc\u5165QA\u95ee\u9898\u56de\u7b54\uff0c\u8bc4\u4f30\u94fe"]}, {"cell_type": "code", "execution_count": 52, "id": "ac1c848f", "metadata": {}, "outputs": [], "source": ["#\u901a\u8fc7\u8c03\u7528chatGPT\u8fdb\u884c\u8bc4\u4f30\n", "llm = ChatOpenAI(temperature=0)\n", "eval_chain = QAEvalChain.from_llm(llm)"]}, {"cell_type": "code", "execution_count": 53, "id": "50c1250a", "metadata": {}, "outputs": [{"name": "stderr", "output_type": "stream", "text": ["Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 1.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 2.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 4.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 8.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 16.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 1.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 2.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 1.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 2.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 4.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 8.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 16.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 1.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 2.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 1.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 2.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 4.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 8.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 16.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 1.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 2.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 4.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 1.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 2.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 4.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 8.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 1.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 2.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 4.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 8.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 16.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 1.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 2.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", "Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 4.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-2YlJyPMl62f07XPJCAlXfDxj on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n"]}], "source": ["graded_outputs = eval_chain.evaluate(examples, predictions)#\u5728\u6b64\u94fe\u4e0a\u8c03\u7528evaluate\uff0c\u8fdb\u884c\u8bc4\u4f30"]}, {"cell_type": "markdown", "id": "72dc8595", "metadata": {}, "source": ["#### \u8bc4\u4f30\u601d\u8def\n", "\u5f53\u5b83\u9762\u524d\u6709\u6574\u4e2a\u6587\u6863\u65f6\uff0c\u5b83\u53ef\u4ee5\u751f\u6210\u4e00\u4e2a\u771f\u5b9e\u7684\u7b54\u6848\uff0c\u6211\u4eec\u5c06\u6253\u5370\u51fa\u9884\u6d4b\u7684\u7b54\uff0c\u5f53\u5b83\u8fdb\u884cQA\u94fe\u65f6\uff0c\u4f7f\u7528embedding\u548c\u5411\u91cf\u6570\u636e\u5e93\u8fdb\u884c\u68c0\u7d22\u65f6\uff0c\u5c06\u5176\u4f20\u9012\u5230\u8bed\u8a00\u6a21\u578b\u4e2d\uff0c\u7136\u540e\u5c1d\u8bd5\u731c\u6d4b\u9884\u6d4b\u7684\u7b54\u6848\uff0c\u6211\u4eec\u8fd8\u5c06\u6253\u5370\u51fa\u6210\u7ee9\uff0c\u8fd9\u4e5f\u662f\u8bed\u8a00\u6a21\u578b\u751f\u6210\u7684\u3002\u5f53\u5b83\u8981\u6c42\u8bc4\u4f30\u94fe\u8bc4\u4f30\u6b63\u5728\u53d1\u751f\u7684\u4e8b\u60c5\u65f6\uff0c\u4ee5\u53ca\u5b83\u662f\u5426\u6b63\u786e\u6216\u4e0d\u6b63\u786e\u3002\u56e0\u6b64\uff0c\u5f53\u6211\u4eec\u5faa\u73af\u904d\u5386\u6240\u6709\u8fd9\u4e9b\u793a\u4f8b\u5e76\u5c06\u5b83\u4eec\u6253\u5370\u51fa\u6765\u65f6\uff0c\u53ef\u4ee5\u8be6\u7ec6\u4e86\u89e3\u6bcf\u4e2a\u793a\u4f8b"]}, {"cell_type": "code", "execution_count": 54, "id": "bf21e40a", "metadata": {}, "outputs": [{"name": "stdout", "output_type": "stream", "text": ["Example 0:\n", "Question: \u9ad8\u6e05\u7535\u89c6\u673a\u600e\u4e48\u8fdb\u884c\u62a4\u7406\uff1f\n", "Real Answer: \u4f7f\u7528\u5e72\u5e03\u6e05\u6d01\u3002\n", "Predicted Answer: \u9ad8\u6e05\u7535\u89c6\u673a\u7684\u62a4\u7406\u975e\u5e38\u7b80\u5355\u3002\u60a8\u53ea\u9700\u8981\u4f7f\u7528\u5e72\u5e03\u6e05\u6d01\u5373\u53ef\u3002\u907f\u514d\u4f7f\u7528\u6e7f\u5e03\u6216\u5316\u5b66\u6e05\u6d01\u5242\uff0c\u4ee5\u514d\u635f\u574f\u7535\u89c6\u673a\u7684\u8868\u9762\u3002\n", "Predicted Grade: CORRECT\n", "\n", "Example 1:\n", "Question: \u65c5\u884c\u80cc\u5305\u6709\u5185\u5916\u888b\u5417\uff1f\n", "Real Answer: \u6709\u3002\n", "Predicted Answer: \u662f\u7684\uff0c\u65c5\u884c\u80cc\u5305\u6709\u591a\u4e2a\u5b9e\u7528\u7684\u5185\u5916\u888b\uff0c\u53ef\u4ee5\u8f7b\u677e\u88c5\u4e0b\u60a8\u7684\u5fc5\u9700\u54c1\u3002\n", "Predicted Grade: CORRECT\n", "\n", "Example 2:\n", "Question: \u8fd9\u6b3e\u5168\u81ea\u52a8\u5496\u5561\u673a\u6709\u4ec0\u4e48\u7279\u70b9\u548c\u4f18\u52bf\uff1f\n", "Real Answer: \u8fd9\u6b3e\u5168\u81ea\u52a8\u5496\u5561\u673a\u7684\u7279\u70b9\u548c\u4f18\u52bf\u5305\u62ec\u4e00\u952e\u64cd\u4f5c\u3001\u5185\u7f6e\u7814\u78e8\u5668\u548c\u6ee4\u7f51\u3001\u9884\u8bbe\u591a\u79cd\u5496\u5561\u6a21\u5f0f\u3001\u8010\u7528\u6027\u548c\u4e00\u81f4\u6027\uff0c\u4ee5\u53ca\u7531\u9ad8\u54c1\u8d28\u4e0d\u9508\u94a2\u5236\u6210\u7684\u6784\u9020\u3002\n", "Predicted Answer: \u8fd9\u6b3e\u5168\u81ea\u52a8\u5496\u5561\u673a\u6709\u4ee5\u4e0b\u7279\u70b9\u548c\u4f18\u52bf\uff1a\n", "1. \u4e00\u952e\u64cd\u4f5c\uff1a\u53ea\u9700\u6309\u4e0b\u6309\u94ae\uff0c\u5373\u53ef\u7814\u78e8\u5496\u5561\u8c46\u5e76\u6c8f\u5236\u51fa\u60a8\u559c\u7231\u7684\u5496\u5561\uff0c\u975e\u5e38\u65b9\u4fbf\u3002\n", "2. \u8010\u7528\u6027\u548c\u4e00\u81f4\u6027\uff1a\u8fd9\u6b3e\u5496\u5561\u673a\u5177\u6709\u8010\u7528\u6027\u548c\u4e00\u81f4\u6027\uff0c\u4f7f\u5176\u6210\u4e3a\u5bb6\u5ead\u548c\u529e\u516c\u5ba4\u7684\u7406\u60f3\u9009\u62e9\u3002\n", "3. \u5185\u7f6e\u7814\u78e8\u5668\u548c\u6ee4\u7f51\uff1a\u5496\u5561\u673a\u5185\u7f6e\u7814\u78e8\u5668\u548c\u6ee4\u7f51\uff0c\u53ef\u4ee5\u786e\u4fdd\u5496\u5561\u7684\u65b0\u9c9c\u548c\u53e3\u611f\u3002\n", "4. \u591a\u79cd\u5496\u5561\u6a21\u5f0f\uff1a\u5496\u5561\u673a\u9884\u8bbe\u4e86\u591a\u79cd\u5496\u5561\u6a21\u5f0f\uff0c\u53ef\u4ee5\u6839\u636e\u4e2a\u4eba\u53e3\u5473\u9009\u62e9\u4e0d\u540c\u7684\u5496\u5561\u3002\n", "5. \u9ad8\u54c1\u8d28\u6750\u6599\uff1a\u5496\u5561\u673a\u7531\u9ad8\u54c1\u8d28\u4e0d\u9508\u94a2\u5236\u6210\uff0c\u5177\u6709\u4f18\u826f\u7684\u8010\u7528\u6027\u548c\u8d28\u611f\u3002\n", "6. \u4e2d\u56fd\u5236\u9020\uff1a\u8fd9\u6b3e\u5496\u5561\u673a\u662f\u5728\u4e2d\u56fd\u5236\u9020\u7684\uff0c\u5177\u6709\u53ef\u9760\u7684\u54c1\u8d28\u4fdd\u8bc1\u3002\n", "Predicted Grade: CORRECT\n", "\n", "Example 3:\n", "Question: \u8fd9\u6b3e\u7535\u52a8\u7259\u5237\u7684\u89c4\u683c\u662f\u4ec0\u4e48\uff1f\n", "Real Answer: \u8fd9\u6b3e\u7535\u52a8\u7259\u5237\u7684\u89c4\u683c\u662f\u4e00\u822c\u5927\u5c0f\uff0c\u9ad8\u5ea6\u4e3a9.5\u82f1\u5bf8\uff0c\u5bbd\u5ea6\u4e3a1\u82f1\u5bf8\u3002\n", "Predicted Answer: \u8fd9\u6b3e\u7535\u52a8\u7259\u5237\u7684\u89c4\u683c\u662f\uff1a\u9ad8\u5ea6\u4e3a9.5\u82f1\u5bf8\uff0c\u5bbd\u5ea6\u4e3a1\u82f1\u5bf8\u3002\n", "Predicted Grade: CORRECT\n", "\n", "Example 4:\n", "Question: \u8fd9\u6b3e\u6a59\u5473\u7ef4\u751f\u7d20C\u6ce1\u817e\u7247\u7684\u89c4\u683c\u662f\u4ec0\u4e48\uff1f\n", "Real Answer: \u8fd9\u6b3e\u6a59\u5473\u7ef4\u751f\u7d20C\u6ce1\u817e\u7247\u6bcf\u76d2\u542b\u670920\u7247\u3002\n", "Predicted Answer: \u8fd9\u6b3e\u6a59\u5473\u7ef4\u751f\u7d20C\u6ce1\u817e\u7247\u7684\u89c4\u683c\u662f\u6bcf\u76d2\u542b\u670920\u7247\u3002\n", "Predicted Grade: CORRECT\n", "\n", "Example 5:\n", "Question: \u8fd9\u6b3e\u65e0\u7ebf\u84dd\u7259\u8033\u673a\u7684\u89c4\u683c\u662f\u4ec0\u4e48\uff1f\n", "Real Answer: \u5355\u4e2a\u8033\u673a\u5c3a\u5bf8\u4e3a1.5'' x 1.3''\u3002\n", "Predicted Answer: \u8fd9\u6b3e\u65e0\u7ebf\u84dd\u7259\u8033\u673a\u7684\u89c4\u683c\u662f\u5355\u4e2a\u8033\u673a\u5c3a\u5bf8\u4e3a1.5'' x 1.3''\u3002\n", "Predicted Grade: CORRECT\n", "\n", "Example 6:\n", "Question: \u8fd9\u4e2a\u4ea7\u54c1\u7684\u540d\u79f0\u662f\u4ec0\u4e48\uff1f\n", "Real Answer: \u745c\u4f3d\u57ab\n", "Predicted Answer: \u8fd9\u4e2a\u4ea7\u54c1\u7684\u540d\u79f0\u662f\u513f\u7ae5\u76ca\u667a\u73a9\u5177\u3002\n", "Predicted Grade: INCORRECT\n", "\n", "Example 7:\n", "Question: \u8fd9\u6b3e\u5168\u81ea\u52a8\u5496\u5561\u673a\u7684\u89c4\u683c\u662f\u4ec0\u4e48\uff1f\n", "Real Answer: \u5927\u578b\u5c3a\u5bf8\u4e3a13.8'' x 17.3''\uff0c\u4e2d\u578b\u5c3a\u5bf8\u4e3a11.5'' x 15.2''\u3002\n", "Predicted Answer: \u8fd9\u6b3e\u5168\u81ea\u52a8\u5496\u5561\u673a\u6709\u4e24\u79cd\u89c4\u683c\uff1a\n", "- \u5927\u578b\u5c3a\u5bf8\u4e3a13.8'' x 17.3''\u3002\n", "- \u4e2d\u578b\u5c3a\u5bf8\u4e3a11.5'' x 15.2''\u3002\n", "Predicted Grade: CORRECT\n", "\n", "Example 8:\n", "Question: \u8fd9\u6b3e\u7535\u52a8\u7259\u5237\u7684\u9ad8\u5ea6\u548c\u5bbd\u5ea6\u5206\u522b\u662f\u591a\u5c11\uff1f\n", "Real Answer: \u8fd9\u6b3e\u7535\u52a8\u7259\u5237\u7684\u9ad8\u5ea6\u662f9.5\u82f1\u5bf8\uff0c\u5bbd\u5ea6\u662f1\u82f1\u5bf8\u3002\n", "Predicted Answer: \u8fd9\u6b3e\u7535\u52a8\u7259\u5237\u7684\u9ad8\u5ea6\u662f9.5\u82f1\u5bf8\uff0c\u5bbd\u5ea6\u662f1\u82f1\u5bf8\u3002\n", "Predicted Grade: CORRECT\n", "\n", "Example 9:\n", "Question: \u8fd9\u6b3e\u6a59\u5473\u7ef4\u751f\u7d20C\u6ce1\u817e\u7247\u7684\u89c4\u683c\u662f\u4ec0\u4e48\uff1f\n", "Real Answer: \u6bcf\u76d2\u542b\u670920\u7247\u3002\n", "Predicted Answer: \u8fd9\u6b3e\u6a59\u5473\u7ef4\u751f\u7d20C\u6ce1\u817e\u7247\u7684\u89c4\u683c\u662f\u6bcf\u76d2\u542b\u670920\u7247\u3002\n", "Predicted Grade: CORRECT\n", "\n", "Example 10:\n", "Question: \u8fd9\u6b3e\u65e0\u7ebf\u84dd\u7259\u8033\u673a\u7684\u5c3a\u5bf8\u662f\u591a\u5c11\uff1f\n", "Real Answer: \u8fd9\u6b3e\u65e0\u7ebf\u84dd\u7259\u8033\u673a\u7684\u5c3a\u5bf8\u662f1.5'' x 1.3''\u3002\n", "Predicted Answer: \u8fd9\u6b3e\u65e0\u7ebf\u84dd\u7259\u8033\u673a\u7684\u5c3a\u5bf8\u662f1.5'' x 1.3''\u3002\n", "Predicted Grade: CORRECT\n", "\n", "Example 11:\n", "Question: \u8fd9\u6b3e\u745c\u4f3d\u57ab\u7684\u5c3a\u5bf8\u662f\u591a\u5c11\uff1f\n", "Real Answer: \u8fd9\u6b3e\u745c\u4f3d\u57ab\u7684\u5c3a\u5bf8\u662f24'' x 68''\u3002\n", "Predicted Answer: \u8fd9\u6b3e\u745c\u4f3d\u57ab\u7684\u5c3a\u5bf8\u662f24'' x 68''\u3002\n", "Predicted Grade: CORRECT\n", "\n"]}], "source": ["#\u6211\u4eec\u5c06\u4f20\u5165\u793a\u4f8b\u548c\u9884\u6d4b\uff0c\u5f97\u5230\u4e00\u5806\u5206\u7ea7\u8f93\u51fa\uff0c\u5faa\u73af\u904d\u5386\u5b83\u4eec\u6253\u5370\u7b54\u6848\n", "for i, eg in enumerate(examples):\n", " print(f\"Example {i}:\")\n", " print(\"Question: \" + predictions[i]['query'])\n", " print(\"Real Answer: \" + predictions[i]['answer'])\n", " print(\"Predicted Answer: \" + predictions[i]['result'])\n", " print(\"Predicted Grade: \" + graded_outputs[i]['text'])\n", " print()"]}, {"cell_type": "markdown", "id": "ece7c7b4", "metadata": {}, "source": ["#### \u7ed3\u679c\u5206\u6790\n", "\u5bf9\u4e8e\u6bcf\u4e2a\u793a\u4f8b\uff0c\u5b83\u770b\u8d77\u6765\u90fd\u662f\u6b63\u786e\u7684\uff0c\u8ba9\u6211\u4eec\u770b\u770b\u7b2c\u4e00\u4e2a\u4f8b\u5b50\u3002\n", "\u8fd9\u91cc\u7684\u95ee\u9898\u662f\uff0c\u65c5\u884c\u80cc\u5305\u6709\u5185\u5916\u888b\u5417\uff1f\u771f\u6b63\u7684\u7b54\u6848\uff0c\u6211\u4eec\u521b\u5efa\u4e86\u8fd9\u4e2a\uff0c\u662f\u80af\u5b9a\u7684\u3002\u6a21\u578b\u9884\u6d4b\u7684\u7b54\u6848\u662f\u662f\u7684\uff0c\u65c5\u884c\u80cc\u5305\u6709\u591a\u4e2a\u5b9e\u7528\u7684\u5185\u5916\u888b\uff0c\u53ef\u4ee5\u8f7b\u677e\u88c5\u4e0b\u60a8\u7684\u5fc5\u9700\u54c1\u3002\u56e0\u6b64\uff0c\u6211\u4eec\u53ef\u4ee5\u7406\u89e3\u8fd9\u662f\u4e00\u4e2a\u6b63\u786e\u7684\u7b54\u6848\u3002\u5b83\u5c06\u5176\u8bc4\u4e3a\u6b63\u786e\u3002 \n", "#### \u4f7f\u7528\u6a21\u578b\u8bc4\u4f30\u7684\u4f18\u52bf\n", "\n", "\u4f60\u6709\u8fd9\u4e9b\u7b54\u6848\uff0c\u5b83\u4eec\u662f\u4efb\u610f\u7684\u5b57\u7b26\u4e32\u3002\u6ca1\u6709\u5355\u4e00\u7684\u771f\u5b9e\u5b57\u7b26\u4e32\u662f\u6700\u597d\u7684\u53ef\u80fd\u7b54\u6848\uff0c\u6709\u8bb8\u591a\u4e0d\u540c\u7684\u53d8\u4f53\uff0c\u53ea\u8981\u5b83\u4eec\u5177\u6709\u76f8\u540c\u7684\u8bed\u4e49\uff0c\u5b83\u4eec\u5e94\u8be5\u88ab\u8bc4\u4e3a\u76f8\u4f3c\u3002\u5982\u679c\u4f7f\u7528\u6b63\u5219\u8fdb\u884c\u7cbe\u51c6\u5339\u914d\u5c31\u4f1a\u4e22\u5931\u8bed\u4e49\u4fe1\u606f\uff0c\u5230\u76ee\u524d\u4e3a\u6b62\u5b58\u5728\u7684\u8bb8\u591a\u8bc4\u4f30\u6307\u6807\u90fd\u4e0d\u591f\u597d\u3002\u76ee\u524d\u6700\u6709\u8da3\u548c\u6700\u53d7\u6b22\u8fce\u7684\u4e4b\u4e00\u5c31\u662f\u4f7f\u7528\u8bed\u8a00\u6a21\u578b\u8fdb\u884c\u8bc4\u4f30\u3002"]}], "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.12"}, "toc": {"base_numbering": 1, "nav_menu": {}, "number_sections": false, "sideBar": true, "skip_h1_title": false, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": false, "toc_position": {"height": "calc(100% - 180px)", "left": "10px", "top": "150px", "width": "261.818px"}, "toc_section_display": true, "toc_window_display": true}}, "nbformat": 4, "nbformat_minor": 5}