|
131 | 131 | },
|
132 | 132 | {
|
133 | 133 | "cell_type": "code",
|
134 |
| - "execution_count": 2, |
| 134 | + "execution_count": 1, |
135 | 135 | "metadata": {},
|
136 | 136 | "outputs": [],
|
137 | 137 | "source": [
|
138 | 138 | "import os\n",
|
| 139 | + "import warnings\n", |
| 140 | + "warnings.filterwarnings('ignore')\n", |
139 | 141 | "\n",
|
140 | 142 | "# Replace values below with your own if using Redis Cloud instance\n",
|
141 | 143 | "REDIS_HOST = os.getenv(\"REDIS_HOST\", \"localhost\") # ex: \"redis-18374.c253.us-central1-1.gce.cloud.redislabs.com\"\n",
|
|
170 | 172 | },
|
171 | 173 | {
|
172 | 174 | "cell_type": "code",
|
173 |
| - "execution_count": 3, |
| 175 | + "execution_count": 2, |
174 | 176 | "metadata": {
|
175 | 177 | "colab": {
|
176 | 178 | "base_uri": "https://localhost:8080/"
|
|
200 | 202 | },
|
201 | 203 | {
|
202 | 204 | "cell_type": "code",
|
203 |
| - "execution_count": 4, |
| 205 | + "execution_count": 3, |
204 | 206 | "metadata": {},
|
205 | 207 | "outputs": [
|
206 |
| - { |
207 |
| - "name": "stderr", |
208 |
| - "output_type": "stream", |
209 |
| - "text": [ |
210 |
| - "/Users/justin.cechmanek/.pyenv/versions/3.11.9/envs/redis-ai-res/lib/python3.11/site-packages/langchain_core/_api/deprecation.py:139: LangChainDeprecationWarning: The class `UnstructuredFileLoader` was deprecated in LangChain 0.2.8 and will be removed in 0.4.0. An updated version of the class exists in the langchain-unstructured package and should be used instead. To use it run `pip install -U langchain-unstructured` and import as `from langchain_unstructured import UnstructuredLoader`.\n", |
211 |
| - " warn_deprecated(\n" |
212 |
| - ] |
213 |
| - }, |
214 | 208 | {
|
215 | 209 | "name": "stdout",
|
216 | 210 | "output_type": "stream",
|
217 | 211 | "text": [
|
218 |
| - "Done preprocessing. Created 180 chunks of the original pdf resources/nke-10k-2023.pdf\n" |
| 212 | + "Done preprocessing. Created 179 chunks of the original pdf resources/nke-10k-2023.pdf\n" |
219 | 213 | ]
|
220 | 214 | }
|
221 | 215 | ],
|
|
249 | 243 | },
|
250 | 244 | {
|
251 | 245 | "cell_type": "code",
|
252 |
| - "execution_count": 5, |
| 246 | + "execution_count": 4, |
253 | 247 | "metadata": {
|
254 | 248 | "colab": {
|
255 | 249 | "base_uri": "https://localhost:8080/",
|
|
414 | 408 | "id": "_h1e-L9yZfaY",
|
415 | 409 | "outputId": "fd540dd7-a0aa-4827-e001-f6d4ef603c6a"
|
416 | 410 | },
|
417 |
| - "outputs": [ |
418 |
| - { |
419 |
| - "name": "stderr", |
420 |
| - "output_type": "stream", |
421 |
| - "text": [ |
422 |
| - "/Users/justin.cechmanek/.pyenv/versions/3.11.9/envs/redis-ai-res/lib/python3.11/site-packages/langchain_core/_api/deprecation.py:139: LangChainDeprecationWarning: The class `HuggingFaceEmbeddings` was deprecated in LangChain 0.2.2 and will be removed in 0.3.0. An updated version of the class exists in the langchain-huggingface package and should be used instead. To use it run `pip install -U langchain-huggingface` and import as `from langchain_huggingface import HuggingFaceEmbeddings`.\n", |
423 |
| - " warn_deprecated(\n" |
424 |
| - ] |
425 |
| - } |
426 |
| - ], |
| 411 | + "outputs": [], |
427 | 412 | "source": [
|
428 | 413 | "from langchain.embeddings.huggingface import HuggingFaceEmbeddings\n",
|
429 | 414 | "\n",
|
|
446 | 431 | },
|
447 | 432 | {
|
448 | 433 | "cell_type": "code",
|
449 |
| - "execution_count": 6, |
| 434 | + "execution_count": 5, |
450 | 435 | "metadata": {
|
451 | 436 | "colab": {
|
452 | 437 | "base_uri": "https://localhost:8080/"
|
|
503 | 488 | },
|
504 | 489 | {
|
505 | 490 | "cell_type": "code",
|
506 |
| - "execution_count": 7, |
| 491 | + "execution_count": 6, |
507 | 492 | "metadata": {
|
508 | 493 | "id": "_Z3KpL8q1vmw"
|
509 | 494 | },
|
|
520 | 505 | },
|
521 | 506 | {
|
522 | 507 | "cell_type": "code",
|
523 |
| - "execution_count": 8, |
| 508 | + "execution_count": 7, |
524 | 509 | "metadata": {
|
525 | 510 | "colab": {
|
526 | 511 | "base_uri": "https://localhost:8080/"
|
|
549 | 534 | " 'epsilon': 0.01}]}"
|
550 | 535 | ]
|
551 | 536 | },
|
552 |
| - "execution_count": 8, |
| 537 | + "execution_count": 7, |
553 | 538 | "metadata": {},
|
554 | 539 | "output_type": "execute_result"
|
555 | 540 | }
|
|
561 | 546 | },
|
562 | 547 | {
|
563 | 548 | "cell_type": "code",
|
564 |
| - "execution_count": 9, |
| 549 | + "execution_count": 8, |
565 | 550 | "metadata": {
|
566 | 551 | "colab": {
|
567 | 552 | "base_uri": "https://localhost:8080/"
|
|
573 | 558 | {
|
574 | 559 | "data": {
|
575 | 560 | "text/plain": [
|
576 |
| - "180" |
| 561 | + "179" |
577 | 562 | ]
|
578 | 563 | },
|
579 |
| - "execution_count": 9, |
| 564 | + "execution_count": 8, |
580 | 565 | "metadata": {},
|
581 | 566 | "output_type": "execute_result"
|
582 | 567 | }
|
|
795 | 780 | },
|
796 | 781 | {
|
797 | 782 | "cell_type": "code",
|
798 |
| - "execution_count": 16, |
| 783 | + "execution_count": 9, |
799 | 784 | "metadata": {
|
800 | 785 | "colab": {
|
801 | 786 | "base_uri": "https://localhost:8080/"
|
802 | 787 | },
|
803 | 788 | "id": "GSpH-cur1vmz",
|
804 | 789 | "outputId": "b00de5c7-1684-4e8e-c146-6d402910cdc5"
|
805 | 790 | },
|
806 |
| - "outputs": [ |
807 |
| - { |
808 |
| - "name": "stderr", |
809 |
| - "output_type": "stream", |
810 |
| - "text": [ |
811 |
| - "/Users/justin.cechmanek/.pyenv/versions/3.11.9/envs/redis-ai-res/lib/python3.11/site-packages/langchain_core/_api/deprecation.py:139: LangChainDeprecationWarning: The class `OpenAI` was deprecated in LangChain 0.0.10 and will be removed in 0.3.0. An updated version of the class exists in the langchain-openai package and should be used instead. To use it run `pip install -U langchain-openai` and import as `from langchain_openai import OpenAI`.\n", |
812 |
| - " warn_deprecated(\n" |
813 |
| - ] |
814 |
| - } |
815 |
| - ], |
| 791 | + "outputs": [], |
816 | 792 | "source": [
|
817 | 793 | "import getpass\n",
|
818 |
| - "from langchain.llms import OpenAI\n", |
| 794 | + "from langchain_openai import ChatOpenAI\n", |
819 | 795 | "\n",
|
820 |
| - "llm = OpenAI(openai_api_key=os.getenv(\"OPENAI_API_KEY\") or getpass.getpass(prompt=\"OpenAI API Key:\"))" |
| 796 | + "llm = ChatOpenAI(openai_api_key=os.getenv(\"OPENAI_API_KEY\") or getpass.getpass(prompt=\"OpenAI API Key:\"))" |
821 | 797 | ]
|
822 | 798 | },
|
823 | 799 | {
|
|
832 | 808 | },
|
833 | 809 | {
|
834 | 810 | "cell_type": "code",
|
835 |
| - "execution_count": 17, |
| 811 | + "execution_count": 10, |
836 | 812 | "metadata": {
|
837 | 813 | "id": "yKKn2KKp3TQ4"
|
838 | 814 | },
|
|
879 | 855 | },
|
880 | 856 | {
|
881 | 857 | "cell_type": "code",
|
882 |
| - "execution_count": 18, |
| 858 | + "execution_count": 11, |
883 | 859 | "metadata": {
|
884 | 860 | "id": "RKNSP0zqZq98"
|
885 | 861 | },
|
|
909 | 885 | },
|
910 | 886 | {
|
911 | 887 | "cell_type": "code",
|
912 |
| - "execution_count": 19, |
| 888 | + "execution_count": 13, |
913 | 889 | "metadata": {
|
914 | 890 | "colab": {
|
915 | 891 | "base_uri": "https://localhost:8080/",
|
|
919 | 895 | "outputId": "813fffe6-3d8b-4df7-a035-c54e421c0856"
|
920 | 896 | },
|
921 | 897 | "outputs": [
|
922 |
| - { |
923 |
| - "name": "stderr", |
924 |
| - "output_type": "stream", |
925 |
| - "text": [ |
926 |
| - "/Users/justin.cechmanek/.pyenv/versions/3.11.9/envs/redis-ai-res/lib/python3.11/site-packages/langchain_core/_api/deprecation.py:139: LangChainDeprecationWarning: The method `Chain.__call__` was deprecated in langchain 0.1.0 and will be removed in 0.3.0. Use invoke instead.\n", |
927 |
| - " warn_deprecated(\n" |
928 |
| - ] |
929 |
| - }, |
930 | 898 | {
|
931 | 899 | "data": {
|
932 | 900 | "text/plain": [
|
933 |
| - "\" Nike's revenue for the fiscal year ended May 31, 2022 was $51,217 million, while their revenue for the previous fiscal year ended May 31, 2021 was $46,710 million. This represents a 10% increase in revenue year-over-year.\"" |
| 901 | + "\"Nike's revenue last year was $46,710 million, and this year it was $51,217 million.\"" |
934 | 902 | ]
|
935 | 903 | },
|
936 |
| - "execution_count": 19, |
| 904 | + "execution_count": 13, |
937 | 905 | "metadata": {},
|
938 | 906 | "output_type": "execute_result"
|
939 | 907 | }
|
940 | 908 | ],
|
941 | 909 | "source": [
|
942 | 910 | "query = \"What was Nike's revenue last year compared to this year??\"\n",
|
943 |
| - "res=qa(query)\n", |
| 911 | + "res=qa.invoke(query)\n", |
944 | 912 | "res['result']"
|
945 | 913 | ]
|
946 | 914 | },
|
947 | 915 | {
|
948 | 916 | "cell_type": "code",
|
949 |
| - "execution_count": 20, |
| 917 | + "execution_count": 14, |
950 | 918 | "metadata": {
|
951 | 919 | "colab": {
|
952 | 920 | "base_uri": "https://localhost:8080/",
|
|
959 | 927 | {
|
960 | 928 | "data": {
|
961 | 929 | "text/plain": [
|
962 |
| - "' Nike offers thousands of products in athletic footwear, apparel, equipment, and accessories. Nike is part of the athletic and leisure industry, specifically the athletic footwear, apparel, and equipment industry.'" |
| 930 | + "'Nike offers three main categories of products: footwear, apparel, and equipment. Nike is part of the athletic footwear, apparel, and equipment industry.'" |
963 | 931 | ]
|
964 | 932 | },
|
965 |
| - "execution_count": 20, |
| 933 | + "execution_count": 14, |
966 | 934 | "metadata": {},
|
967 | 935 | "output_type": "execute_result"
|
968 | 936 | }
|
969 | 937 | ],
|
970 | 938 | "source": [
|
971 | 939 | "query = \"How many products does Nike offer? What is the industry that Nike is part of?\"\n",
|
972 |
| - "res=qa(query)\n", |
| 940 | + "res=qa.invoke(query)\n", |
973 | 941 | "res['result']"
|
974 | 942 | ]
|
975 | 943 | },
|
976 | 944 | {
|
977 | 945 | "cell_type": "code",
|
978 |
| - "execution_count": 21, |
| 946 | + "execution_count": 15, |
979 | 947 | "metadata": {
|
980 | 948 | "colab": {
|
981 | 949 | "base_uri": "https://localhost:8080/",
|
|
988 | 956 | {
|
989 | 957 | "data": {
|
990 | 958 | "text/plain": [
|
991 |
| - "\" I cannot answer this question as it is subjective and not stated in the provided context. The financial 10k filings only provide information about the company's operations and financial performance, not its ethical practices.\"" |
| 959 | + "\"I don't know.\"" |
992 | 960 | ]
|
993 | 961 | },
|
994 |
| - "execution_count": 21, |
| 962 | + "execution_count": 15, |
995 | 963 | "metadata": {},
|
996 | 964 | "output_type": "execute_result"
|
997 | 965 | }
|
998 | 966 | ],
|
999 | 967 | "source": [
|
1000 | 968 | "query = \"Is Nike an ethical company?\"\n",
|
1001 |
| - "res=qa(query)\n", |
1002 |
| - "res['result']" |
1003 |
| - ] |
1004 |
| - }, |
1005 |
| - { |
1006 |
| - "cell_type": "code", |
1007 |
| - "execution_count": 22, |
1008 |
| - "metadata": { |
1009 |
| - "colab": { |
1010 |
| - "base_uri": "https://localhost:8080/", |
1011 |
| - "height": 35 |
1012 |
| - }, |
1013 |
| - "id": "kjTO0RtH1vm1", |
1014 |
| - "outputId": "f415c57b-1612-450a-db33-6b9616bff84b" |
1015 |
| - }, |
1016 |
| - "outputs": [ |
1017 |
| - { |
1018 |
| - "data": { |
1019 |
| - "text/plain": [ |
1020 |
| - "' As of May 31, 2023, Nike had a total of 74,400 employees globally.'" |
1021 |
| - ] |
1022 |
| - }, |
1023 |
| - "execution_count": 22, |
1024 |
| - "metadata": {}, |
1025 |
| - "output_type": "execute_result" |
1026 |
| - } |
1027 |
| - ], |
1028 |
| - "source": [ |
1029 |
| - "query = \"How many employees work at Nike???\"\n", |
1030 |
| - "res=qa(query)\n", |
| 969 | + "res=qa.invoke(query)\n", |
1031 | 970 | "res['result']"
|
1032 | 971 | ]
|
1033 | 972 | },
|
|
0 commit comments