From d6824a5ef4ff9e88d15dc347e37d07e52c2bdcdf Mon Sep 17 00:00:00 2001 From: fanghua Date: Mon, 29 Jul 2024 20:05:27 +0800 Subject: [PATCH] update0728 --- ..._Chengdu_Universiade_China_Gold_Medals.txt | 1 + langchain/jupyter/autogpt/autogpt.ipynb | 108 +++++----- langchain/langsmith/evaluation.ipynb | 47 +++-- langchain/langsmith/tracing.ipynb | 38 ++-- .../translator/translation_chain.py | 28 ++- .../jupyter/translation_chain.ipynb | 107 +++++++--- langchain/sales_chatbot/faiss.ipynb | 144 +++++++------ langchain/sales_chatbot/sales.ipynb | 194 +++++++++++------- langchain/sales_chatbot/sales_chatbot.py | 2 +- 9 files changed, 392 insertions(+), 277 deletions(-) create mode 100644 langchain/jupyter/autogpt/2023_Chengdu_Universiade_China_Gold_Medals.txt diff --git a/langchain/jupyter/autogpt/2023_Chengdu_Universiade_China_Gold_Medals.txt b/langchain/jupyter/autogpt/2023_Chengdu_Universiade_China_Gold_Medals.txt new file mode 100644 index 00000000..5b4315cc --- /dev/null +++ b/langchain/jupyter/autogpt/2023_Chengdu_Universiade_China_Gold_Medals.txt @@ -0,0 +1 @@ +China won 103 gold medals in the 2023 Chengdu Universiade. \ No newline at end of file diff --git a/langchain/jupyter/autogpt/autogpt.ipynb b/langchain/jupyter/autogpt/autogpt.ipynb index 8c1bc171..5a54479c 100644 --- a/langchain/jupyter/autogpt/autogpt.ipynb +++ b/langchain/jupyter/autogpt/autogpt.ipynb @@ -14,18 +14,21 @@ "cell_type": "code", "execution_count": 1, "id": "f15b1505-bbe5-424a-9a24-577cdaae7139", - "metadata": {}, + "metadata": { + "scrolled": true + }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Requirement already satisfied: langchain in c:\\users\\lenovo\\appdata\\roaming\\python\\python310\\site-packages (0.2.7)\n", + "Defaulting to user installation because normal site-packages is not writeable\n", + "Requirement already satisfied: langchain in c:\\users\\lenovo\\appdata\\roaming\\python\\python310\\site-packages (0.2.11)\n", "Requirement already satisfied: PyYAML>=5.3 in c:\\programdata\\anaconda3\\envs\\langchain\\lib\\site-packages (from langchain) (6.0.1)\n", "Requirement already satisfied: SQLAlchemy<3,>=1.4 in c:\\programdata\\anaconda3\\envs\\langchain\\lib\\site-packages (from langchain) (2.0.31)\n", "Requirement already satisfied: aiohttp<4.0.0,>=3.8.3 in c:\\programdata\\anaconda3\\envs\\langchain\\lib\\site-packages (from langchain) (3.9.5)\n", "Requirement already satisfied: async-timeout<5.0.0,>=4.0.0 in c:\\programdata\\anaconda3\\envs\\langchain\\lib\\site-packages (from langchain) (4.0.3)\n", - "Requirement already satisfied: langchain-core<0.3.0,>=0.2.12 in c:\\users\\lenovo\\appdata\\roaming\\python\\python310\\site-packages (from langchain) (0.2.13)\n", + "Requirement already satisfied: langchain-core<0.3.0,>=0.2.23 in c:\\users\\lenovo\\appdata\\roaming\\python\\python310\\site-packages (from langchain) (0.2.24)\n", "Requirement already satisfied: langchain-text-splitters<0.3.0,>=0.2.0 in c:\\programdata\\anaconda3\\envs\\langchain\\lib\\site-packages (from langchain) (0.2.0)\n", "Requirement already satisfied: langsmith<0.2.0,>=0.1.17 in c:\\users\\lenovo\\appdata\\roaming\\python\\python310\\site-packages (from langchain) (0.1.85)\n", "Requirement already satisfied: numpy<2,>=1 in c:\\programdata\\anaconda3\\envs\\langchain\\lib\\site-packages (from langchain) (1.26.4)\n", @@ -37,8 +40,8 @@ "Requirement already satisfied: frozenlist>=1.1.1 in c:\\programdata\\anaconda3\\envs\\langchain\\lib\\site-packages (from aiohttp<4.0.0,>=3.8.3->langchain) (1.4.1)\n", "Requirement already satisfied: multidict<7.0,>=4.5 in c:\\programdata\\anaconda3\\envs\\langchain\\lib\\site-packages (from aiohttp<4.0.0,>=3.8.3->langchain) (6.0.5)\n", "Requirement already satisfied: yarl<2.0,>=1.0 in c:\\programdata\\anaconda3\\envs\\langchain\\lib\\site-packages (from aiohttp<4.0.0,>=3.8.3->langchain) (1.9.4)\n", - "Requirement already satisfied: jsonpatch<2.0,>=1.33 in c:\\programdata\\anaconda3\\envs\\langchain\\lib\\site-packages (from langchain-core<0.3.0,>=0.2.12->langchain) (1.33)\n", - "Requirement already satisfied: packaging<25,>=23.2 in c:\\programdata\\anaconda3\\envs\\langchain\\lib\\site-packages (from langchain-core<0.3.0,>=0.2.12->langchain) (23.2)\n", + "Requirement already satisfied: jsonpatch<2.0,>=1.33 in c:\\programdata\\anaconda3\\envs\\langchain\\lib\\site-packages (from langchain-core<0.3.0,>=0.2.23->langchain) (1.33)\n", + "Requirement already satisfied: packaging<25,>=23.2 in c:\\programdata\\anaconda3\\envs\\langchain\\lib\\site-packages (from langchain-core<0.3.0,>=0.2.23->langchain) (23.2)\n", "Requirement already satisfied: orjson<4.0.0,>=3.9.14 in c:\\programdata\\anaconda3\\envs\\langchain\\lib\\site-packages (from langsmith<0.2.0,>=0.1.17->langchain) (3.10.5)\n", "Requirement already satisfied: annotated-types>=0.4.0 in c:\\programdata\\anaconda3\\envs\\langchain\\lib\\site-packages (from pydantic<3,>=1->langchain) (0.6.0)\n", "Requirement already satisfied: pydantic-core==2.14.6 in c:\\programdata\\anaconda3\\envs\\langchain\\lib\\site-packages (from pydantic<3,>=1->langchain) (2.14.6)\n", @@ -48,7 +51,7 @@ "Requirement already satisfied: urllib3<3,>=1.21.1 in c:\\programdata\\anaconda3\\envs\\langchain\\lib\\site-packages (from requests<3,>=2->langchain) (2.2.2)\n", "Requirement already satisfied: certifi>=2017.4.17 in c:\\programdata\\anaconda3\\envs\\langchain\\lib\\site-packages (from requests<3,>=2->langchain) (2024.2.2)\n", "Requirement already satisfied: greenlet!=0.4.17 in c:\\programdata\\anaconda3\\envs\\langchain\\lib\\site-packages (from SQLAlchemy<3,>=1.4->langchain) (3.0.3)\n", - "Requirement already satisfied: jsonpointer>=1.9 in c:\\programdata\\anaconda3\\envs\\langchain\\lib\\site-packages (from jsonpatch<2.0,>=1.33->langchain-core<0.3.0,>=0.2.12->langchain) (3.0.0)\n" + "Requirement already satisfied: jsonpointer>=1.9 in c:\\programdata\\anaconda3\\envs\\langchain\\lib\\site-packages (from jsonpatch<2.0,>=1.33->langchain-core<0.3.0,>=0.2.23->langchain) (3.0.0)\n" ] } ], @@ -65,7 +68,7 @@ "source": [ "import os\n", "\n", - "os.environ[\"SERPAPI_API_KEY\"] = \"1e3c93e0753ac224098370cd71da86150c6609caba6b5aaa307e04b72a5006e1\"" + "os.environ[\"SERPAPI_API_KEY\"] = \"********************替换为自己的api key*************************\"" ] }, { @@ -78,7 +81,7 @@ "from langchain.utilities import SerpAPIWrapper\n", "from langchain.agents import Tool\n", "from langchain.tools.file_management.write import WriteFileTool\n", - "from langchain.tools.file_management.read import ReadFileTool\n" + "from langchain.tools.file_management.read import ReadFileTool" ] }, { @@ -124,18 +127,10 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 12, "id": "fec6f941-3de6-4124-8eac-fca58e122e7d", "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "`embedding_function` is expected to be an Embeddings object, support for passing in a function will soon be removed.\n" - ] - } - ], + "outputs": [], "source": [ "import faiss\n", "from langchain.vectorstores import FAISS\n", @@ -146,7 +141,10 @@ "# 使用 Faiss 的 IndexFlatL2 索引\n", "index = faiss.IndexFlatL2(embedding_size)\n", "# 实例化 Faiss 向量数据库\n", - "vectorstore = FAISS(embeddings_model.embed_query, index, InMemoryDocstore({}), {})" + "# 旧代码\n", + "# vectorstore = FAISS(embeddings_model.embed_query, index, InMemoryDocstore({}), {})\n", + "# 新代码\n", + "vectorstore = FAISS(embeddings_model, index, InMemoryDocstore({}), {})" ] }, { @@ -159,7 +157,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 13, "id": "d3a718dd-765d-42c5-b490-a7b1e7e78377", "metadata": {}, "outputs": [], @@ -170,7 +168,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 14, "id": "f413b327-9f57-42e0-9923-75a2389f9741", "metadata": {}, "outputs": [], @@ -188,7 +186,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 16, "id": "69ebb267-7bb3-486d-82bd-a0ea56466ba8", "metadata": {}, "outputs": [], @@ -199,7 +197,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 17, "id": "f1606ad4-ccb9-4737-98cc-218a2104e9f2", "metadata": {}, "outputs": [ @@ -216,7 +214,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "C:\\Users\\lenovo\\AppData\\Roaming\\Python\\Python310\\site-packages\\langchain_core\\vectorstores\\base.py:745: UserWarning: No relevant docs were retrieved using the relevance score threshold 0.8\n", + "C:\\Users\\lenovo\\AppData\\Roaming\\Python\\Python310\\site-packages\\langchain_core\\vectorstores\\base.py:796: UserWarning: No relevant docs were retrieved using the relevance score threshold 0.8\n", " warnings.warn(\n" ] }, @@ -277,7 +275,7 @@ " }\n", "} \n", "Ensure the response can be parsed by Python json.loads\n", - "System: The current time and date is Thu Jul 11 20:47:08 2024\n", + "System: The current time and date is Sun Jul 28 21:51:45 2024\n", "System: This reminds you of these events from your past:\n", "[]\n", "\n", @@ -288,9 +286,9 @@ "{\n", " \"thoughts\": {\n", " \"text\": \"I need to find out the number of gold medals China won in the 2023 Chengdu Universiade. To do this, I will use the 'search' command to look up this information online.\",\n", - " \"reasoning\": \"The 'search' command is the most appropriate in this situation because it allows me to find current and historical data from the internet.\",\n", + " \"reasoning\": \"The 'search' command is the most appropriate for this task because it allows me to find current and historical information from the internet.\",\n", " \"plan\": \"- Use the 'search' command to find the number of gold medals China won in the 2023 Chengdu Universiade.\\n- Save the information to a file for future reference.\",\n", - " \"criticism\": \"None at this stage, the plan seems efficient and effective.\",\n", + " \"criticism\": \"None at this stage, as this is the most efficient way to obtain the required information.\",\n", " \"speak\": \"I am going to search for the number of gold medals China won in the 2023 Chengdu Universiade.\"\n", " },\n", " \"command\": {\n", @@ -356,18 +354,18 @@ " }\n", "} \n", "Ensure the response can be parsed by Python json.loads\n", - "System: The current time and date is Thu Jul 11 20:47:25 2024\n", + "System: The current time and date is Sun Jul 28 21:52:26 2024\n", "System: This reminds you of these events from your past:\n", - "['Assistant Reply: {\\n \"thoughts\": {\\n \"text\": \"I need to find out the number of gold medals China won in the 2023 Chengdu Universiade. To do this, I will use the \\'search\\' command to look up this information online.\",\\n \"reasoning\": \"The \\'search\\' command is the most appropriate in this situation because it allows me to find current and historical data from the internet.\",\\n \"plan\": \"- Use the \\'search\\' command to find the number of gold medals China won in the 2023 Chengdu Universiade.\\\\n- Save the information to a file for future reference.\",\\n \"criticism\": \"None at this stage, the plan seems efficient and effective.\",\\n \"speak\": \"I am going to search for the number of gold medals China won in the 2023 Chengdu Universiade.\"\\n },\\n \"command\": {\\n \"name\": \"search\",\\n \"args\": {\\n \"tool_input\": \"2023 Chengdu Universiade China gold medal count\"\\n }\\n }\\n} \\nResult: Command search returned: 103 ']\n", + "['Assistant Reply: {\\n \"thoughts\": {\\n \"text\": \"I need to find out the number of gold medals China won in the 2023 Chengdu Universiade. To do this, I will use the \\'search\\' command to look up this information online.\",\\n \"reasoning\": \"The \\'search\\' command is the most appropriate for this task because it allows me to find current and historical information from the internet.\",\\n \"plan\": \"- Use the \\'search\\' command to find the number of gold medals China won in the 2023 Chengdu Universiade.\\\\n- Save the information to a file for future reference.\",\\n \"criticism\": \"None at this stage, as this is the most efficient way to obtain the required information.\",\\n \"speak\": \"I am going to search for the number of gold medals China won in the 2023 Chengdu Universiade.\"\\n },\\n \"command\": {\\n \"name\": \"search\",\\n \"args\": {\\n \"tool_input\": \"2023 Chengdu Universiade China gold medal count\"\\n }\\n }\\n} \\nResult: Command search returned: 103 ']\n", "\n", "\n", "Human: Determine which next command to use, and respond using the format specified above:\n", "AI: {\n", " \"thoughts\": {\n", " \"text\": \"I need to find out the number of gold medals China won in the 2023 Chengdu Universiade. To do this, I will use the 'search' command to look up this information online.\",\n", - " \"reasoning\": \"The 'search' command is the most appropriate in this situation because it allows me to find current and historical data from the internet.\",\n", + " \"reasoning\": \"The 'search' command is the most appropriate for this task because it allows me to find current and historical information from the internet.\",\n", " \"plan\": \"- Use the 'search' command to find the number of gold medals China won in the 2023 Chengdu Universiade.\\n- Save the information to a file for future reference.\",\n", - " \"criticism\": \"None at this stage, the plan seems efficient and effective.\",\n", + " \"criticism\": \"None at this stage, as this is the most efficient way to obtain the required information.\",\n", " \"speak\": \"I am going to search for the number of gold medals China won in the 2023 Chengdu Universiade.\"\n", " },\n", " \"command\": {\n", @@ -383,10 +381,10 @@ "\u001b[1m> Finished chain.\u001b[0m\n", "{\n", " \"thoughts\": {\n", - " \"text\": \"I have found the number of gold medals China won in the 2023 Chengdu Universiade, which is 103. Now, I need to save this information for future reference. I will use the 'write_file' command to do this.\",\n", - " \"reasoning\": \"The 'write_file' command is the most appropriate in this situation because it allows me to save important information to a file for future reference.\",\n", - " \"plan\": \"- Use the 'write_file' command to save the number of gold medals China won in the 2023 Chengdu Universiade to a file.\\n- Finish the task.\",\n", - " \"criticism\": \"None at this stage, the plan seems efficient and effective.\",\n", + " \"text\": \"I have found the number of gold medals China won in the 2023 Chengdu Universiade, which is 103. Now, I need to save this information to a file for future reference.\",\n", + " \"reasoning\": \"The 'write_file' command is the most appropriate for this task because it allows me to save information to a file.\",\n", + " \"plan\": \"- Use the 'write_file' command to save the number of gold medals China won in the 2023 Chengdu Universiade to a file.\\n- Finish the task after saving the information.\",\n", + " \"criticism\": \"None at this stage, as this is the most efficient way to save the required information.\",\n", " \"speak\": \"I am going to save the number of gold medals China won in the 2023 Chengdu Universiade to a file.\"\n", " },\n", " \"command\": {\n", @@ -454,18 +452,18 @@ " }\n", "} \n", "Ensure the response can be parsed by Python json.loads\n", - "System: The current time and date is Thu Jul 11 20:47:40 2024\n", + "System: The current time and date is Sun Jul 28 21:52:49 2024\n", "System: This reminds you of these events from your past:\n", - "['Assistant Reply: {\\n \"thoughts\": {\\n \"text\": \"I need to find out the number of gold medals China won in the 2023 Chengdu Universiade. To do this, I will use the \\'search\\' command to look up this information online.\",\\n \"reasoning\": \"The \\'search\\' command is the most appropriate in this situation because it allows me to find current and historical data from the internet.\",\\n \"plan\": \"- Use the \\'search\\' command to find the number of gold medals China won in the 2023 Chengdu Universiade.\\\\n- Save the information to a file for future reference.\",\\n \"criticism\": \"None at this stage, the plan seems efficient and effective.\",\\n \"speak\": \"I am going to search for the number of gold medals China won in the 2023 Chengdu Universiade.\"\\n },\\n \"command\": {\\n \"name\": \"search\",\\n \"args\": {\\n \"tool_input\": \"2023 Chengdu Universiade China gold medal count\"\\n }\\n }\\n} \\nResult: Command search returned: 103 ', 'Assistant Reply: {\\n \"thoughts\": {\\n \"text\": \"I have found the number of gold medals China won in the 2023 Chengdu Universiade, which is 103. Now, I need to save this information for future reference. I will use the \\'write_file\\' command to do this.\",\\n \"reasoning\": \"The \\'write_file\\' command is the most appropriate in this situation because it allows me to save important information to a file for future reference.\",\\n \"plan\": \"- Use the \\'write_file\\' command to save the number of gold medals China won in the 2023 Chengdu Universiade to a file.\\\\n- Finish the task.\",\\n \"criticism\": \"None at this stage, the plan seems efficient and effective.\",\\n \"speak\": \"I am going to save the number of gold medals China won in the 2023 Chengdu Universiade to a file.\"\\n },\\n \"command\": {\\n \"name\": \"write_file\",\\n \"args\": {\\n \"file_path\": \"2023_Chengdu_Universiade_China_Gold_Medal_Count.txt\",\\n \"text\": \"China won 103 gold medals in the 2023 Chengdu Universiade.\",\\n \"append\": false\\n }\\n }\\n} \\nResult: Command write_file returned: File written successfully to 2023_Chengdu_Universiade_China_Gold_Medal_Count.txt. ']\n", + "['Assistant Reply: {\\n \"thoughts\": {\\n \"text\": \"I need to find out the number of gold medals China won in the 2023 Chengdu Universiade. To do this, I will use the \\'search\\' command to look up this information online.\",\\n \"reasoning\": \"The \\'search\\' command is the most appropriate for this task because it allows me to find current and historical information from the internet.\",\\n \"plan\": \"- Use the \\'search\\' command to find the number of gold medals China won in the 2023 Chengdu Universiade.\\\\n- Save the information to a file for future reference.\",\\n \"criticism\": \"None at this stage, as this is the most efficient way to obtain the required information.\",\\n \"speak\": \"I am going to search for the number of gold medals China won in the 2023 Chengdu Universiade.\"\\n },\\n \"command\": {\\n \"name\": \"search\",\\n \"args\": {\\n \"tool_input\": \"2023 Chengdu Universiade China gold medal count\"\\n }\\n }\\n} \\nResult: Command search returned: 103 ', 'Assistant Reply: {\\n \"thoughts\": {\\n \"text\": \"I have found the number of gold medals China won in the 2023 Chengdu Universiade, which is 103. Now, I need to save this information to a file for future reference.\",\\n \"reasoning\": \"The \\'write_file\\' command is the most appropriate for this task because it allows me to save information to a file.\",\\n \"plan\": \"- Use the \\'write_file\\' command to save the number of gold medals China won in the 2023 Chengdu Universiade to a file.\\\\n- Finish the task after saving the information.\",\\n \"criticism\": \"None at this stage, as this is the most efficient way to save the required information.\",\\n \"speak\": \"I am going to save the number of gold medals China won in the 2023 Chengdu Universiade to a file.\"\\n },\\n \"command\": {\\n \"name\": \"write_file\",\\n \"args\": {\\n \"file_path\": \"2023_Chengdu_Universiade_China_Gold_Medal_Count.txt\",\\n \"text\": \"China won 103 gold medals in the 2023 Chengdu Universiade.\",\\n \"append\": false\\n }\\n }\\n} \\nResult: Command write_file returned: File written successfully to 2023_Chengdu_Universiade_China_Gold_Medal_Count.txt. ']\n", "\n", "\n", "Human: Determine which next command to use, and respond using the format specified above:\n", "AI: {\n", " \"thoughts\": {\n", " \"text\": \"I need to find out the number of gold medals China won in the 2023 Chengdu Universiade. To do this, I will use the 'search' command to look up this information online.\",\n", - " \"reasoning\": \"The 'search' command is the most appropriate in this situation because it allows me to find current and historical data from the internet.\",\n", + " \"reasoning\": \"The 'search' command is the most appropriate for this task because it allows me to find current and historical information from the internet.\",\n", " \"plan\": \"- Use the 'search' command to find the number of gold medals China won in the 2023 Chengdu Universiade.\\n- Save the information to a file for future reference.\",\n", - " \"criticism\": \"None at this stage, the plan seems efficient and effective.\",\n", + " \"criticism\": \"None at this stage, as this is the most efficient way to obtain the required information.\",\n", " \"speak\": \"I am going to search for the number of gold medals China won in the 2023 Chengdu Universiade.\"\n", " },\n", " \"command\": {\n", @@ -479,10 +477,10 @@ "Human: Determine which next command to use, and respond using the format specified above:\n", "AI: {\n", " \"thoughts\": {\n", - " \"text\": \"I have found the number of gold medals China won in the 2023 Chengdu Universiade, which is 103. Now, I need to save this information for future reference. I will use the 'write_file' command to do this.\",\n", - " \"reasoning\": \"The 'write_file' command is the most appropriate in this situation because it allows me to save important information to a file for future reference.\",\n", - " \"plan\": \"- Use the 'write_file' command to save the number of gold medals China won in the 2023 Chengdu Universiade to a file.\\n- Finish the task.\",\n", - " \"criticism\": \"None at this stage, the plan seems efficient and effective.\",\n", + " \"text\": \"I have found the number of gold medals China won in the 2023 Chengdu Universiade, which is 103. Now, I need to save this information to a file for future reference.\",\n", + " \"reasoning\": \"The 'write_file' command is the most appropriate for this task because it allows me to save information to a file.\",\n", + " \"plan\": \"- Use the 'write_file' command to save the number of gold medals China won in the 2023 Chengdu Universiade to a file.\\n- Finish the task after saving the information.\",\n", + " \"criticism\": \"None at this stage, as this is the most efficient way to save the required information.\",\n", " \"speak\": \"I am going to save the number of gold medals China won in the 2023 Chengdu Universiade to a file.\"\n", " },\n", " \"command\": {\n", @@ -500,16 +498,16 @@ "\u001b[1m> Finished chain.\u001b[0m\n", "{\n", " \"thoughts\": {\n", - " \"text\": \"I have successfully written the number of gold medals China won in the 2023 Chengdu Universiade to a file. Now, I need to signal that I have finished all my objectives.\",\n", - " \"reasoning\": \"The 'finish' command is the most appropriate in this situation because it allows me to signal that I have completed all my tasks.\",\n", - " \"plan\": \"- Use the 'finish' command to signal that I have completed all my tasks.\",\n", - " \"criticism\": \"None at this stage, the plan seems efficient and effective.\",\n", - " \"speak\": \"I have completed all my tasks.\"\n", + " \"text\": \"I have successfully saved the number of gold medals China won in the 2023 Chengdu Universiade to a file. Now, I need to finish the task.\",\n", + " \"reasoning\": \"The 'finish' command is the most appropriate for this task because it allows me to signal that I have completed all my objectives.\",\n", + " \"plan\": \"- Use the 'finish' command to signal that I have completed all my objectives.\",\n", + " \"criticism\": \"None at this stage, as this is the most efficient way to complete the task.\",\n", + " \"speak\": \"I have completed all my objectives.\"\n", " },\n", " \"command\": {\n", " \"name\": \"finish\",\n", " \"args\": {\n", - " \"response\": \"I have found and saved the number of gold medals China won in the 2023 Chengdu Universiade.\"\n", + " \"response\": \"I have found and saved the number of gold medals China won in the 2023 Chengdu Universiade. I have completed all my objectives.\"\n", " }\n", " }\n", "}\n" @@ -518,10 +516,10 @@ { "data": { "text/plain": [ - "'I have found and saved the number of gold medals China won in the 2023 Chengdu Universiade.'" + "'I have found and saved the number of gold medals China won in the 2023 Chengdu Universiade. I have completed all my objectives.'" ] }, - "execution_count": 11, + "execution_count": 17, "metadata": {}, "output_type": "execute_result" } @@ -530,14 +528,6 @@ "agent.run([\"2023年成都大运会,中国金牌数是多少\"])" ] }, - { - "cell_type": "code", - "execution_count": null, - "id": "50dbf7ae-e7b7-494d-afc0-0607a8207188", - "metadata": {}, - "outputs": [], - "source": [] - }, { "cell_type": "code", "execution_count": null, diff --git a/langchain/langsmith/evaluation.ipynb b/langchain/langsmith/evaluation.ipynb index f5ff3bb7..5f1e6ad4 100644 --- a/langchain/langsmith/evaluation.ipynb +++ b/langchain/langsmith/evaluation.ipynb @@ -19,10 +19,27 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "id": "4913e104-82e6-4932-8e80-2b8bd57553c3", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Name: langsmith\n", + "Version: 0.1.85\n", + "Summary: Client library to connect to the LangSmith LLM Tracing and Evaluation Platform.\n", + "Home-page: https://smith.langchain.com/\n", + "Author: LangChain\n", + "Author-email: support@langchain.dev\n", + "License: MIT\n", + "Location: c:\\users\\lenovo\\appdata\\roaming\\python\\python310\\site-packages\n", + "Requires: orjson, pydantic, requests\n", + "Required-by: langchain, langchain-community, langchain-core\n" + ] + } + ], "source": [ "!pip show langsmith" ] @@ -39,7 +56,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 2, "id": "4cb8b089-8d3c-4f56-b5d3-2929dcb49c26", "metadata": {}, "outputs": [], @@ -90,7 +107,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 3, "id": "7b54f22e-17ae-41f2-a137-76e84fef9b49", "metadata": {}, "outputs": [], @@ -135,7 +152,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 4, "id": "0559ea2a-082d-4836-92cd-7473711ee79a", "metadata": {}, "outputs": [], @@ -167,7 +184,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 5, "id": "eeec0c29-5e85-46e1-915b-619b68627d63", "metadata": {}, "outputs": [ @@ -175,7 +192,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "/home/ubuntu/miniconda3/envs/langchain/lib/python3.10/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", + "C:\\ProgramData\\anaconda3\\envs\\langchain\\lib\\site-packages\\tqdm\\auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", " from .autonotebook import tqdm as notebook_tqdm\n" ] }, @@ -183,8 +200,8 @@ "name": "stdout", "output_type": "stream", "text": [ - "View the evaluation results for experiment: 'Toxic Queries-465b0ea2' at:\n", - "https://smith.langchain.com/o/3d35c1a5-b729-4d18-b06d-db0f06a30bc1/datasets/e1df55ff-b66c-4bcf-b5fd-7c63a847136e/compare?selectedSessions=2900c5b7-9dd5-482a-ab79-32888be3d5b9\n", + "View the evaluation results for experiment: 'Toxic Queries-dca23089' at:\n", + "https://smith.langchain.com/o/e310e593-5efd-5b23-825d-2441d452dd41/datasets/4ffa139a-d67c-4bdd-a27c-82700361810b/compare?selectedSessions=fc0f1969-a7af-4c53-9e80-f5aebe2ebb30\n", "\n", "\n" ] @@ -193,7 +210,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "6it [00:01, 4.71it/s]\n" + "6it [00:05, 1.12it/s]\n" ] } ], @@ -242,7 +259,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 6, "id": "46817304-1e17-4ca1-a5ba-faebd80c3728", "metadata": {}, "outputs": [], @@ -275,7 +292,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 7, "id": "096e3129-8e5e-42b9-8c42-d59f072f20c5", "metadata": {}, "outputs": [], @@ -332,17 +349,17 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 8, "id": "431bbdb3-d4a3-445a-9cfc-2e62adff3ad0", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "\"To build a Retrieval-Augmented Generation (RAG) chain in LCEL, you would need to compose a chain that includes a retriever component to fetch relevant documents or data based on a query, and then pass that retrieved data to a generator model to produce a final output. In LCEL, this would typically involve using `Retriever` and `Generator` components, which you can easily piece together thanks to LCEL's composable nature.\\n\\nThe following example is a simplified step-by-step guide to building a bas\"" + "\"To build a Retrieve-and-Generate (RAG) chain in LangChain Expression Language (LCEL), you would typically structure your chain to include a retrieval step from some data source or knowledge base, followed by a generation step using a language model to synthesize responses based on the retrieved information. Although the documentation excerpts provided do not explicitly detail a RAG example, here's a conceptual outline on how you might construct a RAG chain in LCEL based on the principles of chai\"" ] }, - "execution_count": 7, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } diff --git a/langchain/langsmith/tracing.ipynb b/langchain/langsmith/tracing.ipynb index 1fee6f64..217cf485 100644 --- a/langchain/langsmith/tracing.ipynb +++ b/langchain/langsmith/tracing.ipynb @@ -37,7 +37,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 1, "id": "5956cb98-b567-4a2f-9ead-1b14742e8bc7", "metadata": {}, "outputs": [], @@ -81,14 +81,14 @@ "@traceable\n", "def run_pipeline(prompt):\n", " # 运行整个管道流程\n", - " messages = for mat_prompt(prompt) # 创建提示信息\n", + " messages = format_prompt(prompt) # 创建提示信息\n", " response = invoke_llm(messages) # 调用模型\n", " return parse_output(response) # 解析模型输出" ] }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 2, "id": "834711de-9f4a-40e5-90ef-d4fd16c2faff", "metadata": {}, "outputs": [ @@ -98,7 +98,7 @@ "'为一家卖烤鸭的店取名字时,可以考虑以下一些建议:\\n\\n1. 金陵烤鸭坊\\n2. 鸭香阁\\n3. 鸭乐园\\n4. 鸭舫\\n5. 鸭悦坊\\n6. 鸭乐食府\\n7. 鸭香居\\n8. 鸭乐轩\\n9. 鸭乐园\\n10. 鸭乐坊\\n\\n希望这些建议能够帮助你取一个好听且有吸引力的店名!'" ] }, - "execution_count": 7, + "execution_count": 2, "metadata": {}, "output_type": "execute_result" } @@ -109,17 +109,17 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 3, "id": "c2a5528b-9051-4b28-ac04-90579471650f", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "'为一家卖驴肉火烧的店取名可以考虑以下几个方向:\\n1. 与驴肉相关的名字:比如“驴肉香坊”、“驴肉乡村”等。\\n2. 引人入胃的名字:比如“香味驴肉坊”、“美味驴肉馆”等。\\n3. 独特创意的名字:比如“驴肉烧烤屋”、“驴肉烧的香”等。\\n\\n希望以上建议能够帮助你取一个好听的店名!'" + "'为一家卖驴肉火烧的店取名可以考虑以下几个方向:\\n\\n1. 传统风格:比如“骡香阁”、“驴肉馆”等,突出传统风味。\\n\\n2. 创意取名:比如“驴肉一口香”、“驴肉烧之家”等,突出独特创意。\\n\\n3. 地域特色:比如“驴肉火烧坊”、“驴肉香乡”等,突出地域特色。\\n\\n4. 品牌定位:根据店铺的定位和目标顾客群,取名可以突出品牌形象,比如“驴肉鲜香坊”、“驴肉火烧小馆”等。\\n\\n希望以上建议能够帮助你取一个适合的店名!'" ] }, - "execution_count": 8, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } @@ -150,7 +150,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 4, "id": "b3c43988-c21a-4de7-95a6-5c7d8c877d7e", "metadata": {}, "outputs": [], @@ -191,17 +191,17 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 5, "id": "f68fd0b1-42cf-41d6-80db-34ae698938c3", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "'当然!在今天早上的会议中,我们主要讨论了出海创业的机会与挑战。'" + "'当然,今天早上的会议主要讨论了出海创业的机会与挑战。如果需要更详细的总结或其他信息,请告诉我!'" ] }, - "execution_count": 24, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } @@ -243,7 +243,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 6, "id": "b20cc85a-b244-46bb-9f60-ef1bc7dd6596", "metadata": {}, "outputs": [], @@ -326,7 +326,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 7, "id": "21255c23-f9e4-4c96-b729-475cd8ae62f5", "metadata": {}, "outputs": [], @@ -390,7 +390,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 8, "id": "99f85113-0fe2-41c9-80e0-905fbf6d1b22", "metadata": {}, "outputs": [], @@ -423,7 +423,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 9, "id": "c6661f6a-8d54-4fe4-96f8-8f0d046a719b", "metadata": {}, "outputs": [ @@ -431,7 +431,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "这幅图是一种幽默搞笑的对比图。左侧展示的是一只形如肌肉男的柴犬,被称为“16岁的我”,右侧则是一只普通的柴犬,被称为“工作后的我”。图片通过夸张的肌肉和普通的狗的形态来幽默地表达了人们对比自己年轻时充满活力和成年后工作压力导致身体和精神状态“变形”的感受。左边的大肌肉柴犬下方的文字翻译为“我可以一口气做一百个俯卧撑,一条跑足十公里,浴火重生的女人,人见人爱的大男孩”,而右边的普通柴犬下方的文字翻译为“好累啊 好想赖床 浑身疼痛 我没有病 你心有病 我命由我不由天 独步天下”。这些标签富含讽刺和幽默意味,反映了现代生活中劳累与压力的普遍现象。\n" + "这幅图是一种幽默搞笑的图片,通过夸张的形式对比了两种不同的生活方式的后果。左边的狗被描绘成一位肌肉发达的人型体格,代表了经常健身的生活方式,配文是“16岁的我,工作后的我”,意味着这是年轻时候通过努力锻炼得到的结果。右边的狗看起来比较普通甚至有些发福,表示不经常运动、较懒惰的生活状态,与左边形成对比。整个图片表达了生活方式选择对体型和健康的影响的幽默观点。\n" ] } ], @@ -467,7 +467,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 10, "id": "cf7f045a-5a65-4c3d-aa45-e415a38d62ab", "metadata": {}, "outputs": [], @@ -496,7 +496,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 11, "id": "dcb18175-b9ef-40d4-b455-52be5f66028c", "metadata": {}, "outputs": [ @@ -506,7 +506,7 @@ "'孙悟空一共打过四次白骨精。'" ] }, - "execution_count": 22, + "execution_count": 11, "metadata": {}, "output_type": "execute_result" } diff --git a/langchain/openai-translator/ai_translator/translator/translation_chain.py b/langchain/openai-translator/ai_translator/translator/translation_chain.py index e5c85880..b74812e2 100644 --- a/langchain/openai-translator/ai_translator/translator/translation_chain.py +++ b/langchain/openai-translator/ai_translator/translator/translation_chain.py @@ -1,5 +1,12 @@ from langchain_openai import ChatOpenAI -from langchain.chains import LLMChain +# 旧代码 +# from langchain.chains import LLMChain + +# 新代码 +from langchain.globals import set_verbose +from langchain.globals import set_debug + +set_verbose(False) from utils import LOG from langchain_core.prompts import ChatPromptTemplate, HumanMessagePromptTemplate, SystemMessagePromptTemplate @@ -26,16 +33,29 @@ def __init__(self, model_name: str = "gpt-3.5-turbo", verbose: bool = True): # 为了翻译结果的稳定性,将 temperature 设置为 0 chat = ChatOpenAI(model_name=model_name, temperature=0, verbose=verbose) - self.chain = LLMChain(llm=chat, prompt=chat_prompt_template, verbose=verbose) + # 旧代码 + # self.chain = LLMChain(llm=chat, prompt=chat_prompt_template, verbose=verbose) + + # 新代码 + set_debug(verbose) + self.chain = chat_prompt_template | chat def run(self, text: str, source_language: str, target_language: str) -> (str, bool): result = "" try: - result = self.chain.run({ + # 新代码 + result = self.chain.invoke({ "text": text, "source_language": source_language, "target_language": target_language, - }) + }).content + # 旧代码 + # result = self.chain.run({ + # "text": text, + # "source_language": source_language, + # "target_language": target_language, + # }) + except Exception as e: LOG.error(f"An error occurred during translation: {e}") return result, False diff --git a/langchain/openai-translator/jupyter/translation_chain.ipynb b/langchain/openai-translator/jupyter/translation_chain.ipynb index c405ab58..03986200 100644 --- a/langchain/openai-translator/jupyter/translation_chain.ipynb +++ b/langchain/openai-translator/jupyter/translation_chain.ipynb @@ -34,7 +34,7 @@ "在最终调用 `Chat Model` 时,一定是直接传入`LangChain Schema Messages(消息记录)` \n", "\n", "```python\n", - "from langchain.chat_models import ChatOpenAI\n", + "from langchain_openai import ChatOpenAI\n", "chat_model = ChatOpenAI(model_name=\"gpt-3.5-turbo\")\n", "\n", "from langchain.schema import (\n", @@ -50,7 +50,7 @@ "\n", "print(messages)\n", "\n", - "chat_model(messages)\n", + "chat_model.invoke(messages)\n", "```\n", "\n", "打印 messages 输出结果:\n", @@ -69,7 +69,7 @@ "]\n", "```\n", "\n", - "调用 chat_model(messages) 返回结果:\n", + "调用 chat_model.invoke(messages) 返回结果:\n", "\n", "```\n", "AIMessage(\n", @@ -125,7 +125,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "prompt=PromptTemplate(input_variables=[], output_parser=None, partial_variables={}, template='You are a translation expert, proficient in various languages. \\n\\n Translates English to Chinese.', template_format='f-string', validate_template=True) additional_kwargs={}\n" + "prompt=PromptTemplate(input_variables=[], template='You are a translation expert, proficient in various languages. \\n\\n Translates English to Chinese.')\n" ] } ], @@ -155,7 +155,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "prompt=PromptTemplate(input_variables=['text'], output_parser=None, partial_variables={}, template='{text}', template_format='f-string', validate_template=True) additional_kwargs={}\n" + "prompt=PromptTemplate(input_variables=['text'], template='{text}')\n" ] } ], @@ -186,7 +186,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "input_variables=['text'] output_parser=None partial_variables={} messages=[SystemMessagePromptTemplate(prompt=PromptTemplate(input_variables=[], output_parser=None, partial_variables={}, template='You are a translation expert, proficient in various languages. \\n\\n Translates English to Chinese.', template_format='f-string', validate_template=True), additional_kwargs={}), HumanMessagePromptTemplate(prompt=PromptTemplate(input_variables=['text'], output_parser=None, partial_variables={}, template='{text}', template_format='f-string', validate_template=True), additional_kwargs={})]\n" + "input_variables=['text'] messages=[SystemMessagePromptTemplate(prompt=PromptTemplate(input_variables=[], template='You are a translation expert, proficient in various languages. \\n\\n Translates English to Chinese.')), HumanMessagePromptTemplate(prompt=PromptTemplate(input_variables=['text'], template='{text}'))]\n" ] } ], @@ -243,7 +243,7 @@ { "data": { "text/plain": [ - "ChatPromptValue(messages=[SystemMessage(content='You are a translation expert, proficient in various languages. \\n\\n Translates English to Chinese.', additional_kwargs={}), HumanMessage(content='I love programming.', additional_kwargs={}, example=False)])" + "ChatPromptValue(messages=[SystemMessage(content='You are a translation expert, proficient in various languages. \\n\\n Translates English to Chinese.'), HumanMessage(content='I love programming.')])" ] }, "execution_count": 7, @@ -284,8 +284,8 @@ { "data": { "text/plain": [ - "[SystemMessage(content='You are a translation expert, proficient in various languages. \\n\\n Translates English to Chinese.', additional_kwargs={}),\n", - " HumanMessage(content='I love programming.', additional_kwargs={}, example=False)]" + "[SystemMessage(content='You are a translation expert, proficient in various languages. \\n\\n Translates English to Chinese.'),\n", + " HumanMessage(content='I love programming.')]" ] }, "execution_count": 9, @@ -312,7 +312,11 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.chat_models import ChatOpenAI\n", + "#旧代码\n", + "# from langchain.chat_models import ChatOpenAI\n", + "\n", + "# 新代码\n", + "from langchain_openai import ChatOpenAI\n", "\n", "# 为了翻译结果的稳定性,将 temperature 设置为 0\n", "translation_model = ChatOpenAI(model_name=\"gpt-3.5-turbo\", temperature=0)" @@ -325,7 +329,11 @@ "metadata": {}, "outputs": [], "source": [ - "translation_result = translation_model(chat_prompt)" + "#旧代码\n", + "# translation_result = translation_model(chat_prompt)\n", + "\n", + "#新代码\n", + "translation_result = translation_model.invoke(chat_prompt)" ] }, { @@ -337,7 +345,7 @@ { "data": { "text/plain": [ - "AIMessage(content='我喜欢编程。', additional_kwargs={}, example=False)" + "AIMessage(content='我喜欢编程。', response_metadata={'token_usage': {'completion_tokens': 8, 'prompt_tokens': 34, 'total_tokens': 42}, 'model_name': 'gpt-3.5-turbo', 'system_fingerprint': None, 'finish_reason': 'stop', 'logprobs': None}, id='run-dfdaf553-1c18-4c0b-b31b-ee84eb9599c2-0')" ] }, "execution_count": 12, @@ -383,10 +391,15 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.chains import LLMChain\n", + "#旧代码\n", + "# from langchain.chains import LLMChain\n", "\n", "# 无需再每次都使用 to_messages 方法构造 Chat Prompt\n", - "translation_chain = LLMChain(llm=translation_model, prompt=chat_prompt_template)" + "#旧代码\n", + "# translation_chain = LLMChain(llm=translation_model, prompt=chat_prompt_template)\n", + "\n", + "#新代码\n", + "translation_chain = chat_prompt_template | translation_model" ] }, { @@ -397,7 +410,11 @@ "outputs": [], "source": [ "# 等价于 translation_result.content (字符串类型)\n", - "chain_result = translation_chain.run({'text': \"I love programming.\"})" + "#旧代码\n", + "# chain_result = translation_chain.run({'text': \"I love programming.\"})\n", + "\n", + "#新代码\n", + "chain_result = translation_chain.invoke({'text': \"I love programming.\"})" ] }, { @@ -415,12 +432,16 @@ } ], "source": [ - "print(chain_result)" + "# 旧代码\n", + "# print(chain_result)\n", + "\n", + "# 新代码\n", + "print(chain_result.content)" ] }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 17, "id": "faddd232-0308-45ce-b2a6-899f261abe57", "metadata": {}, "outputs": [ @@ -430,13 +451,17 @@ "'我喜欢人工智能和大型语言模型。'" ] }, - "execution_count": 25, + "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "translation_chain.run({'text': \"I love AI and Large Language Model.\"})" + "# 旧代码\n", + "# translation_chain.run({'text': \"I love AI and Large Language Model.\"})\n", + "\n", + "# 新代码\n", + "translation_chain.invoke({'text': \"I love AI and Large Language Model.\"}).content" ] }, { @@ -448,7 +473,7 @@ { "data": { "text/plain": [ - "'[水果, 颜色, 价格(美元)] [苹果, 红色, 1.20] [香蕉, 黄色, 0.50] [橙子, 橙色, 0.80] [草莓, 红色, 2.50] [蓝莓, 蓝色, 3.00] [猕猴桃, 绿色, 1.00] [芒果, 橙色, 1.50] [葡萄, 紫色, 2.00]'" + "'[水果,颜色,价格(美元)] [苹果,红色,1.20] [香蕉,黄色,0.50] [橙子,橙色,0.80] [草莓,红色,2.50] [蓝莓,蓝色,3.00] [猕猴桃,绿色,1.00] [芒果,橙色,1.50] [葡萄,紫色,2.00]'" ] }, "execution_count": 18, @@ -457,7 +482,11 @@ } ], "source": [ - "translation_chain.run({'text': \"[Fruit, Color, Price (USD)] [Apple, Red, 1.20] [Banana, Yellow, 0.50] [Orange, Orange, 0.80] [Strawberry, Red, 2.50] [Blueberry, Blue, 3.00] [Kiwi, Green, 1.00] [Mango, Orange, 1.50] [Grape, Purple, 2.00]\"})\n" + "# 旧代码\n", + "# translation_chain.run({'text': \"[Fruit, Color, Price (USD)] [Apple, Red, 1.20] [Banana, Yellow, 0.50] [Orange, Orange, 0.80] [Strawberry, Red, 2.50] [Blueberry, Blue, 3.00] [Kiwi, Green, 1.00] [Mango, Orange, 1.50] [Grape, Purple, 2.00]\"})\n", + "\n", + "# 新代码\n", + "translation_chain.invoke({'text': \"[Fruit, Color, Price (USD)] [Apple, Red, 1.20] [Banana, Yellow, 0.50] [Orange, Orange, 0.80] [Strawberry, Red, 2.50] [Blueberry, Blue, 3.00] [Kiwi, Green, 1.00] [Mango, Orange, 1.50] [Grape, Purple, 2.00]\"}).content" ] }, { @@ -515,7 +544,11 @@ "metadata": {}, "outputs": [], "source": [ - "m_translation_chain = LLMChain(llm=translation_model, prompt=m_chat_prompt_template) " + "# 旧代码\n", + "# m_translation_chain = LLMChain(llm=translation_model, prompt=m_chat_prompt_template) \n", + "\n", + "# 新代码\n", + "m_translation_chain = m_chat_prompt_template | translation_model" ] }, { @@ -527,7 +560,7 @@ { "data": { "text/plain": [ - "'I enjoy studying large language models, as it is easy, simple, and enjoyable.'" + "'I enjoy studying large language models, which are easy, simple, and enjoyable.'" ] }, "execution_count": 23, @@ -536,11 +569,19 @@ } ], "source": [ - "m_translation_chain.run({\n", + "# 旧代码\n", + "# m_translation_chain.run({\n", + "# \"source_language\": \"Chinese\",\n", + "# \"target_language\": \"English\",\n", + "# \"text\": \"我喜欢学习大语言模型,轻松简单又愉快\",\n", + "# })\n", + "\n", + "# 新代码\n", + "m_translation_chain.invoke({\n", " \"source_language\": \"Chinese\",\n", " \"target_language\": \"English\",\n", " \"text\": \"我喜欢学习大语言模型,轻松简单又愉快\",\n", - "})" + "}).content" ] }, { @@ -552,7 +593,7 @@ { "data": { "text/plain": [ - "'私は大規模言語モデルの学習が好きです。それは簡単で楽しいです。'" + "'私は大規模言語モデルの学習が好きで、簡単で楽しいです。'" ] }, "execution_count": 24, @@ -561,11 +602,19 @@ } ], "source": [ - "m_translation_chain.run({\n", + "# 旧代码\n", + "# m_translation_chain.run({\n", + "# \"source_language\": \"Chinese\",\n", + "# \"target_language\": \"Japanese\",\n", + "# \"text\": \"我喜欢学习大语言模型,轻松简单又愉快\",\n", + "# })\n", + "\n", + "# 新代码\n", + "m_translation_chain.invoke({\n", " \"source_language\": \"Chinese\",\n", " \"target_language\": \"Japanese\",\n", " \"text\": \"我喜欢学习大语言模型,轻松简单又愉快\",\n", - "})" + "}).content" ] }, { @@ -603,7 +652,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.11" + "version": "3.10.14" } }, "nbformat": 4, diff --git a/langchain/sales_chatbot/faiss.ipynb b/langchain/sales_chatbot/faiss.ipynb index aa4f5bd5..8d5dfa69 100644 --- a/langchain/sales_chatbot/faiss.ipynb +++ b/langchain/sales_chatbot/faiss.ipynb @@ -10,9 +10,10 @@ "name": "stdout", "output_type": "stream", "text": [ - "Requirement already satisfied: faiss-cpu in /root/miniconda3/envs/langchain/lib/python3.10/site-packages (1.7.4)\n", - "\u001b[33mWARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv\u001b[0m\u001b[33m\n", - "\u001b[0m" + "Defaulting to user installation because normal site-packages is not writeable\n", + "Requirement already satisfied: faiss-cpu in c:\\users\\lenovo\\appdata\\roaming\\python\\python310\\site-packages (1.8.0.post1)\n", + "Requirement already satisfied: numpy<2.0,>=1.0 in c:\\programdata\\anaconda3\\envs\\langchain\\lib\\site-packages (from faiss-cpu) (1.26.4)\n", + "Requirement already satisfied: packaging in c:\\programdata\\anaconda3\\envs\\langchain\\lib\\site-packages (from faiss-cpu) (23.2)\n" ] } ], @@ -54,20 +55,22 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 4, "id": "cb5d79ae-6fe5-4fff-bfab-30762c1f1188", - "metadata": {}, + "metadata": { + "scrolled": true + }, "outputs": [], "source": [ "# 实例化文档加载器\n", - "loader = TextLoader(\"../jupyter/tests/state_of_the_union.txt\")\n", + "loader = TextLoader(\"../jupyter/tests/state_of_the_union.txt\", encoding='utf-8')\n", "# 加载文档\n", "documents = loader.load()" ] }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 5, "id": "9b404e22-a148-4b63-a69c-54b1e76db5d3", "metadata": {}, "outputs": [], @@ -80,63 +83,58 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 6, "id": "34897ff3-8f9c-42d6-841f-e06c0d2f521c", - "metadata": { - "collapsed": true, - "jupyter": { - "outputs_hidden": true - } - }, + "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "[Document(page_content='Madam Speaker, Madam Vice President, our First Lady and Second Gentleman. Members of Congress and the Cabinet. Justices of the Supreme Court. My fellow Americans. \\n\\nLast year COVID-19 kept us apart. This year we are finally together again. \\n\\nTonight, we meet as Democrats Republicans and Independents. But most importantly as Americans. \\n\\nWith a duty to one another to the American people to the Constitution. \\n\\nAnd with an unwavering resolve that freedom will always triumph over tyranny. \\n\\nSix days ago, Russia’s Vladimir Putin sought to shake the foundations of the free world thinking he could make it bend to his menacing ways. But he badly miscalculated. \\n\\nHe thought he could roll into Ukraine and the world would roll over. Instead he met a wall of strength he never imagined. \\n\\nHe met the Ukrainian people. \\n\\nFrom President Zelenskyy to every Ukrainian, their fearlessness, their courage, their determination, inspires the world.', metadata={'source': '../jupyter/tests/state_of_the_union.txt'}),\n", - " Document(page_content='Groups of citizens blocking tanks with their bodies. Everyone from students to retirees teachers turned soldiers defending their homeland. \\n\\nIn this struggle as President Zelenskyy said in his speech to the European Parliament “Light will win over darkness.” The Ukrainian Ambassador to the United States is here tonight. \\n\\nLet each of us here tonight in this Chamber send an unmistakable signal to Ukraine and to the world. \\n\\nPlease rise if you are able and show that, Yes, we the United States of America stand with the Ukrainian people. \\n\\nThroughout our history we’ve learned this lesson when dictators do not pay a price for their aggression they cause more chaos. \\n\\nThey keep moving. \\n\\nAnd the costs and the threats to America and the world keep rising. \\n\\nThat’s why the NATO Alliance was created to secure peace and stability in Europe after World War 2. \\n\\nThe United States is a member along with 29 other nations. \\n\\nIt matters. American diplomacy matters. American resolve matters.', metadata={'source': '../jupyter/tests/state_of_the_union.txt'}),\n", - " Document(page_content='Putin’s latest attack on Ukraine was premeditated and unprovoked. \\n\\nHe rejected repeated efforts at diplomacy. \\n\\nHe thought the West and NATO wouldn’t respond. And he thought he could divide us at home. Putin was wrong. We were ready. Here is what we did. \\n\\nWe prepared extensively and carefully. \\n\\nWe spent months building a coalition of other freedom-loving nations from Europe and the Americas to Asia and Africa to confront Putin. \\n\\nI spent countless hours unifying our European allies. We shared with the world in advance what we knew Putin was planning and precisely how he would try to falsely justify his aggression. \\n\\nWe countered Russia’s lies with truth. \\n\\nAnd now that he has acted the free world is holding him accountable. \\n\\nAlong with twenty-seven members of the European Union including France, Germany, Italy, as well as countries like the United Kingdom, Canada, Japan, Korea, Australia, New Zealand, and many others, even Switzerland.', metadata={'source': '../jupyter/tests/state_of_the_union.txt'}),\n", - " Document(page_content='We are inflicting pain on Russia and supporting the people of Ukraine. Putin is now isolated from the world more than ever. \\n\\nTogether with our allies –we are right now enforcing powerful economic sanctions. \\n\\nWe are cutting off Russia’s largest banks from the international financial system. \\n\\nPreventing Russia’s central bank from defending the Russian Ruble making Putin’s $630 Billion “war fund” worthless. \\n\\nWe are choking off Russia’s access to technology that will sap its economic strength and weaken its military for years to come. \\n\\nTonight I say to the Russian oligarchs and corrupt leaders who have bilked billions of dollars off this violent regime no more. \\n\\nThe U.S. Department of Justice is assembling a dedicated task force to go after the crimes of Russian oligarchs. \\n\\nWe are joining with our European allies to find and seize your yachts your luxury apartments your private jets. We are coming for your ill-begotten gains.', metadata={'source': '../jupyter/tests/state_of_the_union.txt'}),\n", - " Document(page_content='And tonight I am announcing that we will join our allies in closing off American air space to all Russian flights – further isolating Russia – and adding an additional squeeze –on their economy. The Ruble has lost 30% of its value. \\n\\nThe Russian stock market has lost 40% of its value and trading remains suspended. Russia’s economy is reeling and Putin alone is to blame. \\n\\nTogether with our allies we are providing support to the Ukrainians in their fight for freedom. Military assistance. Economic assistance. Humanitarian assistance. \\n\\nWe are giving more than $1 Billion in direct assistance to Ukraine. \\n\\nAnd we will continue to aid the Ukrainian people as they defend their country and to help ease their suffering. \\n\\nLet me be clear, our forces are not engaged and will not engage in conflict with Russian forces in Ukraine. \\n\\nOur forces are not going to Europe to fight in Ukraine, but to defend our NATO Allies – in the event that Putin decides to keep moving west.', metadata={'source': '../jupyter/tests/state_of_the_union.txt'}),\n", - " Document(page_content='For that purpose we’ve mobilized American ground forces, air squadrons, and ship deployments to protect NATO countries including Poland, Romania, Latvia, Lithuania, and Estonia. \\n\\nAs I have made crystal clear the United States and our Allies will defend every inch of territory of NATO countries with the full force of our collective power. \\n\\nAnd we remain clear-eyed. The Ukrainians are fighting back with pure courage. But the next few days weeks, months, will be hard on them. \\n\\nPutin has unleashed violence and chaos. But while he may make gains on the battlefield – he will pay a continuing high price over the long run. \\n\\nAnd a proud Ukrainian people, who have known 30 years of independence, have repeatedly shown that they will not tolerate anyone who tries to take their country backwards. \\n\\nTo all Americans, I will be honest with you, as I’ve always promised. A Russian dictator, invading a foreign country, has costs around the world.', metadata={'source': '../jupyter/tests/state_of_the_union.txt'}),\n", - " Document(page_content='And I’m taking robust action to make sure the pain of our sanctions is targeted at Russia’s economy. And I will use every tool at our disposal to protect American businesses and consumers. \\n\\nTonight, I can announce that the United States has worked with 30 other countries to release 60 Million barrels of oil from reserves around the world. \\n\\nAmerica will lead that effort, releasing 30 Million barrels from our own Strategic Petroleum Reserve. And we stand ready to do more if necessary, unified with our allies. \\n\\nThese steps will help blunt gas prices here at home. And I know the news about what’s happening can seem alarming. \\n\\nBut I want you to know that we are going to be okay. \\n\\nWhen the history of this era is written Putin’s war on Ukraine will have left Russia weaker and the rest of the world stronger. \\n\\nWhile it shouldn’t have taken something so terrible for people around the world to see what’s at stake now everyone sees it clearly.', metadata={'source': '../jupyter/tests/state_of_the_union.txt'}),\n", - " Document(page_content='We see the unity among leaders of nations and a more unified Europe a more unified West. And we see unity among the people who are gathering in cities in large crowds around the world even in Russia to demonstrate their support for Ukraine. \\n\\nIn the battle between democracy and autocracy, democracies are rising to the moment, and the world is clearly choosing the side of peace and security. \\n\\nThis is a real test. It’s going to take time. So let us continue to draw inspiration from the iron will of the Ukrainian people. \\n\\nTo our fellow Ukrainian Americans who forge a deep bond that connects our two nations we stand with you. \\n\\nPutin may circle Kyiv with tanks, but he will never gain the hearts and souls of the Ukrainian people. \\n\\nHe will never extinguish their love of freedom. He will never weaken the resolve of the free world. \\n\\nWe meet tonight in an America that has lived through two of the hardest years this nation has ever faced. \\n\\nThe pandemic has been punishing.', metadata={'source': '../jupyter/tests/state_of_the_union.txt'}),\n", - " Document(page_content='And so many families are living paycheck to paycheck, struggling to keep up with the rising cost of food, gas, housing, and so much more. \\n\\nI understand. \\n\\nI remember when my Dad had to leave our home in Scranton, Pennsylvania to find work. I grew up in a family where if the price of food went up, you felt it. \\n\\nThat’s why one of the first things I did as President was fight to pass the American Rescue Plan. \\n\\nBecause people were hurting. We needed to act, and we did. \\n\\nFew pieces of legislation have done more in a critical moment in our history to lift us out of crisis. \\n\\nIt fueled our efforts to vaccinate the nation and combat COVID-19. It delivered immediate economic relief for tens of millions of Americans. \\n\\nHelped put food on their table, keep a roof over their heads, and cut the cost of health insurance. \\n\\nAnd as my Dad used to say, it gave people a little breathing room.', metadata={'source': '../jupyter/tests/state_of_the_union.txt'}),\n", - " Document(page_content='And unlike the $2 Trillion tax cut passed in the previous administration that benefitted the top 1% of Americans, the American Rescue Plan helped working people—and left no one behind. \\n\\nAnd it worked. It created jobs. Lots of jobs. \\n\\nIn fact—our economy created over 6.5 Million new jobs just last year, more jobs created in one year \\nthan ever before in the history of America. \\n\\nOur economy grew at a rate of 5.7% last year, the strongest growth in nearly 40 years, the first step in bringing fundamental change to an economy that hasn’t worked for the working people of this nation for too long. \\n\\nFor the past 40 years we were told that if we gave tax breaks to those at the very top, the benefits would trickle down to everyone else. \\n\\nBut that trickle-down theory led to weaker economic growth, lower wages, bigger deficits, and the widest gap between those at the top and everyone else in nearly a century.', metadata={'source': '../jupyter/tests/state_of_the_union.txt'}),\n", - " Document(page_content='Vice President Harris and I ran for office with a new economic vision for America. \\n\\nInvest in America. Educate Americans. Grow the workforce. Build the economy from the bottom up \\nand the middle out, not from the top down. \\n\\nBecause we know that when the middle class grows, the poor have a ladder up and the wealthy do very well. \\n\\nAmerica used to have the best roads, bridges, and airports on Earth. \\n\\nNow our infrastructure is ranked 13th in the world. \\n\\nWe won’t be able to compete for the jobs of the 21st Century if we don’t fix that. \\n\\nThat’s why it was so important to pass the Bipartisan Infrastructure Law—the most sweeping investment to rebuild America in history. \\n\\nThis was a bipartisan effort, and I want to thank the members of both parties who worked to make it happen. \\n\\nWe’re done talking about infrastructure weeks. \\n\\nWe’re going to have an infrastructure decade.', metadata={'source': '../jupyter/tests/state_of_the_union.txt'}),\n", - " Document(page_content='It is going to transform America and put us on a path to win the economic competition of the 21st Century that we face with the rest of the world—particularly with China. \\n\\nAs I’ve told Xi Jinping, it is never a good bet to bet against the American people. \\n\\nWe’ll create good jobs for millions of Americans, modernizing roads, airports, ports, and waterways all across America. \\n\\nAnd we’ll do it all to withstand the devastating effects of the climate crisis and promote environmental justice. \\n\\nWe’ll build a national network of 500,000 electric vehicle charging stations, begin to replace poisonous lead pipes—so every child—and every American—has clean water to drink at home and at school, provide affordable high-speed internet for every American—urban, suburban, rural, and tribal communities. \\n\\n4,000 projects have already been announced. \\n\\nAnd tonight, I’m announcing that this year we will start fixing over 65,000 miles of highway and 1,500 bridges in disrepair.', metadata={'source': '../jupyter/tests/state_of_the_union.txt'}),\n", - " Document(page_content='When we use taxpayer dollars to rebuild America – we are going to Buy American: buy American products to support American jobs. \\n\\nThe federal government spends about $600 Billion a year to keep the country safe and secure. \\n\\nThere’s been a law on the books for almost a century \\nto make sure taxpayers’ dollars support American jobs and businesses. \\n\\nEvery Administration says they’ll do it, but we are actually doing it. \\n\\nWe will buy American to make sure everything from the deck of an aircraft carrier to the steel on highway guardrails are made in America. \\n\\nBut to compete for the best jobs of the future, we also need to level the playing field with China and other competitors. \\n\\nThat’s why it is so important to pass the Bipartisan Innovation Act sitting in Congress that will make record investments in emerging technologies and American manufacturing. \\n\\nLet me give you one example of why it’s so important to pass it.', metadata={'source': '../jupyter/tests/state_of_the_union.txt'}),\n", - " Document(page_content='If you travel 20 miles east of Columbus, Ohio, you’ll find 1,000 empty acres of land. \\n\\nIt won’t look like much, but if you stop and look closely, you’ll see a “Field of dreams,” the ground on which America’s future will be built. \\n\\nThis is where Intel, the American company that helped build Silicon Valley, is going to build its $20 billion semiconductor “mega site”. \\n\\nUp to eight state-of-the-art factories in one place. 10,000 new good-paying jobs. \\n\\nSome of the most sophisticated manufacturing in the world to make computer chips the size of a fingertip that power the world and our everyday lives. \\n\\nSmartphones. The Internet. Technology we have yet to invent. \\n\\nBut that’s just the beginning. \\n\\nIntel’s CEO, Pat Gelsinger, who is here tonight, told me they are ready to increase their investment from \\n$20 billion to $100 billion. \\n\\nThat would be one of the biggest investments in manufacturing in American history. \\n\\nAnd all they’re waiting for is for you to pass this bill.', metadata={'source': '../jupyter/tests/state_of_the_union.txt'}),\n", - " Document(page_content='So let’s not wait any longer. Send it to my desk. I’ll sign it. \\n\\nAnd we will really take off. \\n\\nAnd Intel is not alone. \\n\\nThere’s something happening in America. \\n\\nJust look around and you’ll see an amazing story. \\n\\nThe rebirth of the pride that comes from stamping products “Made In America.” The revitalization of American manufacturing. \\n\\nCompanies are choosing to build new factories here, when just a few years ago, they would have built them overseas. \\n\\nThat’s what is happening. Ford is investing $11 billion to build electric vehicles, creating 11,000 jobs across the country. \\n\\nGM is making the largest investment in its history—$7 billion to build electric vehicles, creating 4,000 jobs in Michigan. \\n\\nAll told, we created 369,000 new manufacturing jobs in America just last year. \\n\\nPowered by people I’ve met like JoJo Burgess, from generations of union steelworkers from Pittsburgh, who’s here with us tonight.', metadata={'source': '../jupyter/tests/state_of_the_union.txt'}),\n", - " Document(page_content='As Ohio Senator Sherrod Brown says, “It’s time to bury the label “Rust Belt.” \\n\\nIt’s time. \\n\\nBut with all the bright spots in our economy, record job growth and higher wages, too many families are struggling to keep up with the bills. \\n\\nInflation is robbing them of the gains they might otherwise feel. \\n\\nI get it. That’s why my top priority is getting prices under control. \\n\\nLook, our economy roared back faster than most predicted, but the pandemic meant that businesses had a hard time hiring enough workers to keep up production in their factories. \\n\\nThe pandemic also disrupted global supply chains. \\n\\nWhen factories close, it takes longer to make goods and get them from the warehouse to the store, and prices go up. \\n\\nLook at cars. \\n\\nLast year, there weren’t enough semiconductors to make all the cars that people wanted to buy. \\n\\nAnd guess what, prices of automobiles went up. \\n\\nSo—we have a choice. \\n\\nOne way to fight inflation is to drive down wages and make Americans poorer.', metadata={'source': '../jupyter/tests/state_of_the_union.txt'}),\n", - " Document(page_content='I have a better plan to fight inflation. \\n\\nLower your costs, not your wages. \\n\\nMake more cars and semiconductors in America. \\n\\nMore infrastructure and innovation in America. \\n\\nMore goods moving faster and cheaper in America. \\n\\nMore jobs where you can earn a good living in America. \\n\\nAnd instead of relying on foreign supply chains, let’s make it in America. \\n\\nEconomists call it “increasing the productive capacity of our economy.” \\n\\nI call it building a better America. \\n\\nMy plan to fight inflation will lower your costs and lower the deficit. \\n\\n17 Nobel laureates in economics say my plan will ease long-term inflationary pressures. Top business leaders and most Americans support my plan. And here’s the plan: \\n\\nFirst – cut the cost of prescription drugs. Just look at insulin. One in ten Americans has diabetes. In Virginia, I met a 13-year-old boy named Joshua Davis.', metadata={'source': '../jupyter/tests/state_of_the_union.txt'}),\n", - " Document(page_content='He and his Dad both have Type 1 diabetes, which means they need insulin every day. Insulin costs about $10 a vial to make. \\n\\nBut drug companies charge families like Joshua and his Dad up to 30 times more. I spoke with Joshua’s mom. \\n\\nImagine what it’s like to look at your child who needs insulin and have no idea how you’re going to pay for it. \\n\\nWhat it does to your dignity, your ability to look your child in the eye, to be the parent you expect to be. \\n\\nJoshua is here with us tonight. Yesterday was his birthday. Happy birthday, buddy. \\n\\nFor Joshua, and for the 200,000 other young people with Type 1 diabetes, let’s cap the cost of insulin at $35 a month so everyone can afford it. \\n\\nDrug companies will still do very well. And while we’re at it let Medicare negotiate lower prices for prescription drugs, like the VA already does.', metadata={'source': '../jupyter/tests/state_of_the_union.txt'}),\n", - " Document(page_content='Look, the American Rescue Plan is helping millions of families on Affordable Care Act plans save $2,400 a year on their health care premiums. Let’s close the coverage gap and make those savings permanent. \\n\\nSecond – cut energy costs for families an average of $500 a year by combatting climate change. \\n\\nLet’s provide investments and tax credits to weatherize your homes and businesses to be energy efficient and you get a tax credit; double America’s clean energy production in solar, wind, and so much more; lower the price of electric vehicles, saving you another $80 a month because you’ll never have to pay at the gas pump again. \\n\\nThird – cut the cost of child care. Many families pay up to $14,000 a year for child care per child. \\n\\nMiddle-class and working families shouldn’t have to pay more than 7% of their income for care of young children.', metadata={'source': '../jupyter/tests/state_of_the_union.txt'}),\n", - " Document(page_content='My plan will cut the cost in half for most families and help parents, including millions of women, who left the workforce during the pandemic because they couldn’t afford child care, to be able to get back to work. \\n\\nMy plan doesn’t stop there. It also includes home and long-term care. More affordable housing. And Pre-K for every 3- and 4-year-old. \\n\\nAll of these will lower costs. \\n\\nAnd under my plan, nobody earning less than $400,000 a year will pay an additional penny in new taxes. Nobody. \\n\\nThe one thing all Americans agree on is that the tax system is not fair. We have to fix it. \\n\\nI’m not looking to punish anyone. But let’s make sure corporations and the wealthiest Americans start paying their fair share. \\n\\nJust last year, 55 Fortune 500 corporations earned $40 billion in profits and paid zero dollars in federal income tax. \\n\\nThat’s simply not fair. That’s why I’ve proposed a 15% minimum tax rate for corporations.', metadata={'source': '../jupyter/tests/state_of_the_union.txt'}),\n", - " Document(page_content='We got more than 130 countries to agree on a global minimum tax rate so companies can’t get out of paying their taxes at home by shipping jobs and factories overseas. \\n\\nThat’s why I’ve proposed closing loopholes so the very wealthy don’t pay a lower tax rate than a teacher or a firefighter. \\n\\nSo that’s my plan. It will grow the economy and lower costs for families. \\n\\nSo what are we waiting for? Let’s get this done. And while you’re at it, confirm my nominees to the Federal Reserve, which plays a critical role in fighting inflation. \\n\\nMy plan will not only lower costs to give families a fair shot, it will lower the deficit. \\n\\nThe previous Administration not only ballooned the deficit with tax cuts for the very wealthy and corporations, it undermined the watchdogs whose job was to keep pandemic relief funds from being wasted. \\n\\nBut in my administration, the watchdogs have been welcomed back.', metadata={'source': '../jupyter/tests/state_of_the_union.txt'}),\n", - " Document(page_content='We’re going after the criminals who stole billions in relief money meant for small businesses and millions of Americans. \\n\\nAnd tonight, I’m announcing that the Justice Department will name a chief prosecutor for pandemic fraud. \\n\\nBy the end of this year, the deficit will be down to less than half what it was before I took office. \\n\\nThe only president ever to cut the deficit by more than one trillion dollars in a single year. \\n\\nLowering your costs also means demanding more competition. \\n\\nI’m a capitalist, but capitalism without competition isn’t capitalism. \\n\\nIt’s exploitation—and it drives up prices. \\n\\nWhen corporations don’t have to compete, their profits go up, your prices go up, and small businesses and family farmers and ranchers go under. \\n\\nWe see it happening with ocean carriers moving goods in and out of America. \\n\\nDuring the pandemic, these foreign-owned companies raised prices by as much as 1,000% and made record profits.', metadata={'source': '../jupyter/tests/state_of_the_union.txt'}),\n", - " Document(page_content='Tonight, I’m announcing a crackdown on these companies overcharging American businesses and consumers. \\n\\nAnd as Wall Street firms take over more nursing homes, quality in those homes has gone down and costs have gone up. \\n\\nThat ends on my watch. \\n\\nMedicare is going to set higher standards for nursing homes and make sure your loved ones get the care they deserve and expect. \\n\\nWe’ll also cut costs and keep the economy going strong by giving workers a fair shot, provide more training and apprenticeships, hire them based on their skills not degrees. \\n\\nLet’s pass the Paycheck Fairness Act and paid leave. \\n\\nRaise the minimum wage to $15 an hour and extend the Child Tax Credit, so no one has to raise a family in poverty. \\n\\nLet’s increase Pell Grants and increase our historic support of HBCUs, and invest in what Jill—our First Lady who teaches full-time—calls America’s best-kept secret: community colleges.', metadata={'source': '../jupyter/tests/state_of_the_union.txt'}),\n", - " Document(page_content='And let’s pass the PRO Act when a majority of workers want to form a union—they shouldn’t be stopped. \\n\\nWhen we invest in our workers, when we build the economy from the bottom up and the middle out together, we can do something we haven’t done in a long time: build a better America. \\n\\nFor more than two years, COVID-19 has impacted every decision in our lives and the life of the nation. \\n\\nAnd I know you’re tired, frustrated, and exhausted. \\n\\nBut I also know this. \\n\\nBecause of the progress we’ve made, because of your resilience and the tools we have, tonight I can say \\nwe are moving forward safely, back to more normal routines. \\n\\nWe’ve reached a new moment in the fight against COVID-19, with severe cases down to a level not seen since last July. \\n\\nJust a few days ago, the Centers for Disease Control and Prevention—the CDC—issued new mask guidelines. \\n\\nUnder these new guidelines, most Americans in most of the country can now be mask free.', metadata={'source': '../jupyter/tests/state_of_the_union.txt'}),\n", - " Document(page_content='And based on the projections, more of the country will reach that point across the next couple of weeks. \\n\\nThanks to the progress we have made this past year, COVID-19 need no longer control our lives. \\n\\nI know some are talking about “living with COVID-19”. Tonight – I say that we will never just accept living with COVID-19. \\n\\nWe will continue to combat the virus as we do other diseases. And because this is a virus that mutates and spreads, we will stay on guard. \\n\\nHere are four common sense steps as we move forward safely. \\n\\nFirst, stay protected with vaccines and treatments. We know how incredibly effective vaccines are. If you’re vaccinated and boosted you have the highest degree of protection. \\n\\nWe will never give up on vaccinating more Americans. Now, I know parents with kids under 5 are eager to see a vaccine authorized for their children. \\n\\nThe scientists are working hard to get that done and we’ll be ready with plenty of vaccines when they do.', metadata={'source': '../jupyter/tests/state_of_the_union.txt'}),\n", - " Document(page_content='We’re also ready with anti-viral treatments. If you get COVID-19, the Pfizer pill reduces your chances of ending up in the hospital by 90%. \\n\\nWe’ve ordered more of these pills than anyone in the world. And Pfizer is working overtime to get us 1 Million pills this month and more than double that next month. \\n\\nAnd we’re launching the “Test to Treat” initiative so people can get tested at a pharmacy, and if they’re positive, receive antiviral pills on the spot at no cost. \\n\\nIf you’re immunocompromised or have some other vulnerability, we have treatments and free high-quality masks. \\n\\nWe’re leaving no one behind or ignoring anyone’s needs as we move forward. \\n\\nAnd on testing, we have made hundreds of millions of tests available for you to order for free. \\n\\nEven if you already ordered free tests tonight, I am announcing that you can order more from covidtests.gov starting next week.', metadata={'source': '../jupyter/tests/state_of_the_union.txt'}),\n", - " Document(page_content='Second – we must prepare for new variants. Over the past year, we’ve gotten much better at detecting new variants. \\n\\nIf necessary, we’ll be able to deploy new vaccines within 100 days instead of many more months or years. \\n\\nAnd, if Congress provides the funds we need, we’ll have new stockpiles of tests, masks, and pills ready if needed. \\n\\nI cannot promise a new variant won’t come. But I can promise you we’ll do everything within our power to be ready if it does. \\n\\nThird – we can end the shutdown of schools and businesses. We have the tools we need. \\n\\nIt’s time for Americans to get back to work and fill our great downtowns again. People working from home can feel safe to begin to return to the office. \\n\\nWe’re doing that here in the federal government. The vast majority of federal workers will once again work in person. \\n\\nOur schools are open. Let’s keep it that way. Our kids need to be in school.', metadata={'source': '../jupyter/tests/state_of_the_union.txt'}),\n", - " Document(page_content='And with 75% of adult Americans fully vaccinated and hospitalizations down by 77%, most Americans can remove their masks, return to work, stay in the classroom, and move forward safely. \\n\\nWe achieved this because we provided free vaccines, treatments, tests, and masks. \\n\\nOf course, continuing this costs money. \\n\\nI will soon send Congress a request. \\n\\nThe vast majority of Americans have used these tools and may want to again, so I expect Congress to pass it quickly. \\n\\nFourth, we will continue vaccinating the world. \\n\\nWe’ve sent 475 Million vaccine doses to 112 countries, more than any other nation. \\n\\nAnd we won’t stop. \\n\\nWe have lost so much to COVID-19. Time with one another. And worst of all, so much loss of life. \\n\\nLet’s use this moment to reset. Let’s stop looking at COVID-19 as a partisan dividing line and see it for what it is: A God-awful disease. \\n\\nLet’s stop seeing each other as enemies, and start seeing each other for who we really are: Fellow Americans.', metadata={'source': '../jupyter/tests/state_of_the_union.txt'}),\n", - " Document(page_content='We can’t change how divided we’ve been. But we can change how we move forward—on COVID-19 and other issues we must face together. \\n\\nI recently visited the New York City Police Department days after the funerals of Officer Wilbert Mora and his partner, Officer Jason Rivera. \\n\\nThey were responding to a 9-1-1 call when a man shot and killed them with a stolen gun. \\n\\nOfficer Mora was 27 years old. \\n\\nOfficer Rivera was 22. \\n\\nBoth Dominican Americans who’d grown up on the same streets they later chose to patrol as police officers. \\n\\nI spoke with their families and told them that we are forever in debt for their sacrifice, and we will carry on their mission to restore the trust and safety every community deserves. \\n\\nI’ve worked on these issues a long time. \\n\\nI know what works: Investing in crime preventionand community police officers who’ll walk the beat, who’ll know the neighborhood, and who can restore trust and safety.', metadata={'source': '../jupyter/tests/state_of_the_union.txt'}),\n", - " Document(page_content='So let’s not abandon our streets. Or choose between safety and equal justice. \\n\\nLet’s come together to protect our communities, restore trust, and hold law enforcement accountable. \\n\\nThat’s why the Justice Department required body cameras, banned chokeholds, and restricted no-knock warrants for its officers. \\n\\nThat’s why the American Rescue Plan provided $350 Billion that cities, states, and counties can use to hire more police and invest in proven strategies like community violence interruption—trusted messengers breaking the cycle of violence and trauma and giving young people hope. \\n\\nWe should all agree: The answer is not to Defund the police. The answer is to FUND the police with the resources and training they need to protect our communities. \\n\\nI ask Democrats and Republicans alike: Pass my budget and keep our neighborhoods safe.', metadata={'source': '../jupyter/tests/state_of_the_union.txt'}),\n", - " Document(page_content='And I will keep doing everything in my power to crack down on gun trafficking and ghost guns you can buy online and make at home—they have no serial numbers and can’t be traced. \\n\\nAnd I ask Congress to pass proven measures to reduce gun violence. Pass universal background checks. Why should anyone on a terrorist list be able to purchase a weapon? \\n\\nBan assault weapons and high-capacity magazines. \\n\\nRepeal the liability shield that makes gun manufacturers the only industry in America that can’t be sued. \\n\\nThese laws don’t infringe on the Second Amendment. They save lives. \\n\\nThe most fundamental right in America is the right to vote – and to have it counted. And it’s under assault. \\n\\nIn state after state, new laws have been passed, not only to suppress the vote, but to subvert entire elections. \\n\\nWe cannot let this happen.', metadata={'source': '../jupyter/tests/state_of_the_union.txt'}),\n", - " Document(page_content='Tonight. I call on the Senate to: Pass the Freedom to Vote Act. Pass the John Lewis Voting Rights Act. And while you’re at it, pass the Disclose Act so Americans can know who is funding our elections. \\n\\nTonight, I’d like to honor someone who has dedicated his life to serve this country: Justice Stephen Breyer—an Army veteran, Constitutional scholar, and retiring Justice of the United States Supreme Court. Justice Breyer, thank you for your service. \\n\\nOne of the most serious constitutional responsibilities a President has is nominating someone to serve on the United States Supreme Court. \\n\\nAnd I did that 4 days ago, when I nominated Circuit Court of Appeals Judge Ketanji Brown Jackson. One of our nation’s top legal minds, who will continue Justice Breyer’s legacy of excellence.', metadata={'source': '../jupyter/tests/state_of_the_union.txt'}),\n", - " Document(page_content='A former top litigator in private practice. A former federal public defender. And from a family of public school educators and police officers. A consensus builder. Since she’s been nominated, she’s received a broad range of support—from the Fraternal Order of Police to former judges appointed by Democrats and Republicans. \\n\\nAnd if we are to advance liberty and justice, we need to secure the Border and fix the immigration system. \\n\\nWe can do both. At our border, we’ve installed new technology like cutting-edge scanners to better detect drug smuggling. \\n\\nWe’ve set up joint patrols with Mexico and Guatemala to catch more human traffickers. \\n\\nWe’re putting in place dedicated immigration judges so families fleeing persecution and violence can have their cases heard faster. \\n\\nWe’re securing commitments and supporting partners in South and Central America to host more refugees and secure their own borders.', metadata={'source': '../jupyter/tests/state_of_the_union.txt'}),\n", - " Document(page_content='We can do all this while keeping lit the torch of liberty that has led generations of immigrants to this land—my forefathers and so many of yours. \\n\\nProvide a pathway to citizenship for Dreamers, those on temporary status, farm workers, and essential workers. \\n\\nRevise our laws so businesses have the workers they need and families don’t wait decades to reunite. \\n\\nIt’s not only the right thing to do—it’s the economically smart thing to do. \\n\\nThat’s why immigration reform is supported by everyone from labor unions to religious leaders to the U.S. Chamber of Commerce. \\n\\nLet’s get it done once and for all. \\n\\nAdvancing liberty and justice also requires protecting the rights of women. \\n\\nThe constitutional right affirmed in Roe v. Wade—standing precedent for half a century—is under attack as never before. \\n\\nIf we want to go forward—not backward—we must protect access to health care. Preserve a woman’s right to choose. And let’s continue to advance maternal health care in America.', metadata={'source': '../jupyter/tests/state_of_the_union.txt'}),\n", - " Document(page_content='And for our LGBTQ+ Americans, let’s finally get the bipartisan Equality Act to my desk. The onslaught of state laws targeting transgender Americans and their families is wrong. \\n\\nAs I said last year, especially to our younger transgender Americans, I will always have your back as your President, so you can be yourself and reach your God-given potential. \\n\\nWhile it often appears that we never agree, that isn’t true. I signed 80 bipartisan bills into law last year. From preventing government shutdowns to protecting Asian-Americans from still-too-common hate crimes to reforming military justice. \\n\\nAnd soon, we’ll strengthen the Violence Against Women Act that I first wrote three decades ago. It is important for us to show the nation that we can come together and do big things. \\n\\nSo tonight I’m offering a Unity Agenda for the Nation. Four big things we can do together. \\n\\nFirst, beat the opioid epidemic.', metadata={'source': '../jupyter/tests/state_of_the_union.txt'}),\n", - " Document(page_content='There is so much we can do. Increase funding for prevention, treatment, harm reduction, and recovery. \\n\\nGet rid of outdated rules that stop doctors from prescribing treatments. And stop the flow of illicit drugs by working with state and local law enforcement to go after traffickers. \\n\\nIf you’re suffering from addiction, know you are not alone. I believe in recovery, and I celebrate the 23 million Americans in recovery. \\n\\nSecond, let’s take on mental health. Especially among our children, whose lives and education have been turned upside down. \\n\\nThe American Rescue Plan gave schools money to hire teachers and help students make up for lost learning. \\n\\nI urge every parent to make sure your school does just that. And we can all play a part—sign up to be a tutor or a mentor. \\n\\nChildren were also struggling before the pandemic. Bullying, violence, trauma, and the harms of social media.', metadata={'source': '../jupyter/tests/state_of_the_union.txt'}),\n", - " Document(page_content='As Frances Haugen, who is here with us tonight, has shown, we must hold social media platforms accountable for the national experiment they’re conducting on our children for profit. \\n\\nIt’s time to strengthen privacy protections, ban targeted advertising to children, demand tech companies stop collecting personal data on our children. \\n\\nAnd let’s get all Americans the mental health services they need. More people they can turn to for help, and full parity between physical and mental health care. \\n\\nThird, support our veterans. \\n\\nVeterans are the best of us. \\n\\nI’ve always believed that we have a sacred obligation to equip all those we send to war and care for them and their families when they come home. \\n\\nMy administration is providing assistance with job training and housing, and now helping lower-income veterans get VA care debt-free. \\n\\nOur troops in Iraq and Afghanistan faced many dangers.', metadata={'source': '../jupyter/tests/state_of_the_union.txt'}),\n", - " Document(page_content='One was stationed at bases and breathing in toxic smoke from “burn pits” that incinerated wastes of war—medical and hazard material, jet fuel, and more. \\n\\nWhen they came home, many of the world’s fittest and best trained warriors were never the same. \\n\\nHeadaches. Numbness. Dizziness. \\n\\nA cancer that would put them in a flag-draped coffin. \\n\\nI know. \\n\\nOne of those soldiers was my son Major Beau Biden. \\n\\nWe don’t know for sure if a burn pit was the cause of his brain cancer, or the diseases of so many of our troops. \\n\\nBut I’m committed to finding out everything we can. \\n\\nCommitted to military families like Danielle Robinson from Ohio. \\n\\nThe widow of Sergeant First Class Heath Robinson. \\n\\nHe was born a soldier. Army National Guard. Combat medic in Kosovo and Iraq. \\n\\nStationed near Baghdad, just yards from burn pits the size of football fields. \\n\\nHeath’s widow Danielle is here with us tonight. They loved going to Ohio State football games. He loved building Legos with their daughter.', metadata={'source': '../jupyter/tests/state_of_the_union.txt'}),\n", - " Document(page_content='But cancer from prolonged exposure to burn pits ravaged Heath’s lungs and body. \\n\\nDanielle says Heath was a fighter to the very end. \\n\\nHe didn’t know how to stop fighting, and neither did she. \\n\\nThrough her pain she found purpose to demand we do better. \\n\\nTonight, Danielle—we are. \\n\\nThe VA is pioneering new ways of linking toxic exposures to diseases, already helping more veterans get benefits. \\n\\nAnd tonight, I’m announcing we’re expanding eligibility to veterans suffering from nine respiratory cancers. \\n\\nI’m also calling on Congress: pass a law to make sure veterans devastated by toxic exposures in Iraq and Afghanistan finally get the benefits and comprehensive health care they deserve. \\n\\nAnd fourth, let’s end cancer as we know it. \\n\\nThis is personal to me and Jill, to Kamala, and to so many of you. \\n\\nCancer is the #2 cause of death in America–second only to heart disease.', metadata={'source': '../jupyter/tests/state_of_the_union.txt'}),\n", - " Document(page_content='Last month, I announced our plan to supercharge \\nthe Cancer Moonshot that President Obama asked me to lead six years ago. \\n\\nOur goal is to cut the cancer death rate by at least 50% over the next 25 years, turn more cancers from death sentences into treatable diseases. \\n\\nMore support for patients and families. \\n\\nTo get there, I call on Congress to fund ARPA-H, the Advanced Research Projects Agency for Health. \\n\\nIt’s based on DARPA—the Defense Department project that led to the Internet, GPS, and so much more. \\n\\nARPA-H will have a singular purpose—to drive breakthroughs in cancer, Alzheimer’s, diabetes, and more. \\n\\nA unity agenda for the nation. \\n\\nWe can do this. \\n\\nMy fellow Americans—tonight , we have gathered in a sacred space—the citadel of our democracy. \\n\\nIn this Capitol, generation after generation, Americans have debated great questions amid great strife, and have done great things. \\n\\nWe have fought for freedom, expanded liberty, defeated totalitarianism and terror.', metadata={'source': '../jupyter/tests/state_of_the_union.txt'}),\n", - " Document(page_content='And built the strongest, freest, and most prosperous nation the world has ever known. \\n\\nNow is the hour. \\n\\nOur moment of responsibility. \\n\\nOur test of resolve and conscience, of history itself. \\n\\nIt is in this moment that our character is formed. Our purpose is found. Our future is forged. \\n\\nWell I know this nation. \\n\\nWe will meet the test. \\n\\nTo protect freedom and liberty, to expand fairness and opportunity. \\n\\nWe will save democracy. \\n\\nAs hard as these times have been, I am more optimistic about America today than I have been my whole life. \\n\\nBecause I see the future that is within our grasp. \\n\\nBecause I know there is simply nothing beyond our capacity. \\n\\nWe are the only nation on Earth that has always turned every crisis we have faced into an opportunity. \\n\\nThe only nation that can be defined by a single word: possibilities. \\n\\nSo on this night, in our 245th year as a nation, I have come to report on the State of the Union.', metadata={'source': '../jupyter/tests/state_of_the_union.txt'}),\n", - " Document(page_content='And my report is this: the State of the Union is strong—because you, the American people, are strong. \\n\\nWe are stronger today than we were a year ago. \\n\\nAnd we will be stronger a year from now than we are today. \\n\\nNow is our moment to meet and overcome the challenges of our time. \\n\\nAnd we will, as one people. \\n\\nOne America. \\n\\nThe United States of America. \\n\\nMay God bless you all. May God protect our troops.', metadata={'source': '../jupyter/tests/state_of_the_union.txt'})]" + "[Document(metadata={'source': '../jupyter/tests/state_of_the_union.txt'}, page_content='Madam Speaker, Madam Vice President, our First Lady and Second Gentleman. Members of Congress and the Cabinet. Justices of the Supreme Court. My fellow Americans. \\n\\nLast year COVID-19 kept us apart. This year we are finally together again. \\n\\nTonight, we meet as Democrats Republicans and Independents. But most importantly as Americans. \\n\\nWith a duty to one another to the American people to the Constitution. \\n\\nAnd with an unwavering resolve that freedom will always triumph over tyranny. \\n\\nSix days ago, Russia’s Vladimir Putin sought to shake the foundations of the free world thinking he could make it bend to his menacing ways. But he badly miscalculated. \\n\\nHe thought he could roll into Ukraine and the world would roll over. Instead he met a wall of strength he never imagined. \\n\\nHe met the Ukrainian people. \\n\\nFrom President Zelenskyy to every Ukrainian, their fearlessness, their courage, their determination, inspires the world.'),\n", + " Document(metadata={'source': '../jupyter/tests/state_of_the_union.txt'}, page_content='Groups of citizens blocking tanks with their bodies. Everyone from students to retirees teachers turned soldiers defending their homeland. \\n\\nIn this struggle as President Zelenskyy said in his speech to the European Parliament “Light will win over darkness.” The Ukrainian Ambassador to the United States is here tonight. \\n\\nLet each of us here tonight in this Chamber send an unmistakable signal to Ukraine and to the world. \\n\\nPlease rise if you are able and show that, Yes, we the United States of America stand with the Ukrainian people. \\n\\nThroughout our history we’ve learned this lesson when dictators do not pay a price for their aggression they cause more chaos. \\n\\nThey keep moving. \\n\\nAnd the costs and the threats to America and the world keep rising. \\n\\nThat’s why the NATO Alliance was created to secure peace and stability in Europe after World War 2. \\n\\nThe United States is a member along with 29 other nations. \\n\\nIt matters. American diplomacy matters. American resolve matters.'),\n", + " Document(metadata={'source': '../jupyter/tests/state_of_the_union.txt'}, page_content='Putin’s latest attack on Ukraine was premeditated and unprovoked. \\n\\nHe rejected repeated efforts at diplomacy. \\n\\nHe thought the West and NATO wouldn’t respond. And he thought he could divide us at home. Putin was wrong. We were ready. Here is what we did. \\n\\nWe prepared extensively and carefully. \\n\\nWe spent months building a coalition of other freedom-loving nations from Europe and the Americas to Asia and Africa to confront Putin. \\n\\nI spent countless hours unifying our European allies. We shared with the world in advance what we knew Putin was planning and precisely how he would try to falsely justify his aggression. \\n\\nWe countered Russia’s lies with truth. \\n\\nAnd now that he has acted the free world is holding him accountable. \\n\\nAlong with twenty-seven members of the European Union including France, Germany, Italy, as well as countries like the United Kingdom, Canada, Japan, Korea, Australia, New Zealand, and many others, even Switzerland.'),\n", + " Document(metadata={'source': '../jupyter/tests/state_of_the_union.txt'}, page_content='We are inflicting pain on Russia and supporting the people of Ukraine. Putin is now isolated from the world more than ever. \\n\\nTogether with our allies –we are right now enforcing powerful economic sanctions. \\n\\nWe are cutting off Russia’s largest banks from the international financial system. \\n\\nPreventing Russia’s central bank from defending the Russian Ruble making Putin’s $630 Billion “war fund” worthless. \\n\\nWe are choking off Russia’s access to technology that will sap its economic strength and weaken its military for years to come. \\n\\nTonight I say to the Russian oligarchs and corrupt leaders who have bilked billions of dollars off this violent regime no more. \\n\\nThe U.S. Department of Justice is assembling a dedicated task force to go after the crimes of Russian oligarchs. \\n\\nWe are joining with our European allies to find and seize your yachts your luxury apartments your private jets. We are coming for your ill-begotten gains.'),\n", + " Document(metadata={'source': '../jupyter/tests/state_of_the_union.txt'}, page_content='And tonight I am announcing that we will join our allies in closing off American air space to all Russian flights – further isolating Russia – and adding an additional squeeze –on their economy. The Ruble has lost 30% of its value. \\n\\nThe Russian stock market has lost 40% of its value and trading remains suspended. Russia’s economy is reeling and Putin alone is to blame. \\n\\nTogether with our allies we are providing support to the Ukrainians in their fight for freedom. Military assistance. Economic assistance. Humanitarian assistance. \\n\\nWe are giving more than $1 Billion in direct assistance to Ukraine. \\n\\nAnd we will continue to aid the Ukrainian people as they defend their country and to help ease their suffering. \\n\\nLet me be clear, our forces are not engaged and will not engage in conflict with Russian forces in Ukraine. \\n\\nOur forces are not going to Europe to fight in Ukraine, but to defend our NATO Allies – in the event that Putin decides to keep moving west.'),\n", + " Document(metadata={'source': '../jupyter/tests/state_of_the_union.txt'}, page_content='For that purpose we’ve mobilized American ground forces, air squadrons, and ship deployments to protect NATO countries including Poland, Romania, Latvia, Lithuania, and Estonia. \\n\\nAs I have made crystal clear the United States and our Allies will defend every inch of territory of NATO countries with the full force of our collective power. \\n\\nAnd we remain clear-eyed. The Ukrainians are fighting back with pure courage. But the next few days weeks, months, will be hard on them. \\n\\nPutin has unleashed violence and chaos. But while he may make gains on the battlefield – he will pay a continuing high price over the long run. \\n\\nAnd a proud Ukrainian people, who have known 30 years of independence, have repeatedly shown that they will not tolerate anyone who tries to take their country backwards. \\n\\nTo all Americans, I will be honest with you, as I’ve always promised. A Russian dictator, invading a foreign country, has costs around the world.'),\n", + " Document(metadata={'source': '../jupyter/tests/state_of_the_union.txt'}, page_content='And I’m taking robust action to make sure the pain of our sanctions is targeted at Russia’s economy. And I will use every tool at our disposal to protect American businesses and consumers. \\n\\nTonight, I can announce that the United States has worked with 30 other countries to release 60 Million barrels of oil from reserves around the world. \\n\\nAmerica will lead that effort, releasing 30 Million barrels from our own Strategic Petroleum Reserve. And we stand ready to do more if necessary, unified with our allies. \\n\\nThese steps will help blunt gas prices here at home. And I know the news about what’s happening can seem alarming. \\n\\nBut I want you to know that we are going to be okay. \\n\\nWhen the history of this era is written Putin’s war on Ukraine will have left Russia weaker and the rest of the world stronger. \\n\\nWhile it shouldn’t have taken something so terrible for people around the world to see what’s at stake now everyone sees it clearly.'),\n", + " Document(metadata={'source': '../jupyter/tests/state_of_the_union.txt'}, page_content='We see the unity among leaders of nations and a more unified Europe a more unified West. And we see unity among the people who are gathering in cities in large crowds around the world even in Russia to demonstrate their support for Ukraine. \\n\\nIn the battle between democracy and autocracy, democracies are rising to the moment, and the world is clearly choosing the side of peace and security. \\n\\nThis is a real test. It’s going to take time. So let us continue to draw inspiration from the iron will of the Ukrainian people. \\n\\nTo our fellow Ukrainian Americans who forge a deep bond that connects our two nations we stand with you. \\n\\nPutin may circle Kyiv with tanks, but he will never gain the hearts and souls of the Ukrainian people. \\n\\nHe will never extinguish their love of freedom. He will never weaken the resolve of the free world. \\n\\nWe meet tonight in an America that has lived through two of the hardest years this nation has ever faced. \\n\\nThe pandemic has been punishing.'),\n", + " Document(metadata={'source': '../jupyter/tests/state_of_the_union.txt'}, page_content='And so many families are living paycheck to paycheck, struggling to keep up with the rising cost of food, gas, housing, and so much more. \\n\\nI understand. \\n\\nI remember when my Dad had to leave our home in Scranton, Pennsylvania to find work. I grew up in a family where if the price of food went up, you felt it. \\n\\nThat’s why one of the first things I did as President was fight to pass the American Rescue Plan. \\n\\nBecause people were hurting. We needed to act, and we did. \\n\\nFew pieces of legislation have done more in a critical moment in our history to lift us out of crisis. \\n\\nIt fueled our efforts to vaccinate the nation and combat COVID-19. It delivered immediate economic relief for tens of millions of Americans. \\n\\nHelped put food on their table, keep a roof over their heads, and cut the cost of health insurance. \\n\\nAnd as my Dad used to say, it gave people a little breathing room.'),\n", + " Document(metadata={'source': '../jupyter/tests/state_of_the_union.txt'}, page_content='And unlike the $2 Trillion tax cut passed in the previous administration that benefitted the top 1% of Americans, the American Rescue Plan helped working people—and left no one behind. \\n\\nAnd it worked. It created jobs. Lots of jobs. \\n\\nIn fact—our economy created over 6.5 Million new jobs just last year, more jobs created in one year \\nthan ever before in the history of America. \\n\\nOur economy grew at a rate of 5.7% last year, the strongest growth in nearly 40 years, the first step in bringing fundamental change to an economy that hasn’t worked for the working people of this nation for too long. \\n\\nFor the past 40 years we were told that if we gave tax breaks to those at the very top, the benefits would trickle down to everyone else. \\n\\nBut that trickle-down theory led to weaker economic growth, lower wages, bigger deficits, and the widest gap between those at the top and everyone else in nearly a century.'),\n", + " Document(metadata={'source': '../jupyter/tests/state_of_the_union.txt'}, page_content='Vice President Harris and I ran for office with a new economic vision for America. \\n\\nInvest in America. Educate Americans. Grow the workforce. Build the economy from the bottom up \\nand the middle out, not from the top down. \\n\\nBecause we know that when the middle class grows, the poor have a ladder up and the wealthy do very well. \\n\\nAmerica used to have the best roads, bridges, and airports on Earth. \\n\\nNow our infrastructure is ranked 13th in the world. \\n\\nWe won’t be able to compete for the jobs of the 21st Century if we don’t fix that. \\n\\nThat’s why it was so important to pass the Bipartisan Infrastructure Law—the most sweeping investment to rebuild America in history. \\n\\nThis was a bipartisan effort, and I want to thank the members of both parties who worked to make it happen. \\n\\nWe’re done talking about infrastructure weeks. \\n\\nWe’re going to have an infrastructure decade.'),\n", + " Document(metadata={'source': '../jupyter/tests/state_of_the_union.txt'}, page_content='It is going to transform America and put us on a path to win the economic competition of the 21st Century that we face with the rest of the world—particularly with China. \\n\\nAs I’ve told Xi Jinping, it is never a good bet to bet against the American people. \\n\\nWe’ll create good jobs for millions of Americans, modernizing roads, airports, ports, and waterways all across America. \\n\\nAnd we’ll do it all to withstand the devastating effects of the climate crisis and promote environmental justice. \\n\\nWe’ll build a national network of 500,000 electric vehicle charging stations, begin to replace poisonous lead pipes—so every child—and every American—has clean water to drink at home and at school, provide affordable high-speed internet for every American—urban, suburban, rural, and tribal communities. \\n\\n4,000 projects have already been announced. \\n\\nAnd tonight, I’m announcing that this year we will start fixing over 65,000 miles of highway and 1,500 bridges in disrepair.'),\n", + " Document(metadata={'source': '../jupyter/tests/state_of_the_union.txt'}, page_content='When we use taxpayer dollars to rebuild America – we are going to Buy American: buy American products to support American jobs. \\n\\nThe federal government spends about $600 Billion a year to keep the country safe and secure. \\n\\nThere’s been a law on the books for almost a century \\nto make sure taxpayers’ dollars support American jobs and businesses. \\n\\nEvery Administration says they’ll do it, but we are actually doing it. \\n\\nWe will buy American to make sure everything from the deck of an aircraft carrier to the steel on highway guardrails are made in America. \\n\\nBut to compete for the best jobs of the future, we also need to level the playing field with China and other competitors. \\n\\nThat’s why it is so important to pass the Bipartisan Innovation Act sitting in Congress that will make record investments in emerging technologies and American manufacturing. \\n\\nLet me give you one example of why it’s so important to pass it.'),\n", + " Document(metadata={'source': '../jupyter/tests/state_of_the_union.txt'}, page_content='If you travel 20 miles east of Columbus, Ohio, you’ll find 1,000 empty acres of land. \\n\\nIt won’t look like much, but if you stop and look closely, you’ll see a “Field of dreams,” the ground on which America’s future will be built. \\n\\nThis is where Intel, the American company that helped build Silicon Valley, is going to build its $20 billion semiconductor “mega site”. \\n\\nUp to eight state-of-the-art factories in one place. 10,000 new good-paying jobs. \\n\\nSome of the most sophisticated manufacturing in the world to make computer chips the size of a fingertip that power the world and our everyday lives. \\n\\nSmartphones. The Internet. Technology we have yet to invent. \\n\\nBut that’s just the beginning. \\n\\nIntel’s CEO, Pat Gelsinger, who is here tonight, told me they are ready to increase their investment from \\n$20 billion to $100 billion. \\n\\nThat would be one of the biggest investments in manufacturing in American history. \\n\\nAnd all they’re waiting for is for you to pass this bill.'),\n", + " Document(metadata={'source': '../jupyter/tests/state_of_the_union.txt'}, page_content='So let’s not wait any longer. Send it to my desk. I’ll sign it. \\n\\nAnd we will really take off. \\n\\nAnd Intel is not alone. \\n\\nThere’s something happening in America. \\n\\nJust look around and you’ll see an amazing story. \\n\\nThe rebirth of the pride that comes from stamping products “Made In America.” The revitalization of American manufacturing. \\n\\nCompanies are choosing to build new factories here, when just a few years ago, they would have built them overseas. \\n\\nThat’s what is happening. Ford is investing $11 billion to build electric vehicles, creating 11,000 jobs across the country. \\n\\nGM is making the largest investment in its history—$7 billion to build electric vehicles, creating 4,000 jobs in Michigan. \\n\\nAll told, we created 369,000 new manufacturing jobs in America just last year. \\n\\nPowered by people I’ve met like JoJo Burgess, from generations of union steelworkers from Pittsburgh, who’s here with us tonight.'),\n", + " Document(metadata={'source': '../jupyter/tests/state_of_the_union.txt'}, page_content='As Ohio Senator Sherrod Brown says, “It’s time to bury the label “Rust Belt.” \\n\\nIt’s time. \\n\\nBut with all the bright spots in our economy, record job growth and higher wages, too many families are struggling to keep up with the bills. \\n\\nInflation is robbing them of the gains they might otherwise feel. \\n\\nI get it. That’s why my top priority is getting prices under control. \\n\\nLook, our economy roared back faster than most predicted, but the pandemic meant that businesses had a hard time hiring enough workers to keep up production in their factories. \\n\\nThe pandemic also disrupted global supply chains. \\n\\nWhen factories close, it takes longer to make goods and get them from the warehouse to the store, and prices go up. \\n\\nLook at cars. \\n\\nLast year, there weren’t enough semiconductors to make all the cars that people wanted to buy. \\n\\nAnd guess what, prices of automobiles went up. \\n\\nSo—we have a choice. \\n\\nOne way to fight inflation is to drive down wages and make Americans poorer.'),\n", + " Document(metadata={'source': '../jupyter/tests/state_of_the_union.txt'}, page_content='I have a better plan to fight inflation. \\n\\nLower your costs, not your wages. \\n\\nMake more cars and semiconductors in America. \\n\\nMore infrastructure and innovation in America. \\n\\nMore goods moving faster and cheaper in America. \\n\\nMore jobs where you can earn a good living in America. \\n\\nAnd instead of relying on foreign supply chains, let’s make it in America. \\n\\nEconomists call it “increasing the productive capacity of our economy.” \\n\\nI call it building a better America. \\n\\nMy plan to fight inflation will lower your costs and lower the deficit. \\n\\n17 Nobel laureates in economics say my plan will ease long-term inflationary pressures. Top business leaders and most Americans support my plan. And here’s the plan: \\n\\nFirst – cut the cost of prescription drugs. Just look at insulin. One in ten Americans has diabetes. In Virginia, I met a 13-year-old boy named Joshua Davis.'),\n", + " Document(metadata={'source': '../jupyter/tests/state_of_the_union.txt'}, page_content='He and his Dad both have Type 1 diabetes, which means they need insulin every day. Insulin costs about $10 a vial to make. \\n\\nBut drug companies charge families like Joshua and his Dad up to 30 times more. I spoke with Joshua’s mom. \\n\\nImagine what it’s like to look at your child who needs insulin and have no idea how you’re going to pay for it. \\n\\nWhat it does to your dignity, your ability to look your child in the eye, to be the parent you expect to be. \\n\\nJoshua is here with us tonight. Yesterday was his birthday. Happy birthday, buddy. \\n\\nFor Joshua, and for the 200,000 other young people with Type 1 diabetes, let’s cap the cost of insulin at $35 a month so everyone can afford it. \\n\\nDrug companies will still do very well. And while we’re at it let Medicare negotiate lower prices for prescription drugs, like the VA already does.'),\n", + " Document(metadata={'source': '../jupyter/tests/state_of_the_union.txt'}, page_content='Look, the American Rescue Plan is helping millions of families on Affordable Care Act plans save $2,400 a year on their health care premiums. Let’s close the coverage gap and make those savings permanent. \\n\\nSecond – cut energy costs for families an average of $500 a year by combatting climate change. \\n\\nLet’s provide investments and tax credits to weatherize your homes and businesses to be energy efficient and you get a tax credit; double America’s clean energy production in solar, wind, and so much more; lower the price of electric vehicles, saving you another $80 a month because you’ll never have to pay at the gas pump again. \\n\\nThird – cut the cost of child care. Many families pay up to $14,000 a year for child care per child. \\n\\nMiddle-class and working families shouldn’t have to pay more than 7% of their income for care of young children.'),\n", + " Document(metadata={'source': '../jupyter/tests/state_of_the_union.txt'}, page_content='My plan will cut the cost in half for most families and help parents, including millions of women, who left the workforce during the pandemic because they couldn’t afford child care, to be able to get back to work. \\n\\nMy plan doesn’t stop there. It also includes home and long-term care. More affordable housing. And Pre-K for every 3- and 4-year-old. \\n\\nAll of these will lower costs. \\n\\nAnd under my plan, nobody earning less than $400,000 a year will pay an additional penny in new taxes. Nobody. \\n\\nThe one thing all Americans agree on is that the tax system is not fair. We have to fix it. \\n\\nI’m not looking to punish anyone. But let’s make sure corporations and the wealthiest Americans start paying their fair share. \\n\\nJust last year, 55 Fortune 500 corporations earned $40 billion in profits and paid zero dollars in federal income tax. \\n\\nThat’s simply not fair. That’s why I’ve proposed a 15% minimum tax rate for corporations.'),\n", + " Document(metadata={'source': '../jupyter/tests/state_of_the_union.txt'}, page_content='We got more than 130 countries to agree on a global minimum tax rate so companies can’t get out of paying their taxes at home by shipping jobs and factories overseas. \\n\\nThat’s why I’ve proposed closing loopholes so the very wealthy don’t pay a lower tax rate than a teacher or a firefighter. \\n\\nSo that’s my plan. It will grow the economy and lower costs for families. \\n\\nSo what are we waiting for? Let’s get this done. And while you’re at it, confirm my nominees to the Federal Reserve, which plays a critical role in fighting inflation. \\n\\nMy plan will not only lower costs to give families a fair shot, it will lower the deficit. \\n\\nThe previous Administration not only ballooned the deficit with tax cuts for the very wealthy and corporations, it undermined the watchdogs whose job was to keep pandemic relief funds from being wasted. \\n\\nBut in my administration, the watchdogs have been welcomed back.'),\n", + " Document(metadata={'source': '../jupyter/tests/state_of_the_union.txt'}, page_content='We’re going after the criminals who stole billions in relief money meant for small businesses and millions of Americans. \\n\\nAnd tonight, I’m announcing that the Justice Department will name a chief prosecutor for pandemic fraud. \\n\\nBy the end of this year, the deficit will be down to less than half what it was before I took office. \\n\\nThe only president ever to cut the deficit by more than one trillion dollars in a single year. \\n\\nLowering your costs also means demanding more competition. \\n\\nI’m a capitalist, but capitalism without competition isn’t capitalism. \\n\\nIt’s exploitation—and it drives up prices. \\n\\nWhen corporations don’t have to compete, their profits go up, your prices go up, and small businesses and family farmers and ranchers go under. \\n\\nWe see it happening with ocean carriers moving goods in and out of America. \\n\\nDuring the pandemic, these foreign-owned companies raised prices by as much as 1,000% and made record profits.'),\n", + " Document(metadata={'source': '../jupyter/tests/state_of_the_union.txt'}, page_content='Tonight, I’m announcing a crackdown on these companies overcharging American businesses and consumers. \\n\\nAnd as Wall Street firms take over more nursing homes, quality in those homes has gone down and costs have gone up. \\n\\nThat ends on my watch. \\n\\nMedicare is going to set higher standards for nursing homes and make sure your loved ones get the care they deserve and expect. \\n\\nWe’ll also cut costs and keep the economy going strong by giving workers a fair shot, provide more training and apprenticeships, hire them based on their skills not degrees. \\n\\nLet’s pass the Paycheck Fairness Act and paid leave. \\n\\nRaise the minimum wage to $15 an hour and extend the Child Tax Credit, so no one has to raise a family in poverty. \\n\\nLet’s increase Pell Grants and increase our historic support of HBCUs, and invest in what Jill—our First Lady who teaches full-time—calls America’s best-kept secret: community colleges.'),\n", + " Document(metadata={'source': '../jupyter/tests/state_of_the_union.txt'}, page_content='And let’s pass the PRO Act when a majority of workers want to form a union—they shouldn’t be stopped. \\n\\nWhen we invest in our workers, when we build the economy from the bottom up and the middle out together, we can do something we haven’t done in a long time: build a better America. \\n\\nFor more than two years, COVID-19 has impacted every decision in our lives and the life of the nation. \\n\\nAnd I know you’re tired, frustrated, and exhausted. \\n\\nBut I also know this. \\n\\nBecause of the progress we’ve made, because of your resilience and the tools we have, tonight I can say \\nwe are moving forward safely, back to more normal routines. \\n\\nWe’ve reached a new moment in the fight against COVID-19, with severe cases down to a level not seen since last July. \\n\\nJust a few days ago, the Centers for Disease Control and Prevention—the CDC—issued new mask guidelines. \\n\\nUnder these new guidelines, most Americans in most of the country can now be mask free.'),\n", + " Document(metadata={'source': '../jupyter/tests/state_of_the_union.txt'}, page_content='And based on the projections, more of the country will reach that point across the next couple of weeks. \\n\\nThanks to the progress we have made this past year, COVID-19 need no longer control our lives. \\n\\nI know some are talking about “living with COVID-19”. Tonight – I say that we will never just accept living with COVID-19. \\n\\nWe will continue to combat the virus as we do other diseases. And because this is a virus that mutates and spreads, we will stay on guard. \\n\\nHere are four common sense steps as we move forward safely. \\n\\nFirst, stay protected with vaccines and treatments. We know how incredibly effective vaccines are. If you’re vaccinated and boosted you have the highest degree of protection. \\n\\nWe will never give up on vaccinating more Americans. Now, I know parents with kids under 5 are eager to see a vaccine authorized for their children. \\n\\nThe scientists are working hard to get that done and we’ll be ready with plenty of vaccines when they do.'),\n", + " Document(metadata={'source': '../jupyter/tests/state_of_the_union.txt'}, page_content='We’re also ready with anti-viral treatments. If you get COVID-19, the Pfizer pill reduces your chances of ending up in the hospital by 90%. \\n\\nWe’ve ordered more of these pills than anyone in the world. And Pfizer is working overtime to get us 1 Million pills this month and more than double that next month. \\n\\nAnd we’re launching the “Test to Treat” initiative so people can get tested at a pharmacy, and if they’re positive, receive antiviral pills on the spot at no cost. \\n\\nIf you’re immunocompromised or have some other vulnerability, we have treatments and free high-quality masks. \\n\\nWe’re leaving no one behind or ignoring anyone’s needs as we move forward. \\n\\nAnd on testing, we have made hundreds of millions of tests available for you to order for free. \\n\\nEven if you already ordered free tests tonight, I am announcing that you can order more from covidtests.gov starting next week.'),\n", + " Document(metadata={'source': '../jupyter/tests/state_of_the_union.txt'}, page_content='Second – we must prepare for new variants. Over the past year, we’ve gotten much better at detecting new variants. \\n\\nIf necessary, we’ll be able to deploy new vaccines within 100 days instead of many more months or years. \\n\\nAnd, if Congress provides the funds we need, we’ll have new stockpiles of tests, masks, and pills ready if needed. \\n\\nI cannot promise a new variant won’t come. But I can promise you we’ll do everything within our power to be ready if it does. \\n\\nThird – we can end the shutdown of schools and businesses. We have the tools we need. \\n\\nIt’s time for Americans to get back to work and fill our great downtowns again. People working from home can feel safe to begin to return to the office. \\n\\nWe’re doing that here in the federal government. The vast majority of federal workers will once again work in person. \\n\\nOur schools are open. Let’s keep it that way. Our kids need to be in school.'),\n", + " Document(metadata={'source': '../jupyter/tests/state_of_the_union.txt'}, page_content='And with 75% of adult Americans fully vaccinated and hospitalizations down by 77%, most Americans can remove their masks, return to work, stay in the classroom, and move forward safely. \\n\\nWe achieved this because we provided free vaccines, treatments, tests, and masks. \\n\\nOf course, continuing this costs money. \\n\\nI will soon send Congress a request. \\n\\nThe vast majority of Americans have used these tools and may want to again, so I expect Congress to pass it quickly. \\n\\nFourth, we will continue vaccinating the world. \\n\\nWe’ve sent 475 Million vaccine doses to 112 countries, more than any other nation. \\n\\nAnd we won’t stop. \\n\\nWe have lost so much to COVID-19. Time with one another. And worst of all, so much loss of life. \\n\\nLet’s use this moment to reset. Let’s stop looking at COVID-19 as a partisan dividing line and see it for what it is: A God-awful disease. \\n\\nLet’s stop seeing each other as enemies, and start seeing each other for who we really are: Fellow Americans.'),\n", + " Document(metadata={'source': '../jupyter/tests/state_of_the_union.txt'}, page_content='We can’t change how divided we’ve been. But we can change how we move forward—on COVID-19 and other issues we must face together. \\n\\nI recently visited the New York City Police Department days after the funerals of Officer Wilbert Mora and his partner, Officer Jason Rivera. \\n\\nThey were responding to a 9-1-1 call when a man shot and killed them with a stolen gun. \\n\\nOfficer Mora was 27 years old. \\n\\nOfficer Rivera was 22. \\n\\nBoth Dominican Americans who’d grown up on the same streets they later chose to patrol as police officers. \\n\\nI spoke with their families and told them that we are forever in debt for their sacrifice, and we will carry on their mission to restore the trust and safety every community deserves. \\n\\nI’ve worked on these issues a long time. \\n\\nI know what works: Investing in crime preventionand community police officers who’ll walk the beat, who’ll know the neighborhood, and who can restore trust and safety.'),\n", + " Document(metadata={'source': '../jupyter/tests/state_of_the_union.txt'}, page_content='So let’s not abandon our streets. Or choose between safety and equal justice. \\n\\nLet’s come together to protect our communities, restore trust, and hold law enforcement accountable. \\n\\nThat’s why the Justice Department required body cameras, banned chokeholds, and restricted no-knock warrants for its officers. \\n\\nThat’s why the American Rescue Plan provided $350 Billion that cities, states, and counties can use to hire more police and invest in proven strategies like community violence interruption—trusted messengers breaking the cycle of violence and trauma and giving young people hope. \\n\\nWe should all agree: The answer is not to Defund the police. The answer is to FUND the police with the resources and training they need to protect our communities. \\n\\nI ask Democrats and Republicans alike: Pass my budget and keep our neighborhoods safe.'),\n", + " Document(metadata={'source': '../jupyter/tests/state_of_the_union.txt'}, page_content='And I will keep doing everything in my power to crack down on gun trafficking and ghost guns you can buy online and make at home—they have no serial numbers and can’t be traced. \\n\\nAnd I ask Congress to pass proven measures to reduce gun violence. Pass universal background checks. Why should anyone on a terrorist list be able to purchase a weapon? \\n\\nBan assault weapons and high-capacity magazines. \\n\\nRepeal the liability shield that makes gun manufacturers the only industry in America that can’t be sued. \\n\\nThese laws don’t infringe on the Second Amendment. They save lives. \\n\\nThe most fundamental right in America is the right to vote – and to have it counted. And it’s under assault. \\n\\nIn state after state, new laws have been passed, not only to suppress the vote, but to subvert entire elections. \\n\\nWe cannot let this happen.'),\n", + " Document(metadata={'source': '../jupyter/tests/state_of_the_union.txt'}, page_content='Tonight. I call on the Senate to: Pass the Freedom to Vote Act. Pass the John Lewis Voting Rights Act. And while you’re at it, pass the Disclose Act so Americans can know who is funding our elections. \\n\\nTonight, I’d like to honor someone who has dedicated his life to serve this country: Justice Stephen Breyer—an Army veteran, Constitutional scholar, and retiring Justice of the United States Supreme Court. Justice Breyer, thank you for your service. \\n\\nOne of the most serious constitutional responsibilities a President has is nominating someone to serve on the United States Supreme Court. \\n\\nAnd I did that 4 days ago, when I nominated Circuit Court of Appeals Judge Ketanji Brown Jackson. One of our nation’s top legal minds, who will continue Justice Breyer’s legacy of excellence.'),\n", + " Document(metadata={'source': '../jupyter/tests/state_of_the_union.txt'}, page_content='A former top litigator in private practice. A former federal public defender. And from a family of public school educators and police officers. A consensus builder. Since she’s been nominated, she’s received a broad range of support—from the Fraternal Order of Police to former judges appointed by Democrats and Republicans. \\n\\nAnd if we are to advance liberty and justice, we need to secure the Border and fix the immigration system. \\n\\nWe can do both. At our border, we’ve installed new technology like cutting-edge scanners to better detect drug smuggling. \\n\\nWe’ve set up joint patrols with Mexico and Guatemala to catch more human traffickers. \\n\\nWe’re putting in place dedicated immigration judges so families fleeing persecution and violence can have their cases heard faster. \\n\\nWe’re securing commitments and supporting partners in South and Central America to host more refugees and secure their own borders.'),\n", + " Document(metadata={'source': '../jupyter/tests/state_of_the_union.txt'}, page_content='We can do all this while keeping lit the torch of liberty that has led generations of immigrants to this land—my forefathers and so many of yours. \\n\\nProvide a pathway to citizenship for Dreamers, those on temporary status, farm workers, and essential workers. \\n\\nRevise our laws so businesses have the workers they need and families don’t wait decades to reunite. \\n\\nIt’s not only the right thing to do—it’s the economically smart thing to do. \\n\\nThat’s why immigration reform is supported by everyone from labor unions to religious leaders to the U.S. Chamber of Commerce. \\n\\nLet’s get it done once and for all. \\n\\nAdvancing liberty and justice also requires protecting the rights of women. \\n\\nThe constitutional right affirmed in Roe v. Wade—standing precedent for half a century—is under attack as never before. \\n\\nIf we want to go forward—not backward—we must protect access to health care. Preserve a woman’s right to choose. And let’s continue to advance maternal health care in America.'),\n", + " Document(metadata={'source': '../jupyter/tests/state_of_the_union.txt'}, page_content='And for our LGBTQ+ Americans, let’s finally get the bipartisan Equality Act to my desk. The onslaught of state laws targeting transgender Americans and their families is wrong. \\n\\nAs I said last year, especially to our younger transgender Americans, I will always have your back as your President, so you can be yourself and reach your God-given potential. \\n\\nWhile it often appears that we never agree, that isn’t true. I signed 80 bipartisan bills into law last year. From preventing government shutdowns to protecting Asian-Americans from still-too-common hate crimes to reforming military justice. \\n\\nAnd soon, we’ll strengthen the Violence Against Women Act that I first wrote three decades ago. It is important for us to show the nation that we can come together and do big things. \\n\\nSo tonight I’m offering a Unity Agenda for the Nation. Four big things we can do together. \\n\\nFirst, beat the opioid epidemic.'),\n", + " Document(metadata={'source': '../jupyter/tests/state_of_the_union.txt'}, page_content='There is so much we can do. Increase funding for prevention, treatment, harm reduction, and recovery. \\n\\nGet rid of outdated rules that stop doctors from prescribing treatments. And stop the flow of illicit drugs by working with state and local law enforcement to go after traffickers. \\n\\nIf you’re suffering from addiction, know you are not alone. I believe in recovery, and I celebrate the 23 million Americans in recovery. \\n\\nSecond, let’s take on mental health. Especially among our children, whose lives and education have been turned upside down. \\n\\nThe American Rescue Plan gave schools money to hire teachers and help students make up for lost learning. \\n\\nI urge every parent to make sure your school does just that. And we can all play a part—sign up to be a tutor or a mentor. \\n\\nChildren were also struggling before the pandemic. Bullying, violence, trauma, and the harms of social media.'),\n", + " Document(metadata={'source': '../jupyter/tests/state_of_the_union.txt'}, page_content='As Frances Haugen, who is here with us tonight, has shown, we must hold social media platforms accountable for the national experiment they’re conducting on our children for profit. \\n\\nIt’s time to strengthen privacy protections, ban targeted advertising to children, demand tech companies stop collecting personal data on our children. \\n\\nAnd let’s get all Americans the mental health services they need. More people they can turn to for help, and full parity between physical and mental health care. \\n\\nThird, support our veterans. \\n\\nVeterans are the best of us. \\n\\nI’ve always believed that we have a sacred obligation to equip all those we send to war and care for them and their families when they come home. \\n\\nMy administration is providing assistance with job training and housing, and now helping lower-income veterans get VA care debt-free. \\n\\nOur troops in Iraq and Afghanistan faced many dangers.'),\n", + " Document(metadata={'source': '../jupyter/tests/state_of_the_union.txt'}, page_content='One was stationed at bases and breathing in toxic smoke from “burn pits” that incinerated wastes of war—medical and hazard material, jet fuel, and more. \\n\\nWhen they came home, many of the world’s fittest and best trained warriors were never the same. \\n\\nHeadaches. Numbness. Dizziness. \\n\\nA cancer that would put them in a flag-draped coffin. \\n\\nI know. \\n\\nOne of those soldiers was my son Major Beau Biden. \\n\\nWe don’t know for sure if a burn pit was the cause of his brain cancer, or the diseases of so many of our troops. \\n\\nBut I’m committed to finding out everything we can. \\n\\nCommitted to military families like Danielle Robinson from Ohio. \\n\\nThe widow of Sergeant First Class Heath Robinson. \\n\\nHe was born a soldier. Army National Guard. Combat medic in Kosovo and Iraq. \\n\\nStationed near Baghdad, just yards from burn pits the size of football fields. \\n\\nHeath’s widow Danielle is here with us tonight. They loved going to Ohio State football games. He loved building Legos with their daughter.'),\n", + " Document(metadata={'source': '../jupyter/tests/state_of_the_union.txt'}, page_content='But cancer from prolonged exposure to burn pits ravaged Heath’s lungs and body. \\n\\nDanielle says Heath was a fighter to the very end. \\n\\nHe didn’t know how to stop fighting, and neither did she. \\n\\nThrough her pain she found purpose to demand we do better. \\n\\nTonight, Danielle—we are. \\n\\nThe VA is pioneering new ways of linking toxic exposures to diseases, already helping more veterans get benefits. \\n\\nAnd tonight, I’m announcing we’re expanding eligibility to veterans suffering from nine respiratory cancers. \\n\\nI’m also calling on Congress: pass a law to make sure veterans devastated by toxic exposures in Iraq and Afghanistan finally get the benefits and comprehensive health care they deserve. \\n\\nAnd fourth, let’s end cancer as we know it. \\n\\nThis is personal to me and Jill, to Kamala, and to so many of you. \\n\\nCancer is the #2 cause of death in America–second only to heart disease.'),\n", + " Document(metadata={'source': '../jupyter/tests/state_of_the_union.txt'}, page_content='Last month, I announced our plan to supercharge \\nthe Cancer Moonshot that President Obama asked me to lead six years ago. \\n\\nOur goal is to cut the cancer death rate by at least 50% over the next 25 years, turn more cancers from death sentences into treatable diseases. \\n\\nMore support for patients and families. \\n\\nTo get there, I call on Congress to fund ARPA-H, the Advanced Research Projects Agency for Health. \\n\\nIt’s based on DARPA—the Defense Department project that led to the Internet, GPS, and so much more. \\n\\nARPA-H will have a singular purpose—to drive breakthroughs in cancer, Alzheimer’s, diabetes, and more. \\n\\nA unity agenda for the nation. \\n\\nWe can do this. \\n\\nMy fellow Americans—tonight , we have gathered in a sacred space—the citadel of our democracy. \\n\\nIn this Capitol, generation after generation, Americans have debated great questions amid great strife, and have done great things. \\n\\nWe have fought for freedom, expanded liberty, defeated totalitarianism and terror.'),\n", + " Document(metadata={'source': '../jupyter/tests/state_of_the_union.txt'}, page_content='And built the strongest, freest, and most prosperous nation the world has ever known. \\n\\nNow is the hour. \\n\\nOur moment of responsibility. \\n\\nOur test of resolve and conscience, of history itself. \\n\\nIt is in this moment that our character is formed. Our purpose is found. Our future is forged. \\n\\nWell I know this nation. \\n\\nWe will meet the test. \\n\\nTo protect freedom and liberty, to expand fairness and opportunity. \\n\\nWe will save democracy. \\n\\nAs hard as these times have been, I am more optimistic about America today than I have been my whole life. \\n\\nBecause I see the future that is within our grasp. \\n\\nBecause I know there is simply nothing beyond our capacity. \\n\\nWe are the only nation on Earth that has always turned every crisis we have faced into an opportunity. \\n\\nThe only nation that can be defined by a single word: possibilities. \\n\\nSo on this night, in our 245th year as a nation, I have come to report on the State of the Union.'),\n", + " Document(metadata={'source': '../jupyter/tests/state_of_the_union.txt'}, page_content='And my report is this: the State of the Union is strong—because you, the American people, are strong. \\n\\nWe are stronger today than we were a year ago. \\n\\nAnd we will be stronger a year from now than we are today. \\n\\nNow is our moment to meet and overcome the challenges of our time. \\n\\nAnd we will, as one people. \\n\\nOne America. \\n\\nThe United States of America. \\n\\nMay God bless you all. May God protect our troops.')]" ] }, - "execution_count": 9, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } @@ -147,7 +145,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 7, "id": "4f755948-f125-44c8-8505-0ca0759c15ff", "metadata": {}, "outputs": [], @@ -158,7 +156,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 8, "id": "8bcd5edb-c085-4a6f-8f50-0885a6d2f15b", "metadata": {}, "outputs": [], @@ -169,7 +167,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 9, "id": "c227bec9-fbe0-46a5-8a86-7bfaf6fe5882", "metadata": {}, "outputs": [], @@ -188,7 +186,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 10, "id": "8fbbbf2e-0ff8-49d9-a378-09e2a0443a77", "metadata": {}, "outputs": [], @@ -199,14 +197,9 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 11, "id": "918221f6-9687-4b04-a6b4-20527b111023", - "metadata": { - "collapsed": true, - "jupyter": { - "outputs_hidden": true - } - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -237,7 +230,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 12, "id": "44f4df2f-ed07-4322-9cfc-7044fc18ed1a", "metadata": {}, "outputs": [], @@ -263,17 +256,22 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 13, "id": "2dd3c237-3b9e-4439-966f-a34270d6471a", "metadata": {}, "outputs": [], "source": [ - "new_db = FAISS.load_local(\"faiss_index\", embeddings)" + "# 旧代码\n", + "# new_db = FAISS.load_local(\"faiss_index\", embeddings)\n", + "\n", + "# 新代码\n", + "# 加载本地FAISS索引\n", + "new_db = FAISS.load_local(\"faiss_index\", embeddings, allow_dangerous_deserialization=True)" ] }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 14, "id": "8c81f9f3-1650-4737-adec-d09380f1b8d9", "metadata": {}, "outputs": [], @@ -283,7 +281,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 15, "id": "0524202a-199c-4284-81d7-c6febf2b584e", "metadata": {}, "outputs": [ diff --git a/langchain/sales_chatbot/sales.ipynb b/langchain/sales_chatbot/sales.ipynb index d1a3bea2..a0c8c916 100644 --- a/langchain/sales_chatbot/sales.ipynb +++ b/langchain/sales_chatbot/sales.ipynb @@ -89,18 +89,14 @@ "metadata": {}, "outputs": [], "source": [ - "with open(\"real_estate_sales_data.txt\") as f:\n", + "with open(\"real_estate_sales_data.txt\", encoding='utf-8') as f:\n", " real_estate_sales = f.read()" ] }, { "cell_type": "markdown", "id": "a9119556-d2e3-4edf-be16-15837da156f1", - "metadata": { - "jupyter": { - "source_hidden": true - } - }, + "metadata": {}, "source": [ "### 使用 CharacterTextSplitter 来进行文本分割\n", "\n", @@ -180,7 +176,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 6, "id": "73b2d47a-27ae-4cd4-a72a-3809b4c22bff", "metadata": {}, "outputs": [ @@ -190,7 +186,7 @@ "70" ] }, - "execution_count": 7, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } @@ -209,12 +205,13 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 7, "id": "508c2ab2-e187-424f-a43c-ca3d3b1a0550", "metadata": {}, "outputs": [], "source": [ - "from langchain.embeddings.openai import OpenAIEmbeddings\n", + "# from langchain.embeddings.openai import OpenAIEmbeddings\n", + "from langchain_openai import OpenAIEmbeddings\n", "from langchain.text_splitter import CharacterTextSplitter\n", "from langchain.vectorstores import FAISS\n", "\n", @@ -223,7 +220,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 8, "id": "250e0873-95e2-4372-98a5-68c0feb304bb", "metadata": {}, "outputs": [], @@ -233,7 +230,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 9, "id": "0d18fcc6-c2be-434b-b8de-9648ac6f83f4", "metadata": {}, "outputs": [], @@ -243,7 +240,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 10, "id": "e689667e-7a45-40d6-9eae-4e52cbc7daab", "metadata": {}, "outputs": [ @@ -273,7 +270,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 11, "id": "a6cc47bf-1566-472f-84d2-a46bd634907c", "metadata": {}, "outputs": [], @@ -293,7 +290,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 12, "id": "17f051c9-8676-48d1-a9a4-e69b52630faf", "metadata": {}, "outputs": [], @@ -304,17 +301,17 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 13, "id": "e33024db-ca7b-4d68-9b0e-c31c15ded57d", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "VectorStoreRetriever(tags=['FAISS'], vectorstore=, search_kwargs={'k': 3})" + "VectorStoreRetriever(tags=['FAISS', 'OpenAIEmbeddings'], vectorstore=, search_kwargs={'k': 3})" ] }, - "execution_count": 14, + "execution_count": 13, "metadata": {}, "output_type": "execute_result" } @@ -325,7 +322,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 14, "id": "7efb1414-859f-4818-bacd-e1e2edf34b95", "metadata": {}, "outputs": [ @@ -346,24 +343,25 @@ } ], "source": [ - "docs = topK_retriever.get_relevant_documents(query)\n", + "# docs = topK_retriever.get_relevant_documents(query)\n", + "docs = topK_retriever.invoke(query)\n", "for doc in docs:\n", " print(doc.page_content + \"\\n\")" ] }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 15, "id": "a3c4b62d-6f8f-461b-a4fb-41c8a404b831", "metadata": {}, "outputs": [], "source": [ - "docs = topK_retriever.get_relevant_documents(\"你们有没有1000万的豪宅啊?\")" + "docs = topK_retriever.invoke(\"你们有没有1000万的豪宅啊?\")" ] }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 16, "id": "04cca3d7-23d9-491f-8350-faeb19861dec", "metadata": {}, "outputs": [ @@ -374,11 +372,11 @@ "[客户问题] 你们会提供家具吗?\n", "[销售回答] 我们的精装房会提供基础家具和家电,让您拎包入住。\n", "\n", - "[客户问题] 我不想要一楼的房子。\n", - "[销售回答] 我理解您的顾虑,我们还有多个楼层的房源可以选择。\n", - "\n", "[客户问题] 都有哪些户型?\n", "[销售回答] 我们有从一室到四室不等的多种户型,定能满足您不同的居住需求。\n", + "\n", + "[客户问题] 我不想要一楼的房子。\n", + "[销售回答] 我理解您的顾虑,我们还有多个楼层的房源可以选择。\n", "\n" ] } @@ -398,7 +396,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 17, "id": "b1298956-6cf3-4a68-a3c2-a3149f64f156", "metadata": {}, "outputs": [], @@ -412,7 +410,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 18, "id": "d61167de-72ed-4618-a2e1-5df04784a3bc", "metadata": {}, "outputs": [ @@ -427,7 +425,7 @@ } ], "source": [ - "docs = retriever.get_relevant_documents(query)\n", + "docs = retriever.invoke(query)\n", "for doc in docs:\n", " print(doc.page_content + \"\\n\")" ] @@ -450,17 +448,17 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 19, "id": "25768463-da65-4762-978d-51c0c3a9c24b", "metadata": {}, "outputs": [], "source": [ - "docs = retriever.get_relevant_documents(query)" + "docs = retriever.invoke(query)" ] }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 20, "id": "4838d3da-dca3-4c31-80da-cec75760a833", "metadata": {}, "outputs": [ @@ -470,7 +468,7 @@ "'[客户问题] 我担心楼下太吵。\\n[销售回答] 这个小区特别注重居住体验,我们有良好的隔音设计,并且小区内部规划了绿化区域,可以有效降低噪音。'" ] }, - "execution_count": 21, + "execution_count": 20, "metadata": {}, "output_type": "execute_result" } @@ -481,7 +479,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 21, "id": "1ba30232-f468-4102-b70c-02c8b74da43d", "metadata": {}, "outputs": [ @@ -491,7 +489,7 @@ "['[客户问题] 我担心楼下太吵。\\n', '这个小区特别注重居住体验,我们有良好的隔音设计,并且小区内部规划了绿化区域,可以有效降低噪音。']" ] }, - "execution_count": 22, + "execution_count": 21, "metadata": {}, "output_type": "execute_result" } @@ -502,7 +500,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 22, "id": "bda8eb0c-eb1f-47b2-91ab-4c94ff71c3db", "metadata": {}, "outputs": [], @@ -512,7 +510,7 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 23, "id": "917a3b6c-3149-42e2-b7b6-abebd94b7f72", "metadata": {}, "outputs": [ @@ -522,7 +520,7 @@ "'这个小区特别注重居住体验,我们有良好的隔音设计,并且小区内部规划了绿化区域,可以有效降低噪音。'" ] }, - "execution_count": 24, + "execution_count": 23, "metadata": {}, "output_type": "execute_result" } @@ -541,7 +539,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 24, "id": "c311a656-e571-45d6-8690-88e4be2c2a65", "metadata": {}, "outputs": [], @@ -550,7 +548,7 @@ "\n", "def sales(query: str, score_threshold: float=0.8) -> List[str]:\n", " retriever = db.as_retriever(search_type=\"similarity_score_threshold\", search_kwargs={\"score_threshold\": score_threshold}) \n", - " docs = retriever.get_relevant_documents(query)\n", + " docs = retriever.invoke(query)\n", " ans_list = [doc.page_content.split(\"[销售回答] \")[-1] for doc in docs]\n", "\n", " return ans_list" @@ -558,7 +556,7 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 25, "id": "2f4c6c08-b97c-4727-9aa1-a474d85a11e4", "metadata": {}, "outputs": [ @@ -573,7 +571,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "/root/miniconda3/envs/langchain/lib/python3.10/site-packages/langchain/schema/vectorstore.py:287: UserWarning: No relevant docs were retrieved using the relevance score threshold 0.8\n", + "C:\\Users\\lenovo\\AppData\\Roaming\\Python\\Python310\\site-packages\\langchain_core\\vectorstores\\base.py:796: UserWarning: No relevant docs were retrieved using the relevance score threshold 0.8\n", " warnings.warn(\n" ] } @@ -586,7 +584,7 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 26, "id": "11e3d8b6-839f-4b2f-b519-841e0271f95b", "metadata": {}, "outputs": [ @@ -604,17 +602,23 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 27, "id": "fc5b030a-ae6f-4d42-9577-1420c78aecb1", "metadata": {}, "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "C:\\Users\\lenovo\\AppData\\Roaming\\Python\\Python310\\site-packages\\langchain_core\\vectorstores\\base.py:796: UserWarning: No relevant docs were retrieved using the relevance score threshold 0.8\n", + " warnings.warn(\n" + ] + }, { "name": "stdout", "output_type": "stream", "text": [ "score:0.8 ans: []\n", - "\n", - "score:0.75 ans: []\n", "\n" ] }, @@ -622,7 +626,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "/root/miniconda3/envs/langchain/lib/python3.10/site-packages/langchain/schema/vectorstore.py:287: UserWarning: No relevant docs were retrieved using the relevance score threshold 0.75\n", + "C:\\Users\\lenovo\\AppData\\Roaming\\Python\\Python310\\site-packages\\langchain_core\\vectorstores\\base.py:796: UserWarning: No relevant docs were retrieved using the relevance score threshold 0.75\n", " warnings.warn(\n" ] }, @@ -630,6 +634,8 @@ "name": "stdout", "output_type": "stream", "text": [ + "score:0.75 ans: []\n", + "\n", "score:0.5 ans: ['我们有不同户型和付款方案,一定有适合您预算的。', '我们的房子位于黄金地段,升值潜力很大,转卖起来不会有问题。', '定金金额取决于您选择的房型和付款方式,我们可以详细为您解释。', '这个区域正在快速发展,未来的升值潜力非常大。']\n", "\n" ] @@ -653,7 +659,7 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 28, "id": "9142feb4-980a-4142-b367-1401021dceef", "metadata": {}, "outputs": [], @@ -669,29 +675,37 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 29, "id": "d281b560-54bb-4a25-a1dc-b23874361654", "metadata": {}, "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "C:\\Users\\lenovo\\AppData\\Roaming\\Python\\Python310\\site-packages\\langchain_core\\vectorstores\\base.py:796: UserWarning: No relevant docs were retrieved using the relevance score threshold 0.8\n", + " warnings.warn(\n" + ] + }, { "data": { "text/plain": [ "{'query': '你们小区有200万的房子吗?',\n", - " 'result': '对不起,我无法回答这个问题,因为我是一个人工智能,没有实时的房地产信息。建议你直接联系房地产经纪人或者查阅相关房地产网站获取信息。'}" + " 'result': \"I'm sorry, but as an AI language model, I don't have access to real estate listings or the ability to determine the availability of housing in specific areas or communities. For information on available properties and their prices, you would need to consult a real estate agent or look at real estate websites that serve the area you are interested in.\"}" ] }, - "execution_count": 31, + "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "qa_chain({\"query\": \"你们小区有200万的房子吗?\"})" + "qa_chain.invoke({\"query\": \"你们小区有200万的房子吗?\"})" ] }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 30, "id": "c6a30dcc-fa6b-4282-935c-b07902746e19", "metadata": {}, "outputs": [ @@ -699,21 +713,21 @@ "data": { "text/plain": [ "{'query': '小区吵不吵',\n", - " 'result': '这个小区特别注重居住体验,有良好的隔音设计,并且小区内部规划了绿化区域,可以有效降低噪音。所以,小区应该不会太吵。'}" + " 'result': '根据销售回答的信息,这个小区特别注重居住体验,拥有良好的隔音设计,并且规划了绿化区域来降低噪音,因此应该不会太吵。'}" ] }, - "execution_count": 32, + "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "qa_chain({\"query\": \"小区吵不吵\"})" + "qa_chain.invoke({\"query\": \"小区吵不吵\"})" ] }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 31, "id": "9da44bd6-02ef-4fb6-8e9e-7c99aeba483a", "metadata": {}, "outputs": [ @@ -747,7 +761,7 @@ }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 32, "id": "913edd04-37ea-4c3f-9346-086aeb0ab447", "metadata": {}, "outputs": [], @@ -755,18 +769,21 @@ "from langchain_openai import OpenAIEmbeddings\n", "from langchain.vectorstores import FAISS\n", "\n", - "db = FAISS.load_local(\"real_estates_sale\", OpenAIEmbeddings())" + "# db = FAISS.load_local(\"real_estates_sale\", OpenAIEmbeddings())\n", + "# 加载本地FAISS索引,并允许危险的反序列化操作\n", + "db = FAISS.load_local(\"real_estates_sale\", OpenAIEmbeddings(), allow_dangerous_deserialization=True)" ] }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 33, "id": "77d8eee4-6383-4b4a-9737-95ea9fc53b87", "metadata": {}, "outputs": [], "source": [ "from langchain.chains import RetrievalQA\n", - "from langchain.chat_models import ChatOpenAI\n", + "# from langchain.chat_models import ChatOpenAI\n", + "from langchain_openai import ChatOpenAI\n", "\n", "llm = ChatOpenAI(model_name=\"gpt-4\", temperature=0.5)\n", "qa_chain = RetrievalQA.from_chain_type(llm,\n", @@ -776,29 +793,36 @@ }, { "cell_type": "code", - "execution_count": 36, + "execution_count": 34, "id": "5dfac197-cadb-47d7-8cbe-1b07a83fc8e1", "metadata": {}, "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "C:\\Users\\lenovo\\AppData\\Roaming\\Python\\Python310\\site-packages\\langchain_core\\vectorstores\\base.py:796: UserWarning: No relevant docs were retrieved using the relevance score threshold 0.8\n", + " warnings.warn(\n" + ] + }, { "data": { "text/plain": [ - "{'query': '我想买别墅,你们有么',\n", - " 'result': '对不起,我无法提供这样的服务。我是一个人工智能,我可以帮助回答问题,但我不能出售商品或房产。'}" + "{'query': '我想买别墅,你们有么', 'result': '对不起,我无法帮助您购买别墅。我是一个人工智能助手,我主要用来提供信息和回答问题。'}" ] }, - "execution_count": 36, + "execution_count": 34, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "qa_chain({\"query\": \"我想买别墅,你们有么\"})" + "qa_chain.invoke({\"query\": \"我想买别墅,你们有么\"})" ] }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 35, "id": "fc393afc-06d3-4483-bd24-efe000ef5f2a", "metadata": {}, "outputs": [], @@ -809,10 +833,18 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 36, "id": "013c313a-5e7c-48d1-8ed4-eee96e50a99c", "metadata": {}, "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "C:\\Users\\lenovo\\AppData\\Roaming\\Python\\Python310\\site-packages\\langchain_core\\vectorstores\\base.py:796: UserWarning: No relevant docs were retrieved using the relevance score threshold 0.8\n", + " warnings.warn(\n" + ] + }, { "name": "stdout", "output_type": "stream", @@ -827,21 +859,21 @@ { "data": { "text/plain": [ - "{'query': '我想买别墅,你们有么', 'result': '对不起,我不能帮助你购买别墅,因为我是一个人工智能,没有提供房地产服务的功能。'}" + "{'query': '我想买别墅,你们有么', 'result': '对不起,我无法帮助您购买别墅。我是一个人工智能,主要用来提供信息和解答问题。'}" ] }, - "execution_count": 38, + "execution_count": 36, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "qa_chain({\"query\": \"我想买别墅,你们有么\"})" + "qa_chain.invoke({\"query\": \"我想买别墅,你们有么\"})" ] }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 37, "id": "e5fb0943-ffe9-4270-8dbe-f5f5314e6042", "metadata": {}, "outputs": [], @@ -852,10 +884,18 @@ }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 38, "id": "fbc1741e-d34f-4df5-874b-02b78e8cd67a", "metadata": {}, "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "C:\\Users\\lenovo\\AppData\\Roaming\\Python\\Python310\\site-packages\\langchain_core\\vectorstores\\base.py:796: UserWarning: No relevant docs were retrieved using the relevance score threshold 0.8\n", + " warnings.warn(\n" + ] + }, { "name": "stdout", "output_type": "stream", @@ -869,12 +909,12 @@ } ], "source": [ - "result = qa_chain({\"query\": \"我想买别墅,你们有么\"})" + "result = qa_chain.invoke({\"query\": \"我想买别墅,你们有么\"})" ] }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 39, "id": "fac8309c-033c-4144-ada0-08e74fa9bf2d", "metadata": {}, "outputs": [ @@ -882,11 +922,11 @@ "data": { "text/plain": [ "{'query': '我想买别墅,你们有么',\n", - " 'result': '对不起,我不能帮你购买别墅。我是一个AI助手,我主要用来提供信息和回答问题。',\n", + " 'result': '对不起,我不能帮助你购买别墅。我是一个人工智能,主要用来提供信息和回答问题。',\n", " 'source_documents': []}" ] }, - "execution_count": 41, + "execution_count": 39, "metadata": {}, "output_type": "execute_result" } diff --git a/langchain/sales_chatbot/sales_chatbot.py b/langchain/sales_chatbot/sales_chatbot.py index e9f4368e..a140b318 100644 --- a/langchain/sales_chatbot/sales_chatbot.py +++ b/langchain/sales_chatbot/sales_chatbot.py @@ -7,7 +7,7 @@ def initialize_sales_bot(vector_store_dir: str="real_estates_sale"): - db = FAISS.load_local(vector_store_dir, OpenAIEmbeddings()) + db = FAISS.load_local(vector_store_dir, OpenAIEmbeddings(), allow_dangerous_deserialization=True) llm = ChatOpenAI(model_name="gpt-3.5-turbo", temperature=0) global SALES_BOT