Created
April 17, 2023 09:25
-
-
Save inspirit941/53f9b8adcfcdd71adec3d33b68b64869 to your computer and use it in GitHub Desktop.
23.04.17. aifactory 김태영 - LangChain 시작하기.ipynb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "nbformat": 4, | |
| "nbformat_minor": 0, | |
| "metadata": { | |
| "colab": { | |
| "provenance": [], | |
| "authorship_tag": "ABX9TyPgg4j3StUuhZFQ7phaWVj9", | |
| "include_colab_link": true | |
| }, | |
| "kernelspec": { | |
| "name": "python3", | |
| "display_name": "Python 3" | |
| }, | |
| "language_info": { | |
| "name": "python" | |
| } | |
| }, | |
| "cells": [ | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "id": "view-in-github", | |
| "colab_type": "text" | |
| }, | |
| "source": [ | |
| "<a href=\"https://colab.research.google.com/gist/inspirit941/53f9b8adcfcdd71adec3d33b68b64869/23-04-17-aifactory-langchain.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "import os\n", | |
| "os.environ[\"OPENAI_API_KEY\"] = \"\" ## api key" | |
| ], | |
| "metadata": { | |
| "id": "PJUE23rqaiAW" | |
| }, | |
| "execution_count": 1, | |
| "outputs": [] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "source": [ | |
| "### Notice\n", | |
| "\n", | |
| "- openAI api에서 따로 세션관리를 하지 않음. 요청할 때 과거 데이터를 api 레벨에서 기억해주지 않는다.\n", | |
| "- 대화를 이어가려면, 이전 대화 메시지를 포함해서 다시 요청을 보내야 함.\n", | |
| "- 코드 까보면 openAI call은 보통 함수 실행 시 한 번임.\n" | |
| ], | |
| "metadata": { | |
| "id": "TdV0l43Hfbqn" | |
| } | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "source": [ | |
| "### pkg" | |
| ], | |
| "metadata": { | |
| "id": "M2o6pSjKZ_AN" | |
| } | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 2, | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/" | |
| }, | |
| "id": "S-7ntia7Zftn", | |
| "outputId": "e8528c61-39d7-4ce7-e42c-1999d93ee9a9" | |
| }, | |
| "outputs": [ | |
| { | |
| "output_type": "stream", | |
| "name": "stdout", | |
| "text": [ | |
| "Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n", | |
| "Collecting langchain\n", | |
| " Downloading langchain-0.0.141-py3-none-any.whl (540 kB)\n", | |
| "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m540.8/540.8 kB\u001b[0m \u001b[31m4.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", | |
| "\u001b[?25hCollecting openapi-schema-pydantic<2.0,>=1.2\n", | |
| " Downloading openapi_schema_pydantic-1.2.4-py3-none-any.whl (90 kB)\n", | |
| "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m90.0/90.0 kB\u001b[0m \u001b[31m7.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", | |
| "\u001b[?25hRequirement already satisfied: pydantic<2,>=1 in /usr/local/lib/python3.9/dist-packages (from langchain) (1.10.7)\n", | |
| "Collecting SQLAlchemy<2,>=1\n", | |
| " Downloading SQLAlchemy-1.4.47-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB)\n", | |
| "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.6/1.6 MB\u001b[0m \u001b[31m19.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", | |
| "\u001b[?25hCollecting gptcache>=0.1.7\n", | |
| " Downloading gptcache-0.1.12-py3-none-any.whl (52 kB)\n", | |
| "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m52.6/52.6 kB\u001b[0m \u001b[31m3.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", | |
| "\u001b[?25hRequirement already satisfied: numpy<2,>=1 in /usr/local/lib/python3.9/dist-packages (from langchain) (1.22.4)\n", | |
| "Requirement already satisfied: PyYAML>=5.4.1 in /usr/local/lib/python3.9/dist-packages (from langchain) (6.0)\n", | |
| "Requirement already satisfied: requests<3,>=2 in /usr/local/lib/python3.9/dist-packages (from langchain) (2.27.1)\n", | |
| "Requirement already satisfied: tenacity<9.0.0,>=8.1.0 in /usr/local/lib/python3.9/dist-packages (from langchain) (8.2.2)\n", | |
| "Collecting dataclasses-json<0.6.0,>=0.5.7\n", | |
| " Downloading dataclasses_json-0.5.7-py3-none-any.whl (25 kB)\n", | |
| "Collecting async-timeout<5.0.0,>=4.0.0\n", | |
| " Downloading async_timeout-4.0.2-py3-none-any.whl (5.8 kB)\n", | |
| "Collecting aiohttp<4.0.0,>=3.8.3\n", | |
| " Downloading aiohttp-3.8.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.0 MB)\n", | |
| "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.0/1.0 MB\u001b[0m \u001b[31m23.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", | |
| "\u001b[?25hCollecting aiosignal>=1.1.2\n", | |
| " Downloading aiosignal-1.3.1-py3-none-any.whl (7.6 kB)\n", | |
| "Requirement already satisfied: attrs>=17.3.0 in /usr/local/lib/python3.9/dist-packages (from aiohttp<4.0.0,>=3.8.3->langchain) (22.2.0)\n", | |
| "Collecting yarl<2.0,>=1.0\n", | |
| " Downloading yarl-1.8.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (264 kB)\n", | |
| "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m264.6/264.6 kB\u001b[0m \u001b[31m10.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", | |
| "\u001b[?25hCollecting multidict<7.0,>=4.5\n", | |
| " Downloading multidict-6.0.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (114 kB)\n", | |
| "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m114.2/114.2 kB\u001b[0m \u001b[31m4.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", | |
| "\u001b[?25hRequirement already satisfied: charset-normalizer<4.0,>=2.0 in /usr/local/lib/python3.9/dist-packages (from aiohttp<4.0.0,>=3.8.3->langchain) (2.0.12)\n", | |
| "Collecting frozenlist>=1.1.1\n", | |
| " Downloading frozenlist-1.3.3-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (158 kB)\n", | |
| "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m158.8/158.8 kB\u001b[0m \u001b[31m7.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", | |
| "\u001b[?25hCollecting marshmallow<4.0.0,>=3.3.0\n", | |
| " Downloading marshmallow-3.19.0-py3-none-any.whl (49 kB)\n", | |
| "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m49.1/49.1 kB\u001b[0m \u001b[31m1.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", | |
| "\u001b[?25hCollecting typing-inspect>=0.4.0\n", | |
| " Downloading typing_inspect-0.8.0-py3-none-any.whl (8.7 kB)\n", | |
| "Collecting marshmallow-enum<2.0.0,>=1.5.1\n", | |
| " Downloading marshmallow_enum-1.5.1-py2.py3-none-any.whl (4.2 kB)\n", | |
| "Collecting openai\n", | |
| " Downloading openai-0.27.4-py3-none-any.whl (70 kB)\n", | |
| "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m70.3/70.3 kB\u001b[0m \u001b[31m4.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", | |
| "\u001b[?25hRequirement already satisfied: cachetools in /usr/local/lib/python3.9/dist-packages (from gptcache>=0.1.7->langchain) (5.3.0)\n", | |
| "Requirement already satisfied: typing-extensions>=4.2.0 in /usr/local/lib/python3.9/dist-packages (from pydantic<2,>=1->langchain) (4.5.0)\n", | |
| "Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.9/dist-packages (from requests<3,>=2->langchain) (3.4)\n", | |
| "Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/local/lib/python3.9/dist-packages (from requests<3,>=2->langchain) (1.26.15)\n", | |
| "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.9/dist-packages (from requests<3,>=2->langchain) (2022.12.7)\n", | |
| "Requirement already satisfied: greenlet!=0.4.17 in /usr/local/lib/python3.9/dist-packages (from SQLAlchemy<2,>=1->langchain) (2.0.2)\n", | |
| "Requirement already satisfied: packaging>=17.0 in /usr/local/lib/python3.9/dist-packages (from marshmallow<4.0.0,>=3.3.0->dataclasses-json<0.6.0,>=0.5.7->langchain) (23.0)\n", | |
| "Collecting mypy-extensions>=0.3.0\n", | |
| " Downloading mypy_extensions-1.0.0-py3-none-any.whl (4.7 kB)\n", | |
| "Requirement already satisfied: tqdm in /usr/local/lib/python3.9/dist-packages (from openai->gptcache>=0.1.7->langchain) (4.65.0)\n", | |
| "Installing collected packages: SQLAlchemy, mypy-extensions, multidict, marshmallow, frozenlist, async-timeout, yarl, typing-inspect, openapi-schema-pydantic, marshmallow-enum, aiosignal, dataclasses-json, aiohttp, openai, gptcache, langchain\n", | |
| " Attempting uninstall: SQLAlchemy\n", | |
| " Found existing installation: SQLAlchemy 2.0.9\n", | |
| " Uninstalling SQLAlchemy-2.0.9:\n", | |
| " Successfully uninstalled SQLAlchemy-2.0.9\n", | |
| "Successfully installed SQLAlchemy-1.4.47 aiohttp-3.8.4 aiosignal-1.3.1 async-timeout-4.0.2 dataclasses-json-0.5.7 frozenlist-1.3.3 gptcache-0.1.12 langchain-0.0.141 marshmallow-3.19.0 marshmallow-enum-1.5.1 multidict-6.0.4 mypy-extensions-1.0.0 openai-0.27.4 openapi-schema-pydantic-1.2.4 typing-inspect-0.8.0 yarl-1.8.2\n", | |
| "Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n", | |
| "Collecting tiktoken\n", | |
| " Downloading tiktoken-0.3.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.7 MB)\n", | |
| "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.7/1.7 MB\u001b[0m \u001b[31m20.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", | |
| "\u001b[?25hRequirement already satisfied: regex>=2022.1.18 in /usr/local/lib/python3.9/dist-packages (from tiktoken) (2022.10.31)\n", | |
| "Requirement already satisfied: requests>=2.26.0 in /usr/local/lib/python3.9/dist-packages (from tiktoken) (2.27.1)\n", | |
| "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.9/dist-packages (from requests>=2.26.0->tiktoken) (2022.12.7)\n", | |
| "Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/local/lib/python3.9/dist-packages (from requests>=2.26.0->tiktoken) (1.26.15)\n", | |
| "Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.9/dist-packages (from requests>=2.26.0->tiktoken) (3.4)\n", | |
| "Requirement already satisfied: charset-normalizer~=2.0.0 in /usr/local/lib/python3.9/dist-packages (from requests>=2.26.0->tiktoken) (2.0.12)\n", | |
| "Installing collected packages: tiktoken\n", | |
| "Successfully installed tiktoken-0.3.3\n", | |
| "Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n", | |
| "Collecting openapi\n", | |
| " Downloading openapi-1.1.0.tar.gz (12 kB)\n", | |
| " Preparing metadata (setup.py) ... \u001b[?25l\u001b[?25hdone\n", | |
| "Collecting inflection>=0.3.1\n", | |
| " Downloading inflection-0.5.1-py2.py3-none-any.whl (9.5 kB)\n", | |
| "Requirement already satisfied: jsonschema>=2.6.0 in /usr/local/lib/python3.9/dist-packages (from openapi) (4.3.3)\n", | |
| "Requirement already satisfied: pyrsistent!=0.17.0,!=0.17.1,!=0.17.2,>=0.14.0 in /usr/local/lib/python3.9/dist-packages (from jsonschema>=2.6.0->openapi) (0.19.3)\n", | |
| "Requirement already satisfied: attrs>=17.4.0 in /usr/local/lib/python3.9/dist-packages (from jsonschema>=2.6.0->openapi) (22.2.0)\n", | |
| "Building wheels for collected packages: openapi\n", | |
| " Building wheel for openapi (setup.py) ... \u001b[?25l\u001b[?25hdone\n", | |
| " Created wheel for openapi: filename=openapi-1.1.0-py3-none-any.whl size=12710 sha256=d33c00e543701b62d0ae6b9ce8ffafd1987e1e6795b3616ef7372ab1a59e1e48\n", | |
| " Stored in directory: /root/.cache/pip/wheels/a1/4c/59/b042cf4725c26543066bddc286c529dc44139abe214e55574d\n", | |
| "Successfully built openapi\n", | |
| "Installing collected packages: inflection, openapi\n", | |
| "Successfully installed inflection-0.5.1 openapi-1.1.0\n", | |
| "Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n", | |
| "Collecting google-search-results\n", | |
| " Downloading google_search_results-2.4.2.tar.gz (18 kB)\n", | |
| " Preparing metadata (setup.py) ... \u001b[?25l\u001b[?25hdone\n", | |
| "Requirement already satisfied: requests in /usr/local/lib/python3.9/dist-packages (from google-search-results) (2.27.1)\n", | |
| "Requirement already satisfied: charset-normalizer~=2.0.0 in /usr/local/lib/python3.9/dist-packages (from requests->google-search-results) (2.0.12)\n", | |
| "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.9/dist-packages (from requests->google-search-results) (2022.12.7)\n", | |
| "Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/local/lib/python3.9/dist-packages (from requests->google-search-results) (1.26.15)\n", | |
| "Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.9/dist-packages (from requests->google-search-results) (3.4)\n", | |
| "Building wheels for collected packages: google-search-results\n", | |
| " Building wheel for google-search-results (setup.py) ... \u001b[?25l\u001b[?25hdone\n", | |
| " Created wheel for google-search-results: filename=google_search_results-2.4.2-py3-none-any.whl size=32019 sha256=5bc2db285898c39eb459d9bfeeb0cf20615344a2d6e6096718b422810d7e1442\n", | |
| " Stored in directory: /root/.cache/pip/wheels/68/8e/73/744b7d9d7ac618849d93081a20e1c0deccd2aef90901c9f5a9\n", | |
| "Successfully built google-search-results\n", | |
| "Installing collected packages: google-search-results\n", | |
| "Successfully installed google-search-results-2.4.2\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "!pip install langchain\n", | |
| "!pip install tiktoken # 토큰 처리 관련\n", | |
| "!pip install openapi\n", | |
| "!pip install google-search-results" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "source": [ | |
| "## LLMS" | |
| ], | |
| "metadata": { | |
| "id": "Y75UfUSBZ8oG" | |
| } | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "from langchain.llms import OpenAI\n", | |
| "\n", | |
| "llm = OpenAI(temperature=0.9)\n", | |
| "text = \"What would be a good company name for a company that makes colorful socks?\"\n", | |
| "print(llm(text))" | |
| ], | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/" | |
| }, | |
| "id": "YyFTZl3PZzFR", | |
| "outputId": "c571b067-9a73-4e45-80ab-52f88fcc520a" | |
| }, | |
| "execution_count": 3, | |
| "outputs": [ | |
| { | |
| "output_type": "stream", | |
| "name": "stdout", | |
| "text": [ | |
| "\n", | |
| "\n", | |
| "Happy Toes Socks\n" | |
| ] | |
| } | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "source": [ | |
| "### Generation" | |
| ], | |
| "metadata": { | |
| "id": "-VfRY-IZa9Px" | |
| } | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "## 질문 여러 개 동시에 받기\n", | |
| "llm_result = llm.generate([\"tell me a joke\", \"tell me a poem\"] * 2)\n", | |
| "len(llm_result.generations) ## 같은 질문을 두 번 했으므로 len은 4" | |
| ], | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/" | |
| }, | |
| "id": "ClHoNHdIZ8Im", | |
| "outputId": "eb837501-53cc-4600-d26e-be14ebda6296" | |
| }, | |
| "execution_count": 4, | |
| "outputs": [ | |
| { | |
| "output_type": "execute_result", | |
| "data": { | |
| "text/plain": [ | |
| "4" | |
| ] | |
| }, | |
| "metadata": {}, | |
| "execution_count": 4 | |
| } | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "llm_result.generations[0]" | |
| ], | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/" | |
| }, | |
| "id": "pViHUEsKbNHs", | |
| "outputId": "2e5e445b-5894-4574-f0d3-b002a47f124d" | |
| }, | |
| "execution_count": 5, | |
| "outputs": [ | |
| { | |
| "output_type": "execute_result", | |
| "data": { | |
| "text/plain": [ | |
| "[Generation(text='\\n\\nWhy did the chicken go to the séance?\\nTo get to the other side!', generation_info={'finish_reason': 'stop', 'logprobs': None})]" | |
| ] | |
| }, | |
| "metadata": {}, | |
| "execution_count": 5 | |
| } | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "llm_result.generations[-1]" | |
| ], | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/" | |
| }, | |
| "id": "Pswlmj2nbPZP", | |
| "outputId": "4676874f-17e1-4ecd-cee3-cb2ccb495ab9" | |
| }, | |
| "execution_count": 6, | |
| "outputs": [ | |
| { | |
| "output_type": "execute_result", | |
| "data": { | |
| "text/plain": [ | |
| "[Generation(text='\\n\\nRoses are red,\\nViolets are blue,\\nSuger is sweet,\\nAnd so are you!', generation_info={'finish_reason': 'stop', 'logprobs': None})]" | |
| ] | |
| }, | |
| "metadata": {}, | |
| "execution_count": 6 | |
| } | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "llm_result.llm_output" | |
| ], | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/" | |
| }, | |
| "id": "7zuvN__Hbcht", | |
| "outputId": "c71e10ed-2a6b-45ba-983a-8c11fe7acba5" | |
| }, | |
| "execution_count": 7, | |
| "outputs": [ | |
| { | |
| "output_type": "execute_result", | |
| "data": { | |
| "text/plain": [ | |
| "{'token_usage': {'completion_tokens': 90,\n", | |
| " 'prompt_tokens': 16,\n", | |
| " 'total_tokens': 106},\n", | |
| " 'model_name': 'text-davinci-003'}" | |
| ] | |
| }, | |
| "metadata": {}, | |
| "execution_count": 7 | |
| } | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "llm.get_num_tokens(\"what a joke\") # 입력 토큰이 3개라서 3 리턴\n", | |
| "# 한글이면 토큰 개수가 많게 잡힘.." | |
| ], | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/" | |
| }, | |
| "id": "H7m2XPnmbp3n", | |
| "outputId": "5d453fbf-858b-4bec-b6e0-437aefa63408" | |
| }, | |
| "execution_count": 8, | |
| "outputs": [ | |
| { | |
| "output_type": "execute_result", | |
| "data": { | |
| "text/plain": [ | |
| "3" | |
| ] | |
| }, | |
| "metadata": {}, | |
| "execution_count": 8 | |
| } | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "source": [ | |
| "### Chat Model" | |
| ], | |
| "metadata": { | |
| "id": "P952l0xOcCQL" | |
| } | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "from langchain.chat_models import ChatOpenAI\n", | |
| "from langchain.schema import (\n", | |
| " AIMessage, HumanMessage, SystemMessage\n", | |
| ")\n", | |
| "\n", | |
| "chat = ChatOpenAI(temperature=0)\n", | |
| "\n", | |
| "chat([HumanMessage(content=\"Translate this sentence from English to Korean. I love Programming.\")])" | |
| ], | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/" | |
| }, | |
| "id": "ENUC1GrJb4Yu", | |
| "outputId": "f3688b24-fd79-4735-f006-dcc4f786f03a" | |
| }, | |
| "execution_count": 9, | |
| "outputs": [ | |
| { | |
| "output_type": "execute_result", | |
| "data": { | |
| "text/plain": [ | |
| "AIMessage(content='저는 프로그래밍을 좋아합니다.', additional_kwargs={})" | |
| ] | |
| }, | |
| "metadata": {}, | |
| "execution_count": 9 | |
| } | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "## 지시문 입력하기\n", | |
| "messages = [\n", | |
| " SystemMessage(content=\"You are a helpful assistant that translate English to Korean.\"),\n", | |
| " HumanMessage(content=\"Translate this sentence from English to Korean. I Love Programming so much.\")\n", | |
| "]\n", | |
| "chat(messages)" | |
| ], | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/" | |
| }, | |
| "id": "NtSaivKacXkM", | |
| "outputId": "5ee7fccf-5cdc-4d8d-f2c1-546f5e429937" | |
| }, | |
| "execution_count": 10, | |
| "outputs": [ | |
| { | |
| "output_type": "execute_result", | |
| "data": { | |
| "text/plain": [ | |
| "AIMessage(content='저는 프로그래밍을 너무 좋아합니다.', additional_kwargs={})" | |
| ] | |
| }, | |
| "metadata": {}, | |
| "execution_count": 10 | |
| } | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "# 묶어서 한 번에 보낼 수 있음.\n", | |
| "batch_messages = [\n", | |
| " [\n", | |
| " SystemMessage(content=\"You are a helpful assistant that translate English to Korean.\"),\n", | |
| " HumanMessage(content=\"Translate this sentence from English to Korean. I Love Programming so much.\")\n", | |
| " ],\n", | |
| " [\n", | |
| " SystemMessage(content=\"You are a helpful assistant that translate English to Korean.\"),\n", | |
| " HumanMessage(content=\"Translate this sentence from English to Korean. What is Artifical Intelligence?\")\n", | |
| " ],\n", | |
| "]\n", | |
| "\n", | |
| "result = chat.generate(batch_messages)\n", | |
| "result" | |
| ], | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/" | |
| }, | |
| "id": "dSs04_spcw-j", | |
| "outputId": "86873046-57fb-473b-8642-56b59e054d83" | |
| }, | |
| "execution_count": 11, | |
| "outputs": [ | |
| { | |
| "output_type": "stream", | |
| "name": "stderr", | |
| "text": [ | |
| "WARNING:/usr/local/lib/python3.9/dist-packages/langchain/chat_models/openai.py:Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 1.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-mfNrETunpMAJBlt7q8zkKlhK on requests per min. Limit: 3 / min. Please try again in 20s. Contact [email protected] if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", | |
| "WARNING:/usr/local/lib/python3.9/dist-packages/langchain/chat_models/openai.py:Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 2.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-mfNrETunpMAJBlt7q8zkKlhK on requests per min. Limit: 3 / min. Please try again in 20s. Contact [email protected] if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", | |
| "WARNING:/usr/local/lib/python3.9/dist-packages/langchain/chat_models/openai.py:Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 4.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-mfNrETunpMAJBlt7q8zkKlhK on requests per min. Limit: 3 / min. Please try again in 20s. Contact [email protected] if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", | |
| "WARNING:/usr/local/lib/python3.9/dist-packages/langchain/chat_models/openai.py:Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 8.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-mfNrETunpMAJBlt7q8zkKlhK on requests per min. Limit: 3 / min. Please try again in 20s. Contact [email protected] if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n" | |
| ] | |
| }, | |
| { | |
| "output_type": "execute_result", | |
| "data": { | |
| "text/plain": [ | |
| "LLMResult(generations=[[ChatGeneration(text='저는 프로그래밍을 너무 좋아합니다.', generation_info=None, message=AIMessage(content='저는 프로그래밍을 너무 좋아합니다.', additional_kwargs={}))], [ChatGeneration(text='인공지능이란 무엇인가요?', generation_info=None, message=AIMessage(content='인공지능이란 무엇인가요?', additional_kwargs={}))]], llm_output={'token_usage': {'prompt_tokens': 77, 'completion_tokens': 33, 'total_tokens': 110}, 'model_name': 'gpt-3.5-turbo'})" | |
| ] | |
| }, | |
| "metadata": {}, | |
| "execution_count": 11 | |
| } | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "source": [ | |
| "### Embedding" | |
| ], | |
| "metadata": { | |
| "id": "f09Ol7Okd1Oa" | |
| } | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "from langchain.embeddings import OpenAIEmbeddings\n", | |
| "\n", | |
| "embeddings = OpenAIEmbeddings()\n", | |
| "\n", | |
| "text = \"this is a test Document\"\n", | |
| "query_result = embeddings.embed_query(text)\n", | |
| "doc_result = embeddings.embed_documents([text])\n", | |
| "\n", | |
| "print(query_result)\n", | |
| "print(doc_result)" | |
| ], | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/" | |
| }, | |
| "id": "ayZ4wth3dGCV", | |
| "outputId": "6628abb6-d918-4926-88e3-722e52857509" | |
| }, | |
| "execution_count": 12, | |
| "outputs": [ | |
| { | |
| "output_type": "stream", | |
| "name": "stdout", | |
| "text": [ | |
| "[-0.0081512013337688, 0.012106734965920695, -0.014181222422994421, -0.02444026373707087, -0.005793223017142049, 0.028309081926401632, -0.015235142413148247, -0.008317961155970752, -0.012893840358138457, -0.02190552040006552, 0.007730967643527587, 0.023959995598140854, -0.012707069208260662, 0.027281844327363965, -0.0005903284038790674, 0.012166768948948222, 0.01946416263799907, -0.009592002956591189, 0.0037954448733902584, -0.015835476655488213, 0.00042607037598638186, 0.0017909963646900666, -0.016369105851360338, 0.005643139456557057, -0.01470151228595357, -0.01049250432010114, 0.017409685577278636, -0.036206810789115, 0.008678161328845711, -0.0078910568679505, 0.005709843106041073, -0.015461935287055174, -0.006250143831014788, -0.03802115378037043, -0.0030550329671338587, 0.002227906083717601, -0.0051528665851116725, -0.03738079502003367, 0.019197346177417904, -0.01708950805975536, -0.002593109321342159, 0.00032580625640487025, 0.002899946574629906, -0.012840476507228693, 0.002251252477452325, -0.014808238125127996, 0.02988329084819205, -0.030390239515593123, -0.008324631288088516, 0.028068949719581727, 0.016635922311941505, 0.012206790672977356, -0.025013915588294678, -0.0047859958144576735, -0.010619241486951408, 0.013180666283750362, 0.0028265725601974894, 0.017743205221682542, 0.0008563097009616849, -0.004765984952443107, -0.02637467283173625, 0.011653149218106838, -0.027455273350361128, 0.0012048369680075798, 0.0006236802868287346, -0.00699055550444055, -0.003266817345283905, 0.015622024045816812, 0.004042248609311754, 0.015888839575075427, 0.01917066564894685, 0.016822691599174194, 0.010245700118518369, 0.01383436344567754, 0.015782113735901, 0.00795776005177324, -0.013080610576693701, -0.017102848323990887, 0.010472492992425298, 0.0016817689931408425, 0.006607008937830866, -0.031083959332871988, -0.009451924594182842, 0.0013849371708603785, -0.002478045351359254, 0.007837693948363289, 0.014194563618552501, 0.03465928053315053, -0.02414676674801865, -0.015261823872941853, -0.0018360213862994364, 0.022559217561992702, 0.003271820177202866, 0.009525298841445897, -0.026614806901201257, 0.029589795721784936, 0.014594786446779145, 0.024093403828431437, 0.003431909168795141, -0.04015567428914913, 0.0030900523249053073, 0.008371324075557964, -0.0013607570106109338, 0.0005673990098170222, -0.022892735343751504, -0.004852699929602965, 0.01751641141645306, -0.002623126080025285, 0.01520846095335464, -0.006093390138312033, -0.012420243282648758, 0.015662045769845947, -0.0051461964529939085, -0.03628685237452816, 0.010505844584336668, -0.017836588933976334, -0.0007204007532035356, -0.020144540328397305, -0.016275722139066542, -0.0007616737672890041, -0.009405232738035946, 0.01650251408165092, 0.026281287256797355, -0.021011689168673336, 0.012400231954972914, 0.016475833553179865, -0.0054163465826501285, -0.03626017184605711, -0.010432470337073613, -0.0044524771013763195, 0.02694832468296006, 0.022172334998001583, 0.026267946992561825, 0.015315186792529065, -0.032257947289080866, 0.028442490156692216, -0.025254049657759688, 0.018570331406606883, -0.056351351117512306, -0.02514732381858526, 0.006170099451633969, 0.03996890313927134, -0.015755431344784843, -0.01658255939235429, -0.0033068397678049526, 0.009105065616865962, 0.019424139982647387, -0.021158437663199445, 0.02400001825349254, -0.01859701193507794, 0.006323518078277843, -0.004649252983769485, 0.010465822860307533, -0.005196224306522239, 0.004002226419621345, 0.03159090800027305, 0.003468596292426669, -0.008738194380550688, -0.014381333837107744, -0.02536077549693411, 0.007244029838141084, 0.0163024026675376, 0.013073940444575938, 0.0003318512964672315, 0.012393561822855151, 0.04378436027165999, 0.008938305794664009, 0.012967213674078961, -0.001547527578412134, -0.012280164920240411, -0.027428592821890075, 0.027455273350361128, -0.03423237717645283, 0.0020844928880810105, -0.017383003186162475, 0.0075441969593110685, 0.001002224254350096, 0.020024474224987352, -0.003698724465223117, 0.005052810878055011, -0.026508081062026834, 0.022786009504577077, 0.011006123119619973, 0.030550330136999863, -0.016342425322889282, -0.007444141252254407, 0.01809006326767687, -0.010685944670774147, -0.008171212661444641, -0.008191223989120484, 0.023252935516626463, 0.015328527988087145, -0.001466649316101276, -0.01278711358764148, -0.6928654741236796, -0.010178996003373077, 0.005683161646247466, -0.003535300174741322, 0.016075610724953223, 0.037620930952143784, 0.018476945831667986, -0.008838250087607349, -0.008524742702201838, 0.03201781135697076, -0.021158437663199445, -0.011879942092013766, -0.004592554998123391, -0.006870488935369322, -0.012120076161478774, -0.02054476315662395, -0.007757649103321194, -0.013580889111977006, -0.013387447829981448, 0.018917191315246315, 0.0032067840607482912, 0.0135542076521834, -0.016542536737002605, -0.014141200698965288, -0.0046759349092243664, 0.0014016130832313824, 0.009965544325024228, -0.007590889746780517, 0.009251814111392071, 0.019157325384711325, -0.03385883487669724, 0.002683159364560899, -0.0026031147523494424, 0.004692610705180051, 0.03465928053315053, -0.009578662692355662, -0.013600899508330298, -0.00969205866364785, 0.021225140847022185, 0.010178996003373077, -0.017623137255627485, -0.0025564221977106318, 0.008337971552324042, 0.01098611179194413, -0.006296836618484237, -0.0038921652815573997, 0.03087050765452314, -0.002134520741609341, 0.019610909269880076, 0.011979997799070427, -0.004752644222546304, -0.009912181405437016, 0.006370210400086016, 0.0004931910542469063, 0.000268482683938268, -0.014608126711014673, 0.011266267585438272, 0.0015975554319404646, 0.022732646584989864, 0.01874376042960405, 0.004812677274251279, 0.013153984823956756, -0.006263484560911591, -0.0193841173272957, -0.017623137255627485, 0.004589219932064508, -0.027481955741477288, 0.008591445886024576, 0.004008897017400384, -0.012907180622373985, 0.003226795155593496, 0.01005225883652281, -0.002841580823123733, -0.031110641723988145, 0.031324091539691894, 0.023946655333905328, 0.009445254462065079, -0.016462491426299235, -0.007437471120136643, 0.029803247400133785, 0.007770989833217997, 0.0011731526762950128, -0.026841598843785636, -0.006566986748140456, 0.01995776917851951, -0.007757649103321194, -0.03572654265018498, -0.004332410066643816, -0.012466936070118206, 0.004209008431513706, 0.02358645516103037, 0.005136190789155988, -0.007977771379449083, -0.0033835490811268895, 0.02269262392963818, -0.008451368454938782, -0.003528629809792921, 0.0006399393741500378, 0.025801020980512443, 0.009198450260482308, 0.002448028592676128, 0.008337971552324042, -0.007063929751703605, 0.01638244797824097, 0.020064495017693935, -0.0008654814818695668, 0.003638690947856865, 0.013087280708811464, 0.016168994437247015, -0.013560877784301165, -0.007864375408156895, -0.013207347743543967, -0.01831685707290635, 0.003565316933424448, -0.016222359219479333, -0.036847165824161546, 0.01941079971841186, -0.0015525304103310947, 0.007297393223389573, 0.0068438074755757155, 0.010499174452218903, 0.008037805362476612, 0.019424139982647387, -0.015835476655488213, 0.0016984449055118462, 0.008824909823371821, 0.005979993701358568, -0.03433910301562725, -0.007951089919655476, -0.011052815907089421, -0.008351312747882122, -0.007690945453837178, 0.0321779019783775, -0.019397457591531227, 0.004172321307882179, -0.0004298224708217726, 0.014314630653285004, 0.0020127864066780345, 0.015248483608706325, -0.018183448842615767, -0.014688171090395491, 0.017102848323990887, -0.01329406225504255, -0.010158984675697235, -0.005856591600567182, -0.02846917068516327, -0.015301846528293538, -0.0034719315913161884, 0.0017909963646900666, 0.0018960547872503694, -0.02366650047173374, -0.006056703014680505, -0.010685944670774147, 0.0010589224728268282, -0.003021681142391851, -0.011799897712632948, -0.00042565346362519185, -0.01882380574030742, 0.0041489749141474545, -0.005936635979948001, -0.008698172656521555, 0.0029366336982614336, -0.01083936329741802, -0.009045031633838435, -0.014074496583819996, -0.01599556541424985, -0.02774877033941335, 0.028762667674215488, -0.011813238908191026, -0.036526988306638274, -0.008884942875076797, 0.013060599249017858, -0.004589219932064508, -0.007991112575007162, 0.00583658027289134, -0.008791557300137899, -0.014954986619654106, 0.019437480246882913, 0.005062816541892933, -0.014114519239171683, -0.002239579280584963, 0.005382994525077483, 0.011099508694558871, 0.0014249593605507877, 0.004165650710103139, 0.009578662692355662, 0.02199890597500442, 0.011546423378932413, -0.0162090170925987, 0.008177882793562406, -0.009478606985299001, 0.0003062120157131961, -0.017769885750153595, 0.007437471120136643, -0.01152641205125657, 0.021238482973902816, -0.019610909269880076, 0.01795665690003139, 0.016809351334938667, 0.02565427248598633, 0.03137745632192421, 0.005079492337848618, 0.008878272742959034, -0.011873271959896002, 0.003698724465223117, -0.035939994328533835, -0.011379664488053012, -0.004492499291066729, 0.015608683781581286, 0.006556981084302535, 0.012480276334353732, -0.024240152322957547, -0.024453604001306396, 0.017116188588226416, 0.029029484134796654, 0.012453594874560128, -0.016675943104648084, 0.0045225158169192176, -0.012513627926265102, -0.0010163987507616195, 0.009758762778793142, -0.0024713749864108524, 0.00584325087067038, -0.003702059531281999, -0.013133973496280912, 0.018570331406606883, 0.02782881565011672, 0.03393888018740061, 0.026788235924198423, -0.02926961634161656, -0.01874376042960405, 0.003715400261178802, -0.0070505890218068015, 0.0001937536242964518, 0.009585332824473426, 0.017129528852461943, 0.02725516193624781, -0.022745986849225394, 0.023106188884745457, -0.0064135681214965825, 0.00695720391252918, 0.02602781292309682, 0.03220458250684855, -0.004685940107401012, 0.019143983257830694, -0.0024396906946982854, 0.024773781518829672, 0.003521959444844519, -0.0063168474804988035, 0.02508062063476252, -0.007931078591979633, 0.008237916776589933, 0.00365870204270207, 0.013927748089293887, 0.025120641427469104, -0.021385231468428925, -0.004185662037778982, 0.012967213674078961, 0.011533083114696885, 0.03313843453094732, 0.015968884885778797, 0.0036453613128052667, 0.0024063386371256396, -0.005399670786694444, 0.02283937242416429, -0.014474719412046642, -0.015021690734799397, 0.01347416234148003, -0.014514742067398327, -0.0101189629516681, 0.013334084910394235, -0.005779882287245246, 0.018770442820720205, 0.00505948147583405, 0.028015586799994514, 0.0149283051598605, 0.021105074743612232, 0.019931088650048456, 0.02934966165231993, 0.00681712601578211, -0.014261267733697793, -0.03367206745210965, 0.00016332002601171023, 0.015368549712116278, 0.015862157183959266, -0.0167293078868804, -0.01191996474736545, 0.004415789977744792, -0.0003514455080550759, 0.0033185129646723147, 0.0007562540521126832, 0.007510845367399699, 0.026361332567500725, -0.026761555395727367, -0.0006916347607078094, 0.019037257418656268, 0.009618684416384795, -0.007557537689207871, 0.008718183984197396, -0.006997226102219589, 0.02015788059263283, -0.006003339629432017, -0.008864931547400954, 0.008024464166918531, 0.03228462781755192, -0.006020015891048978, 0.0027331872180892296, -0.016996122484816464, -0.01606226859807259, -0.0073374154130799825, 0.003108395886721071, 0.002194554258975593, -0.02235910614787938, -0.0004385773393684645, 0.008124519873975193, -0.008851591283165428, -0.00012069214133982106, 0.008604787081582656, 0.01358755924409477, 0.0167293078868804, -0.017409685577278636, -0.013007236329430646, -0.01946416263799907, 0.010439141400513928, 0.04517179618092751, 0.038661508815416974, 0.0005052810761639692, -0.01081935290106473, 0.0027648715098017966, -0.021211800582786655, -0.031964450300028646, -0.02560090956639912, 0.011499730591462963, -0.005643139456557057, 0.002496388913175018, -0.004639247785592839, 0.016262380012185912, -0.005016123754423484, 0.009665377203854244, 0.008764875840344293, 0.0038488077929774707, 0.008884942875076797, -0.017022803013287516, -0.014247926538139713, 0.008184552925680169, 0.00468927563912117, 0.010132303215903629, 0.013640922163681983, 0.02804226732846557, -0.018410242647845246, 0.014247926538139713, 0.00111145162589932, -0.006493612500877401, -0.017903293980444178, -0.019277391488121277, 0.016662602840412558, 0.011366323292494932, 0.0142879491934914, -0.002062814260206365, 0.029483069882610513, -0.00607337881063619, -0.020277948558687888, 0.016462491426299235, 0.009078384157072355, 0.00500278302452668, 0.014594786446779145, -0.0007166486874719746, -0.013700955215386959, -0.012506957794147339, -0.0021878838940271915, -0.010972771527708603, -0.007197337516332912, -0.002694832561428261, -0.009678717468089772, 0.028495853076279425, -0.005896613790257592, -0.0014041144991908628, -0.009058372829396514, 0.020878282801027857, 0.02005115475345841, -0.004319069336747013, 0.007404119062563998, -0.006466931041083796, -0.016595899656589818, -0.030603693056587077, -0.01679601107070314, -0.001581713286084181, -0.01191996474736545, -0.013807681985883936, -0.030230150756831484, -0.027215141143541226, -0.006680383185093921, -0.014648149366366358, 0.0027782122396985995, -0.005079492337848618, -0.015835476655488213, -0.029723202089430415, -0.011332971700583562, 0.016822691599174194, -0.013754319066296723, -0.008884942875076797, 0.01558200232178768, 0.0056864967123063485, 0.027481955741477288, -0.010058928968640574, -0.023719863391320952, 0.008604787081582656, -0.014301289457726926, -0.0163024026675376, 0.020344651742510628, -0.0027948882684849224, -0.000513202149092111, 0.0035486409046381253, 0.01671596575999977, -0.006903840992941968, 0.005372989326900838, -0.0027331872180892296, -0.02910952758285492, 0.022158994733766056, -0.017729863094801908, 0.012166768948948222, 0.005172877912787515, -0.005196224306522239, -0.016195676828363172, -0.014688171090395491, 0.0004569208720803985, -0.00875820570822653, 0.004552532808432981, 0.010912737544681075, -0.00593330091388912, -0.0015200123521038073, 0.028655941835041065, -0.015675387896726577, -0.006106730868208836, 0.002976655887951843, -0.019010576890185215, 0.001254030938605871, -0.02039801466209784, -0.003992221221444699, 0.020878282801027857, -0.0279622220177622, 0.02780213325900056, -0.010158984675697235, -0.0221323123426499, 0.005342972335387074, -0.017209574163165313, 0.0008096170881152146, 0.02602781292309682, 0.020264606431807258, 0.03151086268956969, -0.004499169888845769, -0.0019944428448622708, -0.010405788877280006, 0.0010764321517125525, -0.004939414441101547, 0.003345194424465921, -0.008604787081582656, -0.009031691369602907, -0.02429351524254476, -0.01049250432010114, 0.004352421394319659, 0.013520855128949478, -0.005503061559809987, -0.009131747076659568, -0.02645471814243962, 0.0023813247103614743, 0.010359096089810556, -0.0037554226836998494, -0.015955542758898166, -0.027041710257898956, -0.02444026373707087, 0.006977214774543747, -0.020998348904437806, 0.010332414630016952, 0.008704842788639318, -0.0028966115085710246, -0.023079506493629297, -0.011433027407640224, 0.00779100116089384, -0.028709304754628275, 0.003908841310343723, 0.007517515499517462, 0.015742091080549317, 0.037300749709330304, 0.021518637836074404, -0.00505948147583405, 0.014968326883889632, 0.017769885750153595, -0.0014107848641392643, 0.007657593396264532, -0.006857148205472519, -0.0029232929683646307, -0.019397457591531227, 0.00745748198215121, 0.007770989833217997, 0.00807115695438798, 0.01412785950340721, -0.011252927321202744, 0.019824362810874033, 0.013847703709913069, 0.004302393540791328, 0.013120632300722834, -0.011879942092013766, -0.024186789403370334, -0.0017292954307096926, 0.016102291253424276, -0.013887726365264754, 0.005069487139671972, -0.026281287256797355, -0.0013549204121772525, 0.026014472658861292, 0.0019244038964887353, 0.024853826829533042, 0.012340198903267938, 0.018276834417554663, -0.002479712884388695, -0.007350756142976785, -0.0066837182511528025, 0.007450811850033446, -0.0149283051598605, 0.010679274538656384, -0.00828460863273683, -0.009758762778793142, 0.023813247103614744, -0.0013432473317252095, 0.012887169294698141, 0.0022312413826071206, 0.014608126711014673, 0.011593116166401862, 0.0045792142682265875, 0.009958874192906465, -0.0024263499648014826, -0.01412785950340721, 0.00023658995059702107, -0.023719863391320952, -0.02197222358388826, -0.006910511125059731, -0.007917738327744107, 0.01730295973810421, 0.015555320861994073, -0.0013449148647546503, 0.015475276482613255, -0.008504731374525995, -0.015742091080549317, 0.01278711358764148, -0.002212897820791357, 0.05384328830897801, 0.016969440093700303, -0.0022312413826071206, 0.01254031031738126, 0.0034102305409204957, -0.035753223178656035, 5.61249748940321e-05, -0.02082491801879554, 0.005182883576625437, 0.03404560602657503, 0.03756756616991147, -0.018957213970598002, -0.014007793399997257, 0.007817682620687445, 0.021572000755661618, 0.009618684416384795, -0.02177211216977494, -0.006223462371221182, 0.018476945831667986, -0.004605895728020193, -0.015688728160962104, -0.01195331633927682, -0.03759424669838252, 0.01802336008385413, 0.0006716236658626047, -0.0021995570908945536, -0.020584785811975634, -0.017062825668639203, -0.022092289687298212, 0.006096725204370914, -0.03599335911076615, 0.018450265303196933, 0.011546423378932413, -0.03423237717645283, -0.0024680396875213324, -0.0007120627970180337, -0.030977233493697562, 0.008651479869052105, 0.0038988356465058014, 0.02761536397176787, -0.020704851915385587, -0.0018893844223019677, 0.008084497218623508, 0.011072827234765265, -0.03479269062608622, 0.012246813328329042, -0.005896613790257592, 0.02450696692089361, -0.028015586799994514, -0.009058372829396514, 0.009632025611942874, 0.004282382213115486, 0.006570321814199339, -0.003501948349999314, -0.010078940296316416, -0.013387447829981448, -0.0027398575830376313, -0.003495277752220275, -0.0014132862800987447, 0.020384674397862314, 0.00532963160549027, -0.01570206842519763, -0.005553089413338317, -0.00580322868097997, -0.0053129558095345855, 0.0037087298962304002, -0.01247360620223597, -0.022185675262237112, -0.017836588933976334, 0.008337971552324042, -0.0010197339332358203, 0.023119529148980984, 0.0037487523187514477, -0.013053929116900094, 0.01640912850671202, 0.035806587960888356, -0.020584785811975634, 0.009251814111392071, -3.07723268452829e-05, -0.00528627434974098, -0.018570331406606883, 0.00972541025555922, 0.0015083391552364453, -0.020584785811975634, 0.0338855191304585, -0.019437480246882913, -0.02363981808061758, -0.01591552010354648, -0.009858818485849803, 0.01730295973810421, -0.007864375408156895, -0.0016700957962734802, 0.00551640228970679, 0.0009571991745330665, 0.01686271425452588, 0.013207347743543967, -0.0229861209186904, 0.022452491722818275, -0.002816566896359568, 0.009892170077761173, -0.00929850596753897, -0.010332414630016952, 0.0032818258410407873, 0.0006182606298600733, 0.01171985333325213, 0.006863818337590282, -0.029723202089430415, -0.01977099989128682, 0.008531412834319602, 0.01991774838581293, -0.00120733838396706, -0.00468927563912117, -0.023893292414318115, -0.006650366659241433, -0.004068930534766636, 9.057122005001454e-05, 0.0006824629797999275, -0.013120632300722834, -0.019264051223885748, -0.015008349539241317, -0.02437356055324813, 0.009825465962615881, -0.01962425139676071, 0.0016350763220867126, -0.029483069882610513, -0.01406115631958447, -0.01642246877094755, -0.025494183727224694, 0.00811784974185743, 0.0028732651148363, 0.028709304754628275, -0.011786557448397421, -0.02964315864137215, 9.223881310610429e-06, -0.03292498285259847, -0.01563536524137489, -0.024960552668707465, 0.0004590053465748591, 0.021211800582786655, 0.01902391715442074, -0.011513071787021044, 0.0324180341851974, 0.011272937717556036, 0.04994778586588599, -0.020651488995798373, -0.023959995598140854, 0.0288160305938027, -0.01099945298750221, 0.010405788877280006, 0.006897170395162928, -0.024253492587193073, -0.018450265303196933, 0.023626477816382052, -0.0008671490731066672, 0.01106615617132495, 0.015835476655488213, -0.0077443083734243905, -0.02934966165231993, 0.003528629809792921, 0.022319083492527692, 0.0072573710336991636, 0.0011272937717556036, 0.0031500858422715593, -0.00039063398943842424, 0.006430243917452267, 0.004012232083459266, -0.0026848268975903397, -0.003785439209552337, -0.0021328532085799004, 0.008077827086505745, -0.01846360556743246, -0.0072173483783474785, -0.029296298732732717, -0.00394552843397525, -0.017649819646743642, -0.013700955215386959, 0.019784340155522346, -0.009138417208777332, 0.002683159364560899, 0.02926961634161656, 0.010992781924061895, -0.020771555099208326, -0.011026134447295817, 0.02090496332949891, -0.01326071066313118, -0.010979441659826367, 0.003998891353562462, -0.014888282504508814, -0.003992221221444699, -0.0005407174918157565, -6.352492192260122e-05, -0.031137322252459198, 0.013133973496280912, -0.0043957786500689496, -0.009758762778793142, -0.0163024026675376, -0.009091724421307883, 0.01894387184371737, -0.025841043635864126, -0.013087280708811464, -0.012080053506127088, 0.017729863094801908, -0.015328527988087145, -0.004545862210653942, -0.012266824656004883, -0.00792440845986187, 0.016876054518761407, 0.02119846031855113, -0.016916077174113094, -0.0009563654080183461, 0.010539196176248038, 0.018063382739205814, -0.001827683488321594, 0.008564764426230971, 0.21622695994930743, 0.01236020929962123, 0.008711512920757081, 0.030550330136999863, -0.0008450534455593424, 0.032711531174249624, 0.008904954202752639, -0.012847147570669008, -0.00450250495490465, 0.02047805997280121, 0.018543649015490726, 0.010846034360858335, -0.0016409129205203936, -0.0021745431641303887, -0.010192337198931157, 0.0016467495189540747, -0.024320197633660917, -0.02552086425569575, -0.03634021715676048, -0.014207903882788028, 0.0004502504780281672, -0.029696521560959362, 0.006323518078277843, -0.010479163124543061, 0.022932757999103187, -0.02458701223159698, -0.011806568776073263, -0.008958317122339852, 0.020864940674147226, 0.018556991142371356, -0.014234585342581634, -0.003655366976643188, 0.019130642993595168, -0.007597559878898281, -0.026841598843785636, 4.705742935240515e-05, 0.024546989576245296, -0.022465831987053805, 0.033031708691772896, -0.013180666283750362, 0.0013507514631883313, -0.0124402546103246, -0.0023613136155162698, -0.01142635727552246, 0.006300171684543119, 0.026294629383677985, 0.010439141400513928, -0.019650931925231763, -0.005613122930704569, 0.0021995570908945536, -0.03329852515235406, -0.000862146299395366, 0.021385231468428925, 0.003935522770137329, 0.010332414630016952, -0.0048827164554554525, 0.013527526192389795, -0.005056146409775169, -0.005406340918812207, -0.002529740737917025, -0.017529751680688585, 0.025534204519931276, -0.02544082080763748, 0.020584785811975634, -0.024200129667605864, -0.0025864389563937575, -0.023332980827329833, -0.00482935353586824, 0.0028549215530205363, -0.015835476655488213, 0.005016123754423484, -0.012466936070118206, 0.010879385952769705, -8.859095181797912e-05, -0.012100064833802932, -0.023266277643507093, 0.02113175713472839, 0.03351197683070291, 0.028709304754628275, 0.02199890597500442, -0.015288505332735458, -0.005109509329362381, -0.01642246877094755, -0.04076934879572463, -0.024106744092666964, -0.03751420511296936, -0.007844364080481052, 0.001679267577181362, 0.0023679839804646714, -0.021158437663199445, -0.01763647751986301, -0.019330754407708487, -0.008751535576108766, -0.005066151607951814, 0.007430800522357604, 0.030763781815348713, -0.010479163124543061, 0.028655941835041065, -0.0013732639739930162, 0.012933862082167591, -0.03449919363703399, 0.030043381469598795, 0.01967761431634792, 0.007163985458760266, 0.002611452883157923, 0.005182883576625437, -0.026081175842684032, -0.0051928887748020815, 0.0005081993753808097, 0.005963317439741608, 0.019037257418656268, -0.009972214457141991, 0.014074496583819996, -0.013180666283750362, -0.005709843106041073, 0.015115075378415742, -0.004582549334285469, -0.020144540328397305, 0.008257927172943224, -0.01057254869948196, -0.0058465859367292615, -0.005956647307623844, -0.004118958388294966, 0.007864375408156895, -0.013153984823956756, 2.0884015105887622e-05, -0.02422681205872202, -0.0009063375544900155, 0.009011680041927065, -0.02177211216977494, 0.0032851609070996693, -0.005062816541892933, 0.02450696692089361, -0.0037354113560240064, -0.006870488935369322, -0.006963874044646943, 0.005596446669087608, 0.0026598129708261743, -0.03279157648495299, 0.021958883319652733, 0.005296280013578901, 0.001349917696673611, -0.006943863182632377, -0.002434687862779325, -0.01768984230209533, -0.015261823872941853, 0.0383413312978937, -0.01211340602936101, -0.012633694960997607, -0.007410789660343037, -0.021652046066364988, -0.009485277117416764, 0.0047793256823399095, 0.008357982879999885, 0.03265817011730751, 0.00013372022334551888, -0.01167316054578268, -0.04159647498064897, 0.017383003186162475, 0.003672042772598873, -0.03754088564144041, 0.005539748683441514, 0.03249807949590077, -0.03191108551779633, -0.019584228741409023, -0.007697615585954941, -0.1746038007148972, 0.027001687602547272, 0.012286835983680727, -0.011913294615247687, 0.020571443685095003, -0.011359653160377169, 0.03428574195868515, 0.005406340918812207, 0.012240143196211278, -0.0019260715459334954, -0.009098395484748199, -0.011419686212082145, -0.02486716709376857, -0.009105065616865962, 0.0008329634236422795, -0.00044441390869831587, -0.017049485404403677, -0.0032851609070996693, 0.01946416263799907, 0.024667055679655246, 0.009665377203854244, -0.010605900291393328, 0.028442490156692216, -0.020878282801027857, -0.0011764878587692137, -0.008898284070634876, 0.001218177697904383, 0.021451934652251665, 0.00018645790535818017, 0.013967770744645572, -0.000445247704316866, 0.004145639848088573, 0.012780443455523717, 0.015088393918622137, 0.012553650581616789, 0.004052254273149675, 0.018370219992493563, -0.005413011516591247, -0.009938862865230621, 0.019077280074007955, -0.001399111667271902, 0.023252935516626463, -0.0052562573582272155, -0.030283513676418697, 0.00436242705815758, 0.01648917381741539, 0.030977233493697562, -0.004729297828811579, 0.007157315326642502, -0.00691718172283877, 0.01817010857838024, -0.021718749250187727, -0.011259597453320508, -0.005379659459018601, 0.016515854345886448, -0.000769177898752126, -0.01662258018506087, 0.008884942875076797, -0.006857148205472519, -0.0117532049251635, 0.001163980895387131, -0.013594229376212534, 0.01591552010354648, -0.002694832561428261, -0.0061734345176928515, -0.012346869035385703, -0.040075628978445764, 0.0149283051598605, -0.009925521669672543, 0.008924965530428482, -0.0030583680331927403, -0.021038371559789493, -0.020064495017693935, -0.005379659459018601, 0.014528082331633854, 0.003862148522874274, -0.01658255939235429, 0.021158437663199445, -0.003406895242030976, -0.006633690397624472, -0.006640360995403512, 0.0180100198196186, 0.004375767788054383, 0.015675387896726577, 0.004799336544354476, 0.002076154990103168, -0.017569774336040272, -0.013434140617450897, 0.01736966292192695, 0.0025280732048875844, 0.03095055296522651, -0.035486410443365084, -0.014141200698965288, -0.007597559878898281, -0.0009205121091091985, 0.008811568627813742, 0.00041481412058403934, -0.0026564779047672927, -0.0037220706261272035, 0.004195667701616904, -0.007344085545197746, -0.013567547916418928, -0.035353000350429396, 0.016115631517659802, 0.02690830389025348, 0.0009913848239974541, -0.003578657663321251, 0.009585332824473426, 0.03719402387015588, 0.007590889746780517, -0.03569986212171393, -0.002049473530309562, 0.008331301420206279, 0.023039483838277613, 0.01953086582182181, 0.028229038478343366, 0.003528629809792921, -0.01875710255648468, 0.013180666283750362, 0.012240143196211278, 0.04429130893906106, 0.003715400261178802, -0.027081732913250642, 0.008017794034800768, 0.0036687077065399912, 0.012300176247916253, -0.05987330753555853, -0.03647362352440596, 0.018903849188365685, 0.0446915280419975, -0.011626467758313231, 0.02673487300461121, 0.004385773451892305, 0.024773781518829672, -0.010259040382753897, 0.0013599232440962132, -0.011879942092013766, -0.017182891772049153, -0.028735987145744435, -0.0070906112114972105, 0.008571435489671287, 0.006877159533148361, 0.0007650089497632049, 0.005072822205730854, -0.01099945298750221, 0.02473376072612309, 0.0010772660346425919, -0.010025577376729204, 0.014007793399997257, -0.02169206872171667, -0.01016565573913755, -0.006877159533148361, -0.018957213970598002, 0.0343124224871562, 0.005102838731583342, -0.01412785950340721, -0.016956099829464777, -0.008484720046850152, 0.01018566613549084, -0.013547536588743084, -0.005996669497314253, 0.008171212661444641, -0.03169763383944748, -0.01859701193507794, 0.032151221449906446, -0.018997234763304584, 0.01083936329741802, 0.028309081926401632, -0.0018993899697245702, -0.04015567428914913, 0.004599225130241154, -0.021105074743612232, 0.00250139151226334, 0.011039474711531343, 0.003435244467684661, -0.019797680419757872, -0.01614231390877596, 0.0090050099098093, -0.024413581345954713, 0.004539192078536178, 0.01815676831414471, -0.005856591600567182, 0.026361332567500725, 0.023879952150082588, -0.008184552925680169, 0.002568095394577994, -0.00695053331475014, -0.0018226806564026333, -0.010265711446194212, 0.026428035751323464, -0.02285271455104492, 0.004262371351100919, -0.013300733318482865, -0.0038854949166089985, 0.013300733318482865, -0.012253483460446805, 0.0017309629637391336, 0.0008271268252085984, -0.013360766370187842, -0.005929965847830238, -0.01700946274905199, 0.008678161328845711, -0.03463260000467947, -0.05237580336371691, 0.019490843166470127, -0.005899948856316474, -0.02234576402099875, -0.018556991142371356, 0.006143417991840363, -0.011099508694558871, 0.02450696692089361, 0.019077280074007955, 0.0020261271365748373, -0.0023896628411699547, 0.026361332567500725, -0.0500011506481183, 0.013887726365264754, 0.005603117266866648, 0.008518072570084073, -0.03343193151999954, -0.02235910614787938, 0.008938305794664009, 0.012660376420791214, -0.002633131511032568, 0.02015788059263283, -0.005276268685903058, -0.038661508815416974, -0.0139811110088811, -0.054803820861547836, 0.0167293078868804, -0.005503061559809987, -0.02113175713472839, -0.003538635240800204, 0.010972771527708603, -0.013287392122924787, -0.021091734479376706, -0.020264606431807258, 0.007063929751703605, -0.028789350065331648, -0.0038754894856017153, 0.006493612500877401, -0.009425243134389236, -0.015568661126229599, -0.026614806901201257, 0.03618012653535374, 0.008017794034800768, 0.023826589230495375, 0.018783783084955735, 0.014314630653285004, -0.008191223989120484, 0.01594220249466264, 0.011586446034284098, -0.014488059676282168, 0.014488059676282168, -0.01694275956522925, -0.0005052810761639692, -0.0285758983869828, -0.0074174597924608005, -0.003348529490524803, -0.030470284826296493, -0.0037620930486482506, 0.012106734965920695, -0.003365205519311126, 0.007297393223389573, -0.011372993424612697, 0.040982800474073475, 0.010239029986400605, 0.020958326249086123, -0.0059266303161100795, -0.03276489595648194, 0.008164542529326878, -0.022479172251289332, -0.01608895098918875, 0.0207582148349728, -0.025987790267745132, 0.001274875916381115, 0.037167343341684825, 0.005729854433716915, 0.034552554693976105, 0.005986663833476332, -0.02277266924034155, -0.00691718172283877, 0.0059666529714617654, -0.011486390327227437, 0.011553094442372729, 0.01312730336416315, 0.0015483613449268545, -0.013574218048536691, 0.036233491317586054, -0.0024563664906539703, 0.017289619473868683, -0.004532521480757138, 0.008164542529326878, 0.015688728160962104, -0.015301846528293538, -0.013247369467573102, 0.012893840358138457, -0.019437480246882913, -0.0142879491934914, -0.0068504776076934795, -0.003698724465223117, 0.021371889341548295, 0.029936653767779264, 0.023573114896794842, 0.003458590861419385, 0.01088605608488747, -0.0013082278575384416, 0.030043381469598795, 0.039328548104224786, 0.004899392251411137, -0.02910952758285492, 0.012313517443474333, 0.02398667798925701, 0.007297393223389573, -0.00397888002588662, 0.004025572813356069, -0.001917733531540334, 0.00897165831789793, -0.030577010665470916, 0.018410242647845246, 0.01723625655428147, 8.064382004827367e-06, -0.004195667701616904, -0.020718192179621113, 1.800480778937139e-05, -0.005372989326900838, 0.03167095331097643, 0.017569774336040272, 0.004775990150619752, 0.016916077174113094, -0.0019794345819360267, -0.017062825668639203, -0.009832137026056197, 0.007270711763595967, -0.030683736504645343, -0.03754088564144041, -0.014541423527191934, 0.014754875205540783, -0.0010639251883304698, -0.013847703709913069, 0.006473601638862835, 0.024093403828431437, -0.009338528622890654, 0.004655923581548524, -0.012920521817932063, 0.01363425203156422, -0.030977233493697562, 0.032257947289080866, -0.0007600061760519037, -0.005239581562271531, 0.03279157648495299, -0.01019900733104892, 0.03140413685039526, -0.0013115630400126425, 0.01754309380756922, -0.013514184996831715, 0.009625354548502559, 0.007817682620687445, 0.005156201651170554, 0.0229861209186904, -0.021411911996899978, -0.026761555395727367, -0.006216791773442142, -0.013500843801273636, -0.01440801529690135, 0.026294629383677985, -0.013240699335455337, 0.06456925563510384, 0.0060066751611521745, -0.012066713241891562, 0.009191780128364545, 0.006550310952184771, 0.022559217561992702, 0.00854475402987768, 0.021171777927434972, -0.008678161328845711, 0.004269041483218682, 0.038368011826364755, 0.00026639820944380745, 0.005369653795180679, -0.025214027002408, -0.04559869953762521, 0.019344094671944017, -0.015221801217590166, 0.008998339777691537, -0.0008221240514972972, 0.00695720391252918, 0.013674273755593352, 0.0199044062589323, 0.0071439745967457, 0.001460812717667595, -0.010339085693457267, -0.006390221727761858, 0.025027255852530204, -0.034125651337278406, -0.021065052088260545, -0.015862157183959266, 0.012827136242993165, 0.01103280457941358, -0.017996679555383074, -0.03380547381975513, 0.017342982393455896, -0.0019244038964887353, -0.015141756838209348, -0.009558651364679819, 0.0119666575348349, 0.004999447958467799, 0.019517525557586284, 0.03169763383944748, -0.022412469067466592, -0.013600899508330298, -0.00760423047667732, -0.02037133227098168, -0.014768216401098861, 0.006233468035059103, -0.013080610576693701]\n", | |
| "[[-0.0081512013337688, 0.012106734965920695, -0.014181222422994421, -0.02444026373707087, -0.005793223017142049, 0.028309081926401632, -0.015235142413148247, -0.008317961155970752, -0.012893840358138457, -0.02190552040006552, 0.007730967643527587, 0.023959995598140854, -0.012707069208260662, 0.027281844327363965, -0.0005903284038790674, 0.012166768948948222, 0.01946416263799907, -0.009592002956591189, 0.0037954448733902584, -0.015835476655488213, 0.00042607037598638186, 0.0017909963646900666, -0.016369105851360338, 0.005643139456557057, -0.01470151228595357, -0.01049250432010114, 0.017409685577278636, -0.036206810789115, 0.008678161328845711, -0.0078910568679505, 0.005709843106041073, -0.015461935287055174, -0.006250143831014788, -0.03802115378037043, -0.0030550329671338587, 0.002227906083717601, -0.0051528665851116725, -0.03738079502003367, 0.019197346177417904, -0.01708950805975536, -0.002593109321342159, 0.00032580625640487025, 0.002899946574629906, -0.012840476507228693, 0.002251252477452325, -0.014808238125127996, 0.02988329084819205, -0.030390239515593123, -0.008324631288088516, 0.028068949719581727, 0.016635922311941505, 0.012206790672977356, -0.025013915588294678, -0.0047859958144576735, -0.010619241486951408, 0.013180666283750362, 0.0028265725601974894, 0.017743205221682542, 0.0008563097009616849, -0.004765984952443107, -0.02637467283173625, 0.011653149218106838, -0.027455273350361128, 0.0012048369680075798, 0.0006236802868287346, -0.00699055550444055, -0.003266817345283905, 0.015622024045816812, 0.004042248609311754, 0.015888839575075427, 0.01917066564894685, 0.016822691599174194, 0.010245700118518369, 0.01383436344567754, 0.015782113735901, 0.00795776005177324, -0.013080610576693701, -0.017102848323990887, 0.010472492992425298, 0.0016817689931408425, 0.006607008937830866, -0.031083959332871988, -0.009451924594182842, 0.0013849371708603785, -0.002478045351359254, 0.007837693948363289, 0.014194563618552501, 0.03465928053315053, -0.02414676674801865, -0.015261823872941853, -0.0018360213862994364, 0.022559217561992702, 0.003271820177202866, 0.009525298841445897, -0.026614806901201257, 0.029589795721784936, 0.014594786446779145, 0.024093403828431437, 0.003431909168795141, -0.04015567428914913, 0.0030900523249053073, 0.008371324075557964, -0.0013607570106109338, 0.0005673990098170222, -0.022892735343751504, -0.004852699929602965, 0.01751641141645306, -0.002623126080025285, 0.01520846095335464, -0.006093390138312033, -0.012420243282648758, 0.015662045769845947, -0.0051461964529939085, -0.03628685237452816, 0.010505844584336668, -0.017836588933976334, -0.0007204007532035356, -0.020144540328397305, -0.016275722139066542, -0.0007616737672890041, -0.009405232738035946, 0.01650251408165092, 0.026281287256797355, -0.021011689168673336, 0.012400231954972914, 0.016475833553179865, -0.0054163465826501285, -0.03626017184605711, -0.010432470337073613, -0.0044524771013763195, 0.02694832468296006, 0.022172334998001583, 0.026267946992561825, 0.015315186792529065, -0.032257947289080866, 0.028442490156692216, -0.025254049657759688, 0.018570331406606883, -0.056351351117512306, -0.02514732381858526, 0.006170099451633969, 0.03996890313927134, -0.015755431344784843, -0.01658255939235429, -0.0033068397678049526, 0.009105065616865962, 0.019424139982647387, -0.021158437663199445, 0.02400001825349254, -0.01859701193507794, 0.006323518078277843, -0.004649252983769485, 0.010465822860307533, -0.005196224306522239, 0.004002226419621345, 0.03159090800027305, 0.003468596292426669, -0.008738194380550688, -0.014381333837107744, -0.02536077549693411, 0.007244029838141084, 0.0163024026675376, 0.013073940444575938, 0.0003318512964672315, 0.012393561822855151, 0.04378436027165999, 0.008938305794664009, 0.012967213674078961, -0.001547527578412134, -0.012280164920240411, -0.027428592821890075, 0.027455273350361128, -0.03423237717645283, 0.0020844928880810105, -0.017383003186162475, 0.0075441969593110685, 0.001002224254350096, 0.020024474224987352, -0.003698724465223117, 0.005052810878055011, -0.026508081062026834, 0.022786009504577077, 0.011006123119619973, 0.030550330136999863, -0.016342425322889282, -0.007444141252254407, 0.01809006326767687, -0.010685944670774147, -0.008171212661444641, -0.008191223989120484, 0.023252935516626463, 0.015328527988087145, -0.001466649316101276, -0.01278711358764148, -0.6928654741236796, -0.010178996003373077, 0.005683161646247466, -0.003535300174741322, 0.016075610724953223, 0.037620930952143784, 0.018476945831667986, -0.008838250087607349, -0.008524742702201838, 0.03201781135697076, -0.021158437663199445, -0.011879942092013766, -0.004592554998123391, -0.006870488935369322, -0.012120076161478774, -0.02054476315662395, -0.007757649103321194, -0.013580889111977006, -0.013387447829981448, 0.018917191315246315, 0.0032067840607482912, 0.0135542076521834, -0.016542536737002605, -0.014141200698965288, -0.0046759349092243664, 0.0014016130832313824, 0.009965544325024228, -0.007590889746780517, 0.009251814111392071, 0.019157325384711325, -0.03385883487669724, 0.002683159364560899, -0.0026031147523494424, 0.004692610705180051, 0.03465928053315053, -0.009578662692355662, -0.013600899508330298, -0.00969205866364785, 0.021225140847022185, 0.010178996003373077, -0.017623137255627485, -0.0025564221977106318, 0.008337971552324042, 0.01098611179194413, -0.006296836618484237, -0.0038921652815573997, 0.03087050765452314, -0.002134520741609341, 0.019610909269880076, 0.011979997799070427, -0.004752644222546304, -0.009912181405437016, 0.006370210400086016, 0.0004931910542469063, 0.000268482683938268, -0.014608126711014673, 0.011266267585438272, 0.0015975554319404646, 0.022732646584989864, 0.01874376042960405, 0.004812677274251279, 0.013153984823956756, -0.006263484560911591, -0.0193841173272957, -0.017623137255627485, 0.004589219932064508, -0.027481955741477288, 0.008591445886024576, 0.004008897017400384, -0.012907180622373985, 0.003226795155593496, 0.01005225883652281, -0.002841580823123733, -0.031110641723988145, 0.031324091539691894, 0.023946655333905328, 0.009445254462065079, -0.016462491426299235, -0.007437471120136643, 0.029803247400133785, 0.007770989833217997, 0.0011731526762950128, -0.026841598843785636, -0.006566986748140456, 0.01995776917851951, -0.007757649103321194, -0.03572654265018498, -0.004332410066643816, -0.012466936070118206, 0.004209008431513706, 0.02358645516103037, 0.005136190789155988, -0.007977771379449083, -0.0033835490811268895, 0.02269262392963818, -0.008451368454938782, -0.003528629809792921, 0.0006399393741500378, 0.025801020980512443, 0.009198450260482308, 0.002448028592676128, 0.008337971552324042, -0.007063929751703605, 0.01638244797824097, 0.020064495017693935, -0.0008654814818695668, 0.003638690947856865, 0.013087280708811464, 0.016168994437247015, -0.013560877784301165, -0.007864375408156895, -0.013207347743543967, -0.01831685707290635, 0.003565316933424448, -0.016222359219479333, -0.036847165824161546, 0.01941079971841186, -0.0015525304103310947, 0.007297393223389573, 0.0068438074755757155, 0.010499174452218903, 0.008037805362476612, 0.019424139982647387, -0.015835476655488213, 0.0016984449055118462, 0.008824909823371821, 0.005979993701358568, -0.03433910301562725, -0.007951089919655476, -0.011052815907089421, -0.008351312747882122, -0.007690945453837178, 0.0321779019783775, -0.019397457591531227, 0.004172321307882179, -0.0004298224708217726, 0.014314630653285004, 0.0020127864066780345, 0.015248483608706325, -0.018183448842615767, -0.014688171090395491, 0.017102848323990887, -0.01329406225504255, -0.010158984675697235, -0.005856591600567182, -0.02846917068516327, -0.015301846528293538, -0.0034719315913161884, 0.0017909963646900666, 0.0018960547872503694, -0.02366650047173374, -0.006056703014680505, -0.010685944670774147, 0.0010589224728268282, -0.003021681142391851, -0.011799897712632948, -0.00042565346362519185, -0.01882380574030742, 0.0041489749141474545, -0.005936635979948001, -0.008698172656521555, 0.0029366336982614336, -0.01083936329741802, -0.009045031633838435, -0.014074496583819996, -0.01599556541424985, -0.02774877033941335, 0.028762667674215488, -0.011813238908191026, -0.036526988306638274, -0.008884942875076797, 0.013060599249017858, -0.004589219932064508, -0.007991112575007162, 0.00583658027289134, -0.008791557300137899, -0.014954986619654106, 0.019437480246882913, 0.005062816541892933, -0.014114519239171683, -0.002239579280584963, 0.005382994525077483, 0.011099508694558871, 0.0014249593605507877, 0.004165650710103139, 0.009578662692355662, 0.02199890597500442, 0.011546423378932413, -0.0162090170925987, 0.008177882793562406, -0.009478606985299001, 0.0003062120157131961, -0.017769885750153595, 0.007437471120136643, -0.01152641205125657, 0.021238482973902816, -0.019610909269880076, 0.01795665690003139, 0.016809351334938667, 0.02565427248598633, 0.03137745632192421, 0.005079492337848618, 0.008878272742959034, -0.011873271959896002, 0.003698724465223117, -0.035939994328533835, -0.011379664488053012, -0.004492499291066729, 0.015608683781581286, 0.006556981084302535, 0.012480276334353732, -0.024240152322957547, -0.024453604001306396, 0.017116188588226416, 0.029029484134796654, 0.012453594874560128, -0.016675943104648084, 0.0045225158169192176, -0.012513627926265102, -0.0010163987507616195, 0.009758762778793142, -0.0024713749864108524, 0.00584325087067038, -0.003702059531281999, -0.013133973496280912, 0.018570331406606883, 0.02782881565011672, 0.03393888018740061, 0.026788235924198423, -0.02926961634161656, -0.01874376042960405, 0.003715400261178802, -0.0070505890218068015, 0.0001937536242964518, 0.009585332824473426, 0.017129528852461943, 0.02725516193624781, -0.022745986849225394, 0.023106188884745457, -0.0064135681214965825, 0.00695720391252918, 0.02602781292309682, 0.03220458250684855, -0.004685940107401012, 0.019143983257830694, -0.0024396906946982854, 0.024773781518829672, 0.003521959444844519, -0.0063168474804988035, 0.02508062063476252, -0.007931078591979633, 0.008237916776589933, 0.00365870204270207, 0.013927748089293887, 0.025120641427469104, -0.021385231468428925, -0.004185662037778982, 0.012967213674078961, 0.011533083114696885, 0.03313843453094732, 0.015968884885778797, 0.0036453613128052667, 0.0024063386371256396, -0.005399670786694444, 0.02283937242416429, -0.014474719412046642, -0.015021690734799397, 0.01347416234148003, -0.014514742067398327, -0.0101189629516681, 0.013334084910394235, -0.005779882287245246, 0.018770442820720205, 0.00505948147583405, 0.028015586799994514, 0.0149283051598605, 0.021105074743612232, 0.019931088650048456, 0.02934966165231993, 0.00681712601578211, -0.014261267733697793, -0.03367206745210965, 0.00016332002601171023, 0.015368549712116278, 0.015862157183959266, -0.0167293078868804, -0.01191996474736545, 0.004415789977744792, -0.0003514455080550759, 0.0033185129646723147, 0.0007562540521126832, 0.007510845367399699, 0.026361332567500725, -0.026761555395727367, -0.0006916347607078094, 0.019037257418656268, 0.009618684416384795, -0.007557537689207871, 0.008718183984197396, -0.006997226102219589, 0.02015788059263283, -0.006003339629432017, -0.008864931547400954, 0.008024464166918531, 0.03228462781755192, -0.006020015891048978, 0.0027331872180892296, -0.016996122484816464, -0.01606226859807259, -0.0073374154130799825, 0.003108395886721071, 0.002194554258975593, -0.02235910614787938, -0.0004385773393684645, 0.008124519873975193, -0.008851591283165428, -0.00012069214133982106, 0.008604787081582656, 0.01358755924409477, 0.0167293078868804, -0.017409685577278636, -0.013007236329430646, -0.01946416263799907, 0.010439141400513928, 0.04517179618092751, 0.038661508815416974, 0.0005052810761639692, -0.01081935290106473, 0.0027648715098017966, -0.021211800582786655, -0.031964450300028646, -0.02560090956639912, 0.011499730591462963, -0.005643139456557057, 0.002496388913175018, -0.004639247785592839, 0.016262380012185912, -0.005016123754423484, 0.009665377203854244, 0.008764875840344293, 0.0038488077929774707, 0.008884942875076797, -0.017022803013287516, -0.014247926538139713, 0.008184552925680169, 0.00468927563912117, 0.010132303215903629, 0.013640922163681983, 0.02804226732846557, -0.018410242647845246, 0.014247926538139713, 0.00111145162589932, -0.006493612500877401, -0.017903293980444178, -0.019277391488121277, 0.016662602840412558, 0.011366323292494932, 0.0142879491934914, -0.002062814260206365, 0.029483069882610513, -0.00607337881063619, -0.020277948558687888, 0.016462491426299235, 0.009078384157072355, 0.00500278302452668, 0.014594786446779145, -0.0007166486874719746, -0.013700955215386959, -0.012506957794147339, -0.0021878838940271915, -0.010972771527708603, -0.007197337516332912, -0.002694832561428261, -0.009678717468089772, 0.028495853076279425, -0.005896613790257592, -0.0014041144991908628, -0.009058372829396514, 0.020878282801027857, 0.02005115475345841, -0.004319069336747013, 0.007404119062563998, -0.006466931041083796, -0.016595899656589818, -0.030603693056587077, -0.01679601107070314, -0.001581713286084181, -0.01191996474736545, -0.013807681985883936, -0.030230150756831484, -0.027215141143541226, -0.006680383185093921, -0.014648149366366358, 0.0027782122396985995, -0.005079492337848618, -0.015835476655488213, -0.029723202089430415, -0.011332971700583562, 0.016822691599174194, -0.013754319066296723, -0.008884942875076797, 0.01558200232178768, 0.0056864967123063485, 0.027481955741477288, -0.010058928968640574, -0.023719863391320952, 0.008604787081582656, -0.014301289457726926, -0.0163024026675376, 0.020344651742510628, -0.0027948882684849224, -0.000513202149092111, 0.0035486409046381253, 0.01671596575999977, -0.006903840992941968, 0.005372989326900838, -0.0027331872180892296, -0.02910952758285492, 0.022158994733766056, -0.017729863094801908, 0.012166768948948222, 0.005172877912787515, -0.005196224306522239, -0.016195676828363172, -0.014688171090395491, 0.0004569208720803985, -0.00875820570822653, 0.004552532808432981, 0.010912737544681075, -0.00593330091388912, -0.0015200123521038073, 0.028655941835041065, -0.015675387896726577, -0.006106730868208836, 0.002976655887951843, -0.019010576890185215, 0.001254030938605871, -0.02039801466209784, -0.003992221221444699, 0.020878282801027857, -0.0279622220177622, 0.02780213325900056, -0.010158984675697235, -0.0221323123426499, 0.005342972335387074, -0.017209574163165313, 0.0008096170881152146, 0.02602781292309682, 0.020264606431807258, 0.03151086268956969, -0.004499169888845769, -0.0019944428448622708, -0.010405788877280006, 0.0010764321517125525, -0.004939414441101547, 0.003345194424465921, -0.008604787081582656, -0.009031691369602907, -0.02429351524254476, -0.01049250432010114, 0.004352421394319659, 0.013520855128949478, -0.005503061559809987, -0.009131747076659568, -0.02645471814243962, 0.0023813247103614743, 0.010359096089810556, -0.0037554226836998494, -0.015955542758898166, -0.027041710257898956, -0.02444026373707087, 0.006977214774543747, -0.020998348904437806, 0.010332414630016952, 0.008704842788639318, -0.0028966115085710246, -0.023079506493629297, -0.011433027407640224, 0.00779100116089384, -0.028709304754628275, 0.003908841310343723, 0.007517515499517462, 0.015742091080549317, 0.037300749709330304, 0.021518637836074404, -0.00505948147583405, 0.014968326883889632, 0.017769885750153595, -0.0014107848641392643, 0.007657593396264532, -0.006857148205472519, -0.0029232929683646307, -0.019397457591531227, 0.00745748198215121, 0.007770989833217997, 0.00807115695438798, 0.01412785950340721, -0.011252927321202744, 0.019824362810874033, 0.013847703709913069, 0.004302393540791328, 0.013120632300722834, -0.011879942092013766, -0.024186789403370334, -0.0017292954307096926, 0.016102291253424276, -0.013887726365264754, 0.005069487139671972, -0.026281287256797355, -0.0013549204121772525, 0.026014472658861292, 0.0019244038964887353, 0.024853826829533042, 0.012340198903267938, 0.018276834417554663, -0.002479712884388695, -0.007350756142976785, -0.0066837182511528025, 0.007450811850033446, -0.0149283051598605, 0.010679274538656384, -0.00828460863273683, -0.009758762778793142, 0.023813247103614744, -0.0013432473317252095, 0.012887169294698141, 0.0022312413826071206, 0.014608126711014673, 0.011593116166401862, 0.0045792142682265875, 0.009958874192906465, -0.0024263499648014826, -0.01412785950340721, 0.00023658995059702107, -0.023719863391320952, -0.02197222358388826, -0.006910511125059731, -0.007917738327744107, 0.01730295973810421, 0.015555320861994073, -0.0013449148647546503, 0.015475276482613255, -0.008504731374525995, -0.015742091080549317, 0.01278711358764148, -0.002212897820791357, 0.05384328830897801, 0.016969440093700303, -0.0022312413826071206, 0.01254031031738126, 0.0034102305409204957, -0.035753223178656035, 5.61249748940321e-05, -0.02082491801879554, 0.005182883576625437, 0.03404560602657503, 0.03756756616991147, -0.018957213970598002, -0.014007793399997257, 0.007817682620687445, 0.021572000755661618, 0.009618684416384795, -0.02177211216977494, -0.006223462371221182, 0.018476945831667986, -0.004605895728020193, -0.015688728160962104, -0.01195331633927682, -0.03759424669838252, 0.01802336008385413, 0.0006716236658626047, -0.0021995570908945536, -0.020584785811975634, -0.017062825668639203, -0.022092289687298212, 0.006096725204370914, -0.03599335911076615, 0.018450265303196933, 0.011546423378932413, -0.03423237717645283, -0.0024680396875213324, -0.0007120627970180337, -0.030977233493697562, 0.008651479869052105, 0.0038988356465058014, 0.02761536397176787, -0.020704851915385587, -0.0018893844223019677, 0.008084497218623508, 0.011072827234765265, -0.03479269062608622, 0.012246813328329042, -0.005896613790257592, 0.02450696692089361, -0.028015586799994514, -0.009058372829396514, 0.009632025611942874, 0.004282382213115486, 0.006570321814199339, -0.003501948349999314, -0.010078940296316416, -0.013387447829981448, -0.0027398575830376313, -0.003495277752220275, -0.0014132862800987447, 0.020384674397862314, 0.00532963160549027, -0.01570206842519763, -0.005553089413338317, -0.00580322868097997, -0.0053129558095345855, 0.0037087298962304002, -0.01247360620223597, -0.022185675262237112, -0.017836588933976334, 0.008337971552324042, -0.0010197339332358203, 0.023119529148980984, 0.0037487523187514477, -0.013053929116900094, 0.01640912850671202, 0.035806587960888356, -0.020584785811975634, 0.009251814111392071, -3.07723268452829e-05, -0.00528627434974098, -0.018570331406606883, 0.00972541025555922, 0.0015083391552364453, -0.020584785811975634, 0.0338855191304585, -0.019437480246882913, -0.02363981808061758, -0.01591552010354648, -0.009858818485849803, 0.01730295973810421, -0.007864375408156895, -0.0016700957962734802, 0.00551640228970679, 0.0009571991745330665, 0.01686271425452588, 0.013207347743543967, -0.0229861209186904, 0.022452491722818275, -0.002816566896359568, 0.009892170077761173, -0.00929850596753897, -0.010332414630016952, 0.0032818258410407873, 0.0006182606298600733, 0.01171985333325213, 0.006863818337590282, -0.029723202089430415, -0.01977099989128682, 0.008531412834319602, 0.01991774838581293, -0.00120733838396706, -0.00468927563912117, -0.023893292414318115, -0.006650366659241433, -0.004068930534766636, 9.057122005001454e-05, 0.0006824629797999275, -0.013120632300722834, -0.019264051223885748, -0.015008349539241317, -0.02437356055324813, 0.009825465962615881, -0.01962425139676071, 0.0016350763220867126, -0.029483069882610513, -0.01406115631958447, -0.01642246877094755, -0.025494183727224694, 0.00811784974185743, 0.0028732651148363, 0.028709304754628275, -0.011786557448397421, -0.02964315864137215, 9.223881310610429e-06, -0.03292498285259847, -0.01563536524137489, -0.024960552668707465, 0.0004590053465748591, 0.021211800582786655, 0.01902391715442074, -0.011513071787021044, 0.0324180341851974, 0.011272937717556036, 0.04994778586588599, -0.020651488995798373, -0.023959995598140854, 0.0288160305938027, -0.01099945298750221, 0.010405788877280006, 0.006897170395162928, -0.024253492587193073, -0.018450265303196933, 0.023626477816382052, -0.0008671490731066672, 0.01106615617132495, 0.015835476655488213, -0.0077443083734243905, -0.02934966165231993, 0.003528629809792921, 0.022319083492527692, 0.0072573710336991636, 0.0011272937717556036, 0.0031500858422715593, -0.00039063398943842424, 0.006430243917452267, 0.004012232083459266, -0.0026848268975903397, -0.003785439209552337, -0.0021328532085799004, 0.008077827086505745, -0.01846360556743246, -0.0072173483783474785, -0.029296298732732717, -0.00394552843397525, -0.017649819646743642, -0.013700955215386959, 0.019784340155522346, -0.009138417208777332, 0.002683159364560899, 0.02926961634161656, 0.010992781924061895, -0.020771555099208326, -0.011026134447295817, 0.02090496332949891, -0.01326071066313118, -0.010979441659826367, 0.003998891353562462, -0.014888282504508814, -0.003992221221444699, -0.0005407174918157565, -6.352492192260122e-05, -0.031137322252459198, 0.013133973496280912, -0.0043957786500689496, -0.009758762778793142, -0.0163024026675376, -0.009091724421307883, 0.01894387184371737, -0.025841043635864126, -0.013087280708811464, -0.012080053506127088, 0.017729863094801908, -0.015328527988087145, -0.004545862210653942, -0.012266824656004883, -0.00792440845986187, 0.016876054518761407, 0.02119846031855113, -0.016916077174113094, -0.0009563654080183461, 0.010539196176248038, 0.018063382739205814, -0.001827683488321594, 0.008564764426230971, 0.21622695994930743, 0.01236020929962123, 0.008711512920757081, 0.030550330136999863, -0.0008450534455593424, 0.032711531174249624, 0.008904954202752639, -0.012847147570669008, -0.00450250495490465, 0.02047805997280121, 0.018543649015490726, 0.010846034360858335, -0.0016409129205203936, -0.0021745431641303887, -0.010192337198931157, 0.0016467495189540747, -0.024320197633660917, -0.02552086425569575, -0.03634021715676048, -0.014207903882788028, 0.0004502504780281672, -0.029696521560959362, 0.006323518078277843, -0.010479163124543061, 0.022932757999103187, -0.02458701223159698, -0.011806568776073263, -0.008958317122339852, 0.020864940674147226, 0.018556991142371356, -0.014234585342581634, -0.003655366976643188, 0.019130642993595168, -0.007597559878898281, -0.026841598843785636, 4.705742935240515e-05, 0.024546989576245296, -0.022465831987053805, 0.033031708691772896, -0.013180666283750362, 0.0013507514631883313, -0.0124402546103246, -0.0023613136155162698, -0.01142635727552246, 0.006300171684543119, 0.026294629383677985, 0.010439141400513928, -0.019650931925231763, -0.005613122930704569, 0.0021995570908945536, -0.03329852515235406, -0.000862146299395366, 0.021385231468428925, 0.003935522770137329, 0.010332414630016952, -0.0048827164554554525, 0.013527526192389795, -0.005056146409775169, -0.005406340918812207, -0.002529740737917025, -0.017529751680688585, 0.025534204519931276, -0.02544082080763748, 0.020584785811975634, -0.024200129667605864, -0.0025864389563937575, -0.023332980827329833, -0.00482935353586824, 0.0028549215530205363, -0.015835476655488213, 0.005016123754423484, -0.012466936070118206, 0.010879385952769705, -8.859095181797912e-05, -0.012100064833802932, -0.023266277643507093, 0.02113175713472839, 0.03351197683070291, 0.028709304754628275, 0.02199890597500442, -0.015288505332735458, -0.005109509329362381, -0.01642246877094755, -0.04076934879572463, -0.024106744092666964, -0.03751420511296936, -0.007844364080481052, 0.001679267577181362, 0.0023679839804646714, -0.021158437663199445, -0.01763647751986301, -0.019330754407708487, -0.008751535576108766, -0.005066151607951814, 0.007430800522357604, 0.030763781815348713, -0.010479163124543061, 0.028655941835041065, -0.0013732639739930162, 0.012933862082167591, -0.03449919363703399, 0.030043381469598795, 0.01967761431634792, 0.007163985458760266, 0.002611452883157923, 0.005182883576625437, -0.026081175842684032, -0.0051928887748020815, 0.0005081993753808097, 0.005963317439741608, 0.019037257418656268, -0.009972214457141991, 0.014074496583819996, -0.013180666283750362, -0.005709843106041073, 0.015115075378415742, -0.004582549334285469, -0.020144540328397305, 0.008257927172943224, -0.01057254869948196, -0.0058465859367292615, -0.005956647307623844, -0.004118958388294966, 0.007864375408156895, -0.013153984823956756, 2.0884015105887622e-05, -0.02422681205872202, -0.0009063375544900155, 0.009011680041927065, -0.02177211216977494, 0.0032851609070996693, -0.005062816541892933, 0.02450696692089361, -0.0037354113560240064, -0.006870488935369322, -0.006963874044646943, 0.005596446669087608, 0.0026598129708261743, -0.03279157648495299, 0.021958883319652733, 0.005296280013578901, 0.001349917696673611, -0.006943863182632377, -0.002434687862779325, -0.01768984230209533, -0.015261823872941853, 0.0383413312978937, -0.01211340602936101, -0.012633694960997607, -0.007410789660343037, -0.021652046066364988, -0.009485277117416764, 0.0047793256823399095, 0.008357982879999885, 0.03265817011730751, 0.00013372022334551888, -0.01167316054578268, -0.04159647498064897, 0.017383003186162475, 0.003672042772598873, -0.03754088564144041, 0.005539748683441514, 0.03249807949590077, -0.03191108551779633, -0.019584228741409023, -0.007697615585954941, -0.1746038007148972, 0.027001687602547272, 0.012286835983680727, -0.011913294615247687, 0.020571443685095003, -0.011359653160377169, 0.03428574195868515, 0.005406340918812207, 0.012240143196211278, -0.0019260715459334954, -0.009098395484748199, -0.011419686212082145, -0.02486716709376857, -0.009105065616865962, 0.0008329634236422795, -0.00044441390869831587, -0.017049485404403677, -0.0032851609070996693, 0.01946416263799907, 0.024667055679655246, 0.009665377203854244, -0.010605900291393328, 0.028442490156692216, -0.020878282801027857, -0.0011764878587692137, -0.008898284070634876, 0.001218177697904383, 0.021451934652251665, 0.00018645790535818017, 0.013967770744645572, -0.000445247704316866, 0.004145639848088573, 0.012780443455523717, 0.015088393918622137, 0.012553650581616789, 0.004052254273149675, 0.018370219992493563, -0.005413011516591247, -0.009938862865230621, 0.019077280074007955, -0.001399111667271902, 0.023252935516626463, -0.0052562573582272155, -0.030283513676418697, 0.00436242705815758, 0.01648917381741539, 0.030977233493697562, -0.004729297828811579, 0.007157315326642502, -0.00691718172283877, 0.01817010857838024, -0.021718749250187727, -0.011259597453320508, -0.005379659459018601, 0.016515854345886448, -0.000769177898752126, -0.01662258018506087, 0.008884942875076797, -0.006857148205472519, -0.0117532049251635, 0.001163980895387131, -0.013594229376212534, 0.01591552010354648, -0.002694832561428261, -0.0061734345176928515, -0.012346869035385703, -0.040075628978445764, 0.0149283051598605, -0.009925521669672543, 0.008924965530428482, -0.0030583680331927403, -0.021038371559789493, -0.020064495017693935, -0.005379659459018601, 0.014528082331633854, 0.003862148522874274, -0.01658255939235429, 0.021158437663199445, -0.003406895242030976, -0.006633690397624472, -0.006640360995403512, 0.0180100198196186, 0.004375767788054383, 0.015675387896726577, 0.004799336544354476, 0.002076154990103168, -0.017569774336040272, -0.013434140617450897, 0.01736966292192695, 0.0025280732048875844, 0.03095055296522651, -0.035486410443365084, -0.014141200698965288, -0.007597559878898281, -0.0009205121091091985, 0.008811568627813742, 0.00041481412058403934, -0.0026564779047672927, -0.0037220706261272035, 0.004195667701616904, -0.007344085545197746, -0.013567547916418928, -0.035353000350429396, 0.016115631517659802, 0.02690830389025348, 0.0009913848239974541, -0.003578657663321251, 0.009585332824473426, 0.03719402387015588, 0.007590889746780517, -0.03569986212171393, -0.002049473530309562, 0.008331301420206279, 0.023039483838277613, 0.01953086582182181, 0.028229038478343366, 0.003528629809792921, -0.01875710255648468, 0.013180666283750362, 0.012240143196211278, 0.04429130893906106, 0.003715400261178802, -0.027081732913250642, 0.008017794034800768, 0.0036687077065399912, 0.012300176247916253, -0.05987330753555853, -0.03647362352440596, 0.018903849188365685, 0.0446915280419975, -0.011626467758313231, 0.02673487300461121, 0.004385773451892305, 0.024773781518829672, -0.010259040382753897, 0.0013599232440962132, -0.011879942092013766, -0.017182891772049153, -0.028735987145744435, -0.0070906112114972105, 0.008571435489671287, 0.006877159533148361, 0.0007650089497632049, 0.005072822205730854, -0.01099945298750221, 0.02473376072612309, 0.0010772660346425919, -0.010025577376729204, 0.014007793399997257, -0.02169206872171667, -0.01016565573913755, -0.006877159533148361, -0.018957213970598002, 0.0343124224871562, 0.005102838731583342, -0.01412785950340721, -0.016956099829464777, -0.008484720046850152, 0.01018566613549084, -0.013547536588743084, -0.005996669497314253, 0.008171212661444641, -0.03169763383944748, -0.01859701193507794, 0.032151221449906446, -0.018997234763304584, 0.01083936329741802, 0.028309081926401632, -0.0018993899697245702, -0.04015567428914913, 0.004599225130241154, -0.021105074743612232, 0.00250139151226334, 0.011039474711531343, 0.003435244467684661, -0.019797680419757872, -0.01614231390877596, 0.0090050099098093, -0.024413581345954713, 0.004539192078536178, 0.01815676831414471, -0.005856591600567182, 0.026361332567500725, 0.023879952150082588, -0.008184552925680169, 0.002568095394577994, -0.00695053331475014, -0.0018226806564026333, -0.010265711446194212, 0.026428035751323464, -0.02285271455104492, 0.004262371351100919, -0.013300733318482865, -0.0038854949166089985, 0.013300733318482865, -0.012253483460446805, 0.0017309629637391336, 0.0008271268252085984, -0.013360766370187842, -0.005929965847830238, -0.01700946274905199, 0.008678161328845711, -0.03463260000467947, -0.05237580336371691, 0.019490843166470127, -0.005899948856316474, -0.02234576402099875, -0.018556991142371356, 0.006143417991840363, -0.011099508694558871, 0.02450696692089361, 0.019077280074007955, 0.0020261271365748373, -0.0023896628411699547, 0.026361332567500725, -0.0500011506481183, 0.013887726365264754, 0.005603117266866648, 0.008518072570084073, -0.03343193151999954, -0.02235910614787938, 0.008938305794664009, 0.012660376420791214, -0.002633131511032568, 0.02015788059263283, -0.005276268685903058, -0.038661508815416974, -0.0139811110088811, -0.054803820861547836, 0.0167293078868804, -0.005503061559809987, -0.02113175713472839, -0.003538635240800204, 0.010972771527708603, -0.013287392122924787, -0.021091734479376706, -0.020264606431807258, 0.007063929751703605, -0.028789350065331648, -0.0038754894856017153, 0.006493612500877401, -0.009425243134389236, -0.015568661126229599, -0.026614806901201257, 0.03618012653535374, 0.008017794034800768, 0.023826589230495375, 0.018783783084955735, 0.014314630653285004, -0.008191223989120484, 0.01594220249466264, 0.011586446034284098, -0.014488059676282168, 0.014488059676282168, -0.01694275956522925, -0.0005052810761639692, -0.0285758983869828, -0.0074174597924608005, -0.003348529490524803, -0.030470284826296493, -0.0037620930486482506, 0.012106734965920695, -0.003365205519311126, 0.007297393223389573, -0.011372993424612697, 0.040982800474073475, 0.010239029986400605, 0.020958326249086123, -0.0059266303161100795, -0.03276489595648194, 0.008164542529326878, -0.022479172251289332, -0.01608895098918875, 0.0207582148349728, -0.025987790267745132, 0.001274875916381115, 0.037167343341684825, 0.005729854433716915, 0.034552554693976105, 0.005986663833476332, -0.02277266924034155, -0.00691718172283877, 0.0059666529714617654, -0.011486390327227437, 0.011553094442372729, 0.01312730336416315, 0.0015483613449268545, -0.013574218048536691, 0.036233491317586054, -0.0024563664906539703, 0.017289619473868683, -0.004532521480757138, 0.008164542529326878, 0.015688728160962104, -0.015301846528293538, -0.013247369467573102, 0.012893840358138457, -0.019437480246882913, -0.0142879491934914, -0.0068504776076934795, -0.003698724465223117, 0.021371889341548295, 0.029936653767779264, 0.023573114896794842, 0.003458590861419385, 0.01088605608488747, -0.0013082278575384416, 0.030043381469598795, 0.039328548104224786, 0.004899392251411137, -0.02910952758285492, 0.012313517443474333, 0.02398667798925701, 0.007297393223389573, -0.00397888002588662, 0.004025572813356069, -0.001917733531540334, 0.00897165831789793, -0.030577010665470916, 0.018410242647845246, 0.01723625655428147, 8.064382004827367e-06, -0.004195667701616904, -0.020718192179621113, 1.800480778937139e-05, -0.005372989326900838, 0.03167095331097643, 0.017569774336040272, 0.004775990150619752, 0.016916077174113094, -0.0019794345819360267, -0.017062825668639203, -0.009832137026056197, 0.007270711763595967, -0.030683736504645343, -0.03754088564144041, -0.014541423527191934, 0.014754875205540783, -0.0010639251883304698, -0.013847703709913069, 0.006473601638862835, 0.024093403828431437, -0.009338528622890654, 0.004655923581548524, -0.012920521817932063, 0.01363425203156422, -0.030977233493697562, 0.032257947289080866, -0.0007600061760519037, -0.005239581562271531, 0.03279157648495299, -0.01019900733104892, 0.03140413685039526, -0.0013115630400126425, 0.01754309380756922, -0.013514184996831715, 0.009625354548502559, 0.007817682620687445, 0.005156201651170554, 0.0229861209186904, -0.021411911996899978, -0.026761555395727367, -0.006216791773442142, -0.013500843801273636, -0.01440801529690135, 0.026294629383677985, -0.013240699335455337, 0.06456925563510384, 0.0060066751611521745, -0.012066713241891562, 0.009191780128364545, 0.006550310952184771, 0.022559217561992702, 0.00854475402987768, 0.021171777927434972, -0.008678161328845711, 0.004269041483218682, 0.038368011826364755, 0.00026639820944380745, 0.005369653795180679, -0.025214027002408, -0.04559869953762521, 0.019344094671944017, -0.015221801217590166, 0.008998339777691537, -0.0008221240514972972, 0.00695720391252918, 0.013674273755593352, 0.0199044062589323, 0.0071439745967457, 0.001460812717667595, -0.010339085693457267, -0.006390221727761858, 0.025027255852530204, -0.034125651337278406, -0.021065052088260545, -0.015862157183959266, 0.012827136242993165, 0.01103280457941358, -0.017996679555383074, -0.03380547381975513, 0.017342982393455896, -0.0019244038964887353, -0.015141756838209348, -0.009558651364679819, 0.0119666575348349, 0.004999447958467799, 0.019517525557586284, 0.03169763383944748, -0.022412469067466592, -0.013600899508330298, -0.00760423047667732, -0.02037133227098168, -0.014768216401098861, 0.006233468035059103, -0.013080610576693701]]\n" | |
| ] | |
| } | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "source": [ | |
| "### Prompt template\n", | |
| "\n", | |
| "https://github.com/hwchase17/langchain-hub 에서 여러 종류의 prompt / chain 등의 예시를 볼 수 있다." | |
| ], | |
| "metadata": { | |
| "id": "CHIO30ZzfPuL" | |
| } | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "from langchain.prompts import PromptTemplate\n", | |
| "\n", | |
| "prompt = PromptTemplate(\n", | |
| " input_variables=[\"product\"],\n", | |
| " template=\"what is a good name for a company that makes {product}?\",\n", | |
| ")\n", | |
| "\n", | |
| "print(prompt.format(product=\"colorful socks\"))" | |
| ], | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/" | |
| }, | |
| "id": "5nSoroM5eEa-", | |
| "outputId": "0c3ed86e-fba2-46cf-8170-b0b1b52d0515" | |
| }, | |
| "execution_count": 13, | |
| "outputs": [ | |
| { | |
| "output_type": "stream", | |
| "name": "stdout", | |
| "text": [ | |
| "what is a good name for a company that makes colorful socks?\n" | |
| ] | |
| } | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "from langchain import PromptTemplate, FewShotPromptTemplate\n", | |
| "\n", | |
| "## Create the list of few shot example\n", | |
| "examples = [\n", | |
| " {\"word\": \"happy\", \"antonym\":\"sad\"},\n", | |
| " {\"word\":\"tall\", \"antonym\":\"short\"},\n", | |
| "]\n", | |
| "\n", | |
| "## specify the template to format the examples we have provided\n", | |
| "## use PromptTemplate class.\n", | |
| "example_formatter_template = \"\"\"\n", | |
| "Word: {word}\n", | |
| "Antonym: {antonym}\\n\n", | |
| "\"\"\"\n", | |
| "\n", | |
| "example_prompt = PromptTemplate(\n", | |
| " input_variables=[\"word\", \"antonym\"],\n", | |
| " template=example_formatter_template,\n", | |
| ")\n", | |
| "\n", | |
| "few_shot_prompt = FewShotPromptTemplate(\n", | |
| " ## few shot으로 사용할 예시 모음\n", | |
| " examples=examples,\n", | |
| " ## 입력값을 prompt format으로 맞춰주기 위한 template\n", | |
| " example_prompt=example_prompt,\n", | |
| " ## prompt 시작하기 전에 붙는 prefix. 보통 instruction을 쓴다\n", | |
| " prefix=\"Give me antonym of every input\",\n", | |
| " ## prompt 넣은 후 뒤에 붙는 suffix. 보통 user input이 들어간다.\n", | |
| " suffix=\"Word: {input} \\nAntonym:\",\n", | |
| " ## prompt가 인지할 input variable의 이름.\n", | |
| " input_variables=[\"input\"],\n", | |
| " ## prefix, prompt, suffix 합칠 때 사용할 separator\n", | |
| " example_separator=\"\\n\\n\",\n", | |
| ")\n", | |
| "\n", | |
| "print(few_shot_prompt.format(input=\"big\"))" | |
| ], | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/" | |
| }, | |
| "id": "EIiWWh3ahb9b", | |
| "outputId": "fb915699-c43d-4c59-b539-bf2e2a79b0fa" | |
| }, | |
| "execution_count": 14, | |
| "outputs": [ | |
| { | |
| "output_type": "stream", | |
| "name": "stdout", | |
| "text": [ | |
| "Give me antonym of every input\n", | |
| "\n", | |
| "\n", | |
| "Word: happy\n", | |
| "Antonym: sad\n", | |
| "\n", | |
| "\n", | |
| "\n", | |
| "\n", | |
| "Word: tall\n", | |
| "Antonym: short\n", | |
| "\n", | |
| "\n", | |
| "\n", | |
| "Word: big \n", | |
| "Antonym:\n" | |
| ] | |
| } | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "source": [ | |
| "few shot example로 사용할 값조차도 달라져야 할 때가 있다. 프로그래밍해서 동적으로 적용되도록 만들 수 있음.\n", | |
| "\n", | |
| "few shot으로 예시 잘 만들면 좀더 괜찮은 성능을 기대할 수 있다." | |
| ], | |
| "metadata": { | |
| "id": "b2CmbyeKke6n" | |
| } | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "source": [ | |
| "### Chat Prompt Template" | |
| ], | |
| "metadata": { | |
| "id": "nBA-4trmkuFS" | |
| } | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "from langchain.chat_models import ChatOpenAI\n", | |
| "from langchain.prompts.chat import (\n", | |
| " ChatPromptTemplate,\n", | |
| " SystemMessagePromptTemplate,\n", | |
| " HumanMessagePromptTemplate,\n", | |
| ")\n", | |
| "\n", | |
| "chat = ChatOpenAI(temperature=0)\n", | |
| "\n", | |
| "template = \"You are a helpful assistent that translate {input_language} to {output_language}.\"\n", | |
| "system_message_prompt = SystemMessagePromptTemplate.from_template(template)\n", | |
| "human_template = \"{text}\"\n", | |
| "human_message_prompt = HumanMessagePromptTemplate.from_template(human_template)\n", | |
| "\n", | |
| "chat_prompt = ChatPromptTemplate.from_messages([system_message_prompt, human_message_prompt])\n", | |
| "\n", | |
| "chat(chat_prompt.format_prompt(\n", | |
| " input_language=\"English\", \n", | |
| " output_language=\"Korean\", \n", | |
| " text=\"I Love Programming.\")\n", | |
| ".to_messages())" | |
| ], | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/" | |
| }, | |
| "id": "ws6zWpstkT1i", | |
| "outputId": "152b0296-c7d8-46d9-9dea-3a06ba57fa46" | |
| }, | |
| "execution_count": 15, | |
| "outputs": [ | |
| { | |
| "output_type": "stream", | |
| "name": "stderr", | |
| "text": [ | |
| "WARNING:/usr/local/lib/python3.9/dist-packages/langchain/chat_models/openai.py:Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 1.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-mfNrETunpMAJBlt7q8zkKlhK on requests per min. Limit: 3 / min. Please try again in 20s. Contact [email protected] if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", | |
| "WARNING:/usr/local/lib/python3.9/dist-packages/langchain/chat_models/openai.py:Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 2.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-mfNrETunpMAJBlt7q8zkKlhK on requests per min. Limit: 3 / min. Please try again in 20s. Contact [email protected] if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", | |
| "WARNING:/usr/local/lib/python3.9/dist-packages/langchain/chat_models/openai.py:Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 4.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-mfNrETunpMAJBlt7q8zkKlhK on requests per min. Limit: 3 / min. Please try again in 20s. Contact [email protected] if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", | |
| "WARNING:/usr/local/lib/python3.9/dist-packages/langchain/chat_models/openai.py:Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 8.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo in organization org-mfNrETunpMAJBlt7q8zkKlhK on requests per min. Limit: 3 / min. Please try again in 20s. Contact [email protected] if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n" | |
| ] | |
| }, | |
| { | |
| "output_type": "execute_result", | |
| "data": { | |
| "text/plain": [ | |
| "AIMessage(content='저는 프로그래밍을 좋아합니다.', additional_kwargs={})" | |
| ] | |
| }, | |
| "metadata": {}, | |
| "execution_count": 15 | |
| } | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "source": [ | |
| "### indexes" | |
| ], | |
| "metadata": { | |
| "id": "4tlBGwjFmjlj" | |
| } | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "!wget https://raw.githubusercontent.com/hwchase17/chat-your-data/master/state_of_the_union.txt" | |
| ], | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/" | |
| }, | |
| "id": "cvIwFLnQwluj", | |
| "outputId": "c3e50146-6137-4906-b47a-450e9ba3817e" | |
| }, | |
| "execution_count": 16, | |
| "outputs": [ | |
| { | |
| "output_type": "stream", | |
| "name": "stdout", | |
| "text": [ | |
| "--2023-04-17 08:29:23-- https://raw.githubusercontent.com/hwchase17/chat-your-data/master/state_of_the_union.txt\n", | |
| "Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.109.133, 185.199.110.133, 185.199.108.133, ...\n", | |
| "Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|185.199.109.133|:443... connected.\n", | |
| "HTTP request sent, awaiting response... 200 OK\n", | |
| "Length: 39027 (38K) [text/plain]\n", | |
| "Saving to: ‘state_of_the_union.txt’\n", | |
| "\n", | |
| "\rstate_of_the_union. 0%[ ] 0 --.-KB/s \rstate_of_the_union. 100%[===================>] 38.11K --.-KB/s in 0.003s \n", | |
| "\n", | |
| "2023-04-17 08:29:23 (11.9 MB/s) - ‘state_of_the_union.txt’ saved [39027/39027]\n", | |
| "\n" | |
| ] | |
| } | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "!pip install chromadb" | |
| ], | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/", | |
| "height": 1000 | |
| }, | |
| "id": "-WWbBCj1Xc5d", | |
| "outputId": "5307118e-2cbe-424e-8c63-bf5d84f620ea" | |
| }, | |
| "execution_count": 19, | |
| "outputs": [ | |
| { | |
| "output_type": "stream", | |
| "name": "stdout", | |
| "text": [ | |
| "Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n", | |
| "Collecting chromadb\n", | |
| " Downloading chromadb-0.3.21-py3-none-any.whl (46 kB)\n", | |
| "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m46.4/46.4 kB\u001b[0m \u001b[31m2.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", | |
| "\u001b[?25hCollecting fastapi>=0.85.1\n", | |
| " Downloading fastapi-0.95.1-py3-none-any.whl (56 kB)\n", | |
| "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m57.0/57.0 kB\u001b[0m \u001b[31m7.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", | |
| "\u001b[?25hCollecting posthog>=2.4.0\n", | |
| " Downloading posthog-2.5.0-py2.py3-none-any.whl (36 kB)\n", | |
| "Collecting requests>=2.28\n", | |
| " Downloading requests-2.28.2-py3-none-any.whl (62 kB)\n", | |
| "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m62.8/62.8 kB\u001b[0m \u001b[31m7.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", | |
| "\u001b[?25hCollecting uvicorn[standard]>=0.18.3\n", | |
| " Downloading uvicorn-0.21.1-py3-none-any.whl (57 kB)\n", | |
| "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m57.8/57.8 kB\u001b[0m \u001b[31m6.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", | |
| "\u001b[?25hRequirement already satisfied: pydantic>=1.9 in /usr/local/lib/python3.9/dist-packages (from chromadb) (1.10.7)\n", | |
| "Requirement already satisfied: numpy>=1.21.6 in /usr/local/lib/python3.9/dist-packages (from chromadb) (1.22.4)\n", | |
| "Collecting sentence-transformers>=2.2.2\n", | |
| " Downloading sentence-transformers-2.2.2.tar.gz (85 kB)\n", | |
| "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m86.0/86.0 kB\u001b[0m \u001b[31m8.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", | |
| "\u001b[?25h Preparing metadata (setup.py) ... \u001b[?25l\u001b[?25hdone\n", | |
| "Requirement already satisfied: pandas>=1.3 in /usr/local/lib/python3.9/dist-packages (from chromadb) (1.5.3)\n", | |
| "Collecting duckdb>=0.7.1\n", | |
| " Downloading duckdb-0.7.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.2 MB)\n", | |
| "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m15.2/15.2 MB\u001b[0m \u001b[31m64.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", | |
| "\u001b[?25hCollecting hnswlib>=0.7\n", | |
| " Downloading hnswlib-0.7.0.tar.gz (33 kB)\n", | |
| " Installing build dependencies ... \u001b[?25l\u001b[?25hdone\n", | |
| " Getting requirements to build wheel ... \u001b[?25l\u001b[?25hdone\n", | |
| " Preparing metadata (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n", | |
| "Collecting clickhouse-connect>=0.5.7\n", | |
| " Downloading clickhouse_connect-0.5.20-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (927 kB)\n", | |
| "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m927.8/927.8 kB\u001b[0m \u001b[31m4.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", | |
| "\u001b[?25hCollecting zstandard\n", | |
| " Downloading zstandard-0.21.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.7 MB)\n", | |
| "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.7/2.7 MB\u001b[0m \u001b[31m74.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", | |
| "\u001b[?25hRequirement already satisfied: certifi in /usr/local/lib/python3.9/dist-packages (from clickhouse-connect>=0.5.7->chromadb) (2022.12.7)\n", | |
| "Collecting lz4\n", | |
| " Downloading lz4-4.3.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.3 MB)\n", | |
| "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.3/1.3 MB\u001b[0m \u001b[31m63.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", | |
| "\u001b[?25hRequirement already satisfied: urllib3>=1.26 in /usr/local/lib/python3.9/dist-packages (from clickhouse-connect>=0.5.7->chromadb) (1.26.15)\n", | |
| "Requirement already satisfied: pytz in /usr/local/lib/python3.9/dist-packages (from clickhouse-connect>=0.5.7->chromadb) (2022.7.1)\n", | |
| "Collecting starlette<0.27.0,>=0.26.1\n", | |
| " Downloading starlette-0.26.1-py3-none-any.whl (66 kB)\n", | |
| "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m66.9/66.9 kB\u001b[0m \u001b[31m7.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", | |
| "\u001b[?25hRequirement already satisfied: python-dateutil>=2.8.1 in /usr/local/lib/python3.9/dist-packages (from pandas>=1.3->chromadb) (2.8.2)\n", | |
| "Collecting monotonic>=1.5\n", | |
| " Downloading monotonic-1.6-py2.py3-none-any.whl (8.2 kB)\n", | |
| "Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.9/dist-packages (from posthog>=2.4.0->chromadb) (1.16.0)\n", | |
| "Collecting backoff>=1.10.0\n", | |
| " Downloading backoff-2.2.1-py3-none-any.whl (15 kB)\n", | |
| "Requirement already satisfied: typing-extensions>=4.2.0 in /usr/local/lib/python3.9/dist-packages (from pydantic>=1.9->chromadb) (4.5.0)\n", | |
| "Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.9/dist-packages (from requests>=2.28->chromadb) (2.0.12)\n", | |
| "Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.9/dist-packages (from requests>=2.28->chromadb) (3.4)\n", | |
| "Collecting transformers<5.0.0,>=4.6.0\n", | |
| " Downloading transformers-4.28.1-py3-none-any.whl (7.0 MB)\n", | |
| "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m7.0/7.0 MB\u001b[0m \u001b[31m83.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", | |
| "\u001b[?25hRequirement already satisfied: tqdm in /usr/local/lib/python3.9/dist-packages (from sentence-transformers>=2.2.2->chromadb) (4.65.0)\n", | |
| "Requirement already satisfied: torch>=1.6.0 in /usr/local/lib/python3.9/dist-packages (from sentence-transformers>=2.2.2->chromadb) (2.0.0+cu118)\n", | |
| "Requirement already satisfied: torchvision in /usr/local/lib/python3.9/dist-packages (from sentence-transformers>=2.2.2->chromadb) (0.15.1+cu118)\n", | |
| "Requirement already satisfied: scikit-learn in /usr/local/lib/python3.9/dist-packages (from sentence-transformers>=2.2.2->chromadb) (1.2.2)\n", | |
| "Requirement already satisfied: scipy in /usr/local/lib/python3.9/dist-packages (from sentence-transformers>=2.2.2->chromadb) (1.10.1)\n", | |
| "Requirement already satisfied: nltk in /usr/local/lib/python3.9/dist-packages (from sentence-transformers>=2.2.2->chromadb) (3.8.1)\n", | |
| "Collecting sentencepiece\n", | |
| " Downloading sentencepiece-0.1.98-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.3 MB)\n", | |
| "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.3/1.3 MB\u001b[0m \u001b[31m54.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", | |
| "\u001b[?25hCollecting huggingface-hub>=0.4.0\n", | |
| " Downloading huggingface_hub-0.13.4-py3-none-any.whl (200 kB)\n", | |
| "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m200.1/200.1 kB\u001b[0m \u001b[31m18.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", | |
| "\u001b[?25hCollecting h11>=0.8\n", | |
| " Downloading h11-0.14.0-py3-none-any.whl (58 kB)\n", | |
| "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m58.3/58.3 kB\u001b[0m \u001b[31m6.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", | |
| "\u001b[?25hRequirement already satisfied: click>=7.0 in /usr/local/lib/python3.9/dist-packages (from uvicorn[standard]>=0.18.3->chromadb) (8.1.3)\n", | |
| "Collecting uvloop!=0.15.0,!=0.15.1,>=0.14.0\n", | |
| " Downloading uvloop-0.17.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.2 MB)\n", | |
| "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m4.2/4.2 MB\u001b[0m \u001b[31m76.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", | |
| "\u001b[?25hCollecting watchfiles>=0.13\n", | |
| " Downloading watchfiles-0.19.0-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.3 MB)\n", | |
| "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.3/1.3 MB\u001b[0m \u001b[31m63.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", | |
| "\u001b[?25hRequirement already satisfied: pyyaml>=5.1 in /usr/local/lib/python3.9/dist-packages (from uvicorn[standard]>=0.18.3->chromadb) (6.0)\n", | |
| "Collecting httptools>=0.5.0\n", | |
| " Downloading httptools-0.5.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (417 kB)\n", | |
| "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m417.9/417.9 kB\u001b[0m \u001b[31m31.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", | |
| "\u001b[?25hCollecting python-dotenv>=0.13\n", | |
| " Downloading python_dotenv-1.0.0-py3-none-any.whl (19 kB)\n", | |
| "Collecting websockets>=10.4\n", | |
| " Downloading websockets-11.0.1-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (129 kB)\n", | |
| "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m129.5/129.5 kB\u001b[0m \u001b[31m11.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", | |
| "\u001b[?25hRequirement already satisfied: filelock in /usr/local/lib/python3.9/dist-packages (from huggingface-hub>=0.4.0->sentence-transformers>=2.2.2->chromadb) (3.11.0)\n", | |
| "Requirement already satisfied: packaging>=20.9 in /usr/local/lib/python3.9/dist-packages (from huggingface-hub>=0.4.0->sentence-transformers>=2.2.2->chromadb) (23.0)\n", | |
| "Requirement already satisfied: anyio<5,>=3.4.0 in /usr/local/lib/python3.9/dist-packages (from starlette<0.27.0,>=0.26.1->fastapi>=0.85.1->chromadb) (3.6.2)\n", | |
| "Requirement already satisfied: networkx in /usr/local/lib/python3.9/dist-packages (from torch>=1.6.0->sentence-transformers>=2.2.2->chromadb) (3.1)\n", | |
| "Requirement already satisfied: triton==2.0.0 in /usr/local/lib/python3.9/dist-packages (from torch>=1.6.0->sentence-transformers>=2.2.2->chromadb) (2.0.0)\n", | |
| "Requirement already satisfied: sympy in /usr/local/lib/python3.9/dist-packages (from torch>=1.6.0->sentence-transformers>=2.2.2->chromadb) (1.11.1)\n", | |
| "Requirement already satisfied: jinja2 in /usr/local/lib/python3.9/dist-packages (from torch>=1.6.0->sentence-transformers>=2.2.2->chromadb) (3.1.2)\n", | |
| "Requirement already satisfied: cmake in /usr/local/lib/python3.9/dist-packages (from triton==2.0.0->torch>=1.6.0->sentence-transformers>=2.2.2->chromadb) (3.25.2)\n", | |
| "Requirement already satisfied: lit in /usr/local/lib/python3.9/dist-packages (from triton==2.0.0->torch>=1.6.0->sentence-transformers>=2.2.2->chromadb) (16.0.1)\n", | |
| "Collecting tokenizers!=0.11.3,<0.14,>=0.11.1\n", | |
| " Downloading tokenizers-0.13.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (7.8 MB)\n", | |
| "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m7.8/7.8 MB\u001b[0m \u001b[31m59.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", | |
| "\u001b[?25hRequirement already satisfied: regex!=2019.12.17 in /usr/local/lib/python3.9/dist-packages (from transformers<5.0.0,>=4.6.0->sentence-transformers>=2.2.2->chromadb) (2022.10.31)\n", | |
| "Requirement already satisfied: joblib in /usr/local/lib/python3.9/dist-packages (from nltk->sentence-transformers>=2.2.2->chromadb) (1.2.0)\n", | |
| "Requirement already satisfied: threadpoolctl>=2.0.0 in /usr/local/lib/python3.9/dist-packages (from scikit-learn->sentence-transformers>=2.2.2->chromadb) (3.1.0)\n", | |
| "Requirement already satisfied: pillow!=8.3.*,>=5.3.0 in /usr/local/lib/python3.9/dist-packages (from torchvision->sentence-transformers>=2.2.2->chromadb) (8.4.0)\n", | |
| "Requirement already satisfied: sniffio>=1.1 in /usr/local/lib/python3.9/dist-packages (from anyio<5,>=3.4.0->starlette<0.27.0,>=0.26.1->fastapi>=0.85.1->chromadb) (1.3.0)\n", | |
| "Requirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib/python3.9/dist-packages (from jinja2->torch>=1.6.0->sentence-transformers>=2.2.2->chromadb) (2.1.2)\n", | |
| "Requirement already satisfied: mpmath>=0.19 in /usr/local/lib/python3.9/dist-packages (from sympy->torch>=1.6.0->sentence-transformers>=2.2.2->chromadb) (1.3.0)\n", | |
| "Building wheels for collected packages: hnswlib, sentence-transformers\n", | |
| " Building wheel for hnswlib (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n", | |
| " Created wheel for hnswlib: filename=hnswlib-0.7.0-cp39-cp39-linux_x86_64.whl size=2118402 sha256=a2a0f197038106c5cc1d81b3643c91c2b67d589120d4779f55e3ba1cff708169\n", | |
| " Stored in directory: /root/.cache/pip/wheels/ba/26/61/fface6c407f56418b3140cd7645917f20ba6b27d4e32b2bd20\n", | |
| " Building wheel for sentence-transformers (setup.py) ... \u001b[?25l\u001b[?25hdone\n", | |
| " Created wheel for sentence-transformers: filename=sentence_transformers-2.2.2-py3-none-any.whl size=125942 sha256=e9b659a0a72cebfdc0247b43bbf7c65c1f5724bbf4e414d820081ff144986585\n", | |
| " Stored in directory: /root/.cache/pip/wheels/71/67/06/162a3760c40d74dd40bc855d527008d26341c2b0ecf3e8e11f\n", | |
| "Successfully built hnswlib sentence-transformers\n", | |
| "Installing collected packages: tokenizers, sentencepiece, monotonic, duckdb, zstandard, websockets, uvloop, requests, python-dotenv, lz4, httptools, hnswlib, h11, backoff, watchfiles, uvicorn, starlette, posthog, huggingface-hub, clickhouse-connect, transformers, fastapi, sentence-transformers, chromadb\n", | |
| " Attempting uninstall: requests\n", | |
| " Found existing installation: requests 2.27.1\n", | |
| " Uninstalling requests-2.27.1:\n", | |
| " Successfully uninstalled requests-2.27.1\n", | |
| "Successfully installed backoff-2.2.1 chromadb-0.3.21 clickhouse-connect-0.5.20 duckdb-0.7.1 fastapi-0.95.1 h11-0.14.0 hnswlib-0.7.0 httptools-0.5.0 huggingface-hub-0.13.4 lz4-4.3.2 monotonic-1.6 posthog-2.5.0 python-dotenv-1.0.0 requests-2.28.2 sentence-transformers-2.2.2 sentencepiece-0.1.98 starlette-0.26.1 tokenizers-0.13.3 transformers-4.28.1 uvicorn-0.21.1 uvloop-0.17.0 watchfiles-0.19.0 websockets-11.0.1 zstandard-0.21.0\n" | |
| ] | |
| }, | |
| { | |
| "output_type": "display_data", | |
| "data": { | |
| "application/vnd.colab-display-data+json": { | |
| "pip_warning": { | |
| "packages": [ | |
| "requests" | |
| ] | |
| } | |
| } | |
| }, | |
| "metadata": {} | |
| } | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "source": [ | |
| "#### Question / Answering" | |
| ], | |
| "metadata": { | |
| "id": "ZnjOtEDfmltM" | |
| } | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "from langchain.document_loaders import TextLoader\n", | |
| "loader = TextLoader(\"state_of_the_union.txt\")\n", | |
| "\n", | |
| "from langchain.indexes import VectorstoreIndexCreator\n", | |
| "index = VectorstoreIndexCreator().from_loaders([loader])\n", | |
| "\n", | |
| "query = \"what did the president say about Ketanji Brown Jackson\"\n", | |
| "print(index.query(query))\n", | |
| "\n", | |
| "query = \"what did the president say about Ketanji Brown Jackson\"\n", | |
| "print(index.query_with_sources(query)) ## 해당 쿼리의 source까지 포함해서 이야기해주는 함수 (state_of_the_union.txt 파일명을 리턴해줌)" | |
| ], | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/" | |
| }, | |
| "id": "Y7l4KNrrlyls", | |
| "outputId": "91e71093-e4d8-4b66-f59d-0bb73de78c23" | |
| }, | |
| "execution_count": 20, | |
| "outputs": [ | |
| { | |
| "output_type": "stream", | |
| "name": "stderr", | |
| "text": [ | |
| "WARNING:chromadb:Using embedded DuckDB without persistence: data will be transient\n" | |
| ] | |
| }, | |
| { | |
| "output_type": "stream", | |
| "name": "stdout", | |
| "text": [ | |
| " The president said that Ketanji Brown Jackson is one of the nation's top legal minds, a former top litigator in private practice, a former federal public defender, and from a family of public school educators and police officers. He also said she is a consensus builder and has received a broad range of support from the Fraternal Order of Police to former judges appointed by Democrats and Republicans.\n", | |
| "{'question': 'what did the president say about Ketanji Brown Jackson', 'answer': \" The president said that he nominated Circuit Court of Appeals Judge Ketanji Brown Jackson, one of the nation's top legal minds, to continue Justice Breyer's legacy of excellence. He also said that she has received a broad range of support from the Fraternal Order of Police to former judges appointed by Democrats and Republicans.\\n\", 'sources': 'state_of_the_union.txt'}\n" | |
| ] | |
| } | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "source": [ | |
| "#### Q&A with vector DB" | |
| ], | |
| "metadata": { | |
| "id": "W524vGG3n5Xg" | |
| } | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "from langchain.embeddings.openai import OpenAIEmbeddings\n", | |
| "from langchain.text_splitter import CharacterTextSplitter\n", | |
| "from langchain.vectorstores import Chroma\n", | |
| "from langchain.docstore.document import Document\n", | |
| "from langchain.prompts import PromptTemplate\n", | |
| "from langchain.indexes.vectorstore import VectorstoreIndexCreator" | |
| ], | |
| "metadata": { | |
| "id": "XUlcDnoJoEal" | |
| }, | |
| "execution_count": 21, | |
| "outputs": [] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "with open(\"state_of_the_union.txt\") as f:\n", | |
| " state_of_the_unions = f.read()\n", | |
| "\n", | |
| "# text split 로직\n", | |
| "text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)\n", | |
| "texts= text_splitter.split_text(state_of_the_unions)\n", | |
| "\n", | |
| "embeddings = OpenAIEmbeddings()\n", | |
| "\n", | |
| "## text를 어떤 방식으로 embedding할 것인지, metadata에는 '어느 source로부터 가져왔는지' 를 지정\n", | |
| "### 문자열을 embedding -> vector DB에 저장. 이후 요청을 보낼 때 vector DB에서 search하면 됨.\n", | |
| "doc_search = Chroma.from_texts(\n", | |
| " texts, embeddings, metadatas=[{\"source\":str(i)} for i in range(len(texts))]\n", | |
| ").as_retriever()\n", | |
| "\n", | |
| "\n", | |
| "query = \"what did the president say about Justice Breyer\"\n", | |
| "docs = doc_search.get_relevant_documents(query)\n", | |
| "\n", | |
| "from langchain.chains.question_answering import load_qa_chain ## 자주 쓰는 걸 아예 함수로 빼놓은 것.\n", | |
| "from langchain.llms import OpenAI\n", | |
| "\n", | |
| "chain = load_qa_chain(OpenAI(temperature=0), chain_type=\"stuff\")\n", | |
| "query = \"what did the president say about Justice Breyer\"\n", | |
| "\n", | |
| "## 문서가 저장된 vector DB에서 쿼리 날리고, 결과 가져와서 리턴\n", | |
| "chain.run(input_documents=docs, question=query)\n" | |
| ], | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/", | |
| "height": 72 | |
| }, | |
| "id": "RBIjZhodoYIF", | |
| "outputId": "d1f18f19-d4db-47af-9a3d-29a230562b62" | |
| }, | |
| "execution_count": 23, | |
| "outputs": [ | |
| { | |
| "output_type": "stream", | |
| "name": "stderr", | |
| "text": [ | |
| "WARNING:chromadb:Using embedded DuckDB without persistence: data will be transient\n" | |
| ] | |
| }, | |
| { | |
| "output_type": "execute_result", | |
| "data": { | |
| "text/plain": [ | |
| "' The president said that Justice Breyer is an Army veteran, Constitutional scholar, and retiring Justice of the United States Supreme Court, and thanked him for his service.'" | |
| ], | |
| "application/vnd.google.colaboratory.intrinsic+json": { | |
| "type": "string" | |
| } | |
| }, | |
| "metadata": {}, | |
| "execution_count": 23 | |
| } | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "## prompt별로 다른 template을 적용한다던가 할 때... prompt를 파라미터로 추가해서 구분할 수 있음.\n", | |
| "## prompt에 '잘 모르겠으면 어떻게 해라' 라는 조건문이 추가되면 좋음.\n", | |
| "### 아래 prompt는 응답을 한국어로 리턴하도록 만든 것.\n", | |
| "prompt_template = \"\"\"Use the following pieces of context to answer the question at the end. If you don't know the answer, just say that you don't know, don't try to make up an answer.\n", | |
| "\n", | |
| "{context}\n", | |
| "\n", | |
| "Question: {question}\n", | |
| "Answer in Korean: \n", | |
| "\"\"\"\n", | |
| "PROMPT = PromptTemplate(\n", | |
| " template=prompt_template,\n", | |
| " input_variables=[\"context\", \"question\"]\n", | |
| ")\n", | |
| "chain = load_qa_chain(OpenAI(temperature=0), chain_type=\"stuff\", prompt=PROMPT)\n", | |
| "chain({\"input_documents\":docs, \"question\":query}, return_only_outputs=True)\n" | |
| ], | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/" | |
| }, | |
| "id": "v3XYmiLRtPsD", | |
| "outputId": "130c5748-230c-4094-ebcf-29390ebc1fdd" | |
| }, | |
| "execution_count": 24, | |
| "outputs": [ | |
| { | |
| "output_type": "execute_result", | |
| "data": { | |
| "text/plain": [ | |
| "{'output_text': '대통령은 스티븐 브라이어 재판관에 대해 말했다. 그는 군인, 헌법학자 및 미국 최고법원 퇴임 재판관이며, 그의 서비스에 감사를 표하고 있다고 말했다.'}" | |
| ] | |
| }, | |
| "metadata": {}, | |
| "execution_count": 24 | |
| } | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "source": [ | |
| "### Map-Rerank\n", | |
| "\n", | |
| "내 질문과 유사한 것을 찾아서 응답을 여러 개 리턴하는 것." | |
| ], | |
| "metadata": { | |
| "id": "kzQWo-_muisL" | |
| } | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "chain = load_qa_chain(OpenAI(temperature=0), chain_type=\"map_rerank\", return_intermediate_steps=True)\n", | |
| "\n", | |
| "query = \"what did the president say about Justice Breyer\"\n", | |
| "results = chain({\"input_documents\":docs, \"question\": query}, return_only_outputs=True)\n", | |
| "\n", | |
| "print(results['output_text'])\n", | |
| "\n", | |
| "print(results['intermediate_steps'])" | |
| ], | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/" | |
| }, | |
| "id": "rrWzsXSauuCE", | |
| "outputId": "bcb30e86-ad86-4619-ea61-ca6e63ac9db6" | |
| }, | |
| "execution_count": 25, | |
| "outputs": [ | |
| { | |
| "output_type": "stream", | |
| "name": "stdout", | |
| "text": [ | |
| " The President thanked Justice Breyer for his service and honored him for dedicating his life to serve the country.\n", | |
| "[{'answer': ' The President thanked Justice Breyer for his service and honored him for dedicating his life to serve the country.', 'score': '100'}, {'answer': ' This document does not answer the question', 'score': '0'}, {'answer': ' This document does not answer the question', 'score': '0'}, {'answer': ' This document does not answer the question', 'score': '0'}]\n" | |
| ] | |
| } | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "source": [ | |
| "prompt 분리" | |
| ], | |
| "metadata": { | |
| "id": "6ygrLT7LvFEc" | |
| } | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "from langchain.output_parsers import RegexParser\n", | |
| "\n", | |
| "output_parser = RegexParser(\n", | |
| " regex=r\"(.*?)\\nScore: (.*)\",\n", | |
| " output_keys=[\"answer\", \"score\"]\n", | |
| ")\n", | |
| "\n", | |
| "prompt_template = \"\"\"Use the following pieces of context to answer the question at the end. If you don't know the answer, just say that you don't know, don't try to make up an answer.\n", | |
| "\n", | |
| "In addition to giving an answer, also return a score of how fully it answered the user's question. This should be in the following format:\n", | |
| "\n", | |
| "Question: [question here]\n", | |
| "Helpful Answer in Korean: [answer here]\n", | |
| "Score: [score between 0 and 100]\n", | |
| "\n", | |
| "Begin:\n", | |
| "\n", | |
| "Context:\n", | |
| "------------\n", | |
| "{context}\n", | |
| "------------\n", | |
| "Question: {question}\n", | |
| "Helpful Answer in Korean:\n", | |
| "\"\"\"\n", | |
| "\n", | |
| "PROMPT = PromptTemplate(\n", | |
| " template=prompt_template,\n", | |
| " input_variables=[\"context\", \"question\"],\n", | |
| " output_parser=output_parser\n", | |
| ")\n", | |
| "\n", | |
| "chain = load_qa_chain(\n", | |
| " OpenAI(temperature=0), \n", | |
| " chain_type=\"map_rerank\", \n", | |
| " return_intermediate_steps=True, \n", | |
| " prompt=PROMPT\n", | |
| ")\n", | |
| "\n", | |
| "query = \"what did the president say about Justice Breyer\"\n", | |
| "chain({\"input_documents\":docs, \"question\": query}, return_only_outputs=True)" | |
| ], | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/" | |
| }, | |
| "id": "KlPn1WzhvHOX", | |
| "outputId": "b9a09dcb-8005-4cec-c9fb-781d56a23817" | |
| }, | |
| "execution_count": 28, | |
| "outputs": [ | |
| { | |
| "output_type": "execute_result", | |
| "data": { | |
| "text/plain": [ | |
| "{'intermediate_steps': [{'answer': '대통령은 스티븐 브라이어 재판관에 대해 말했습니다. 그는 국가를 서비스하기 위해 삶을 헌신한 사람으로 존경하고 인정하고 있다고 말했습니다.',\n", | |
| " 'score': '100'},\n", | |
| " {'answer': '정의 소송 변호사로 이전한 경력이 있고, 연방 공무원 변호사로 이전한 경력도 있으며, 공립학교 교사와 경찰관들로부터 이루어진 가족이 있다고 합의를 이루는 분이라고 대통령이 밝혔습니다.',\n", | |
| " 'score': '100'},\n", | |
| " {'answer': '정의 브라이어에 대해 대통령은 무엇을 말했습니까?', 'score': '0'},\n", | |
| " {'answer': '정의 부문에 대해 대통령은 무엇을 말했습니까?', 'score': '0'}],\n", | |
| " 'output_text': '대통령은 스티븐 브라이어 재판관에 대해 말했습니다. 그는 국가를 서비스하기 위해 삶을 헌신한 사람으로 존경하고 인정하고 있다고 말했습니다.'}" | |
| ] | |
| }, | |
| "metadata": {}, | |
| "execution_count": 28 | |
| } | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "source": [ | |
| "### RetrievalQA chain 활용한 검색기반 질의응답\n" | |
| ], | |
| "metadata": { | |
| "id": "G9GDbPkxw-eG" | |
| } | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "from langchain.embeddings.openai import OpenAIEmbeddings\n", | |
| "from langchain.vectorstores import Chroma\n", | |
| "from langchain.text_splitter import CharacterTextSplitter\n", | |
| "from langchain.llms import OpenAI\n", | |
| "from langchain.chains import RetrievalQA\n", | |
| "\n", | |
| "from langchain.document_loaders import TextLoader\n", | |
| "loader = TextLoader(\"state_of_the_union.txt\")\n", | |
| "documents = loader.load()\n", | |
| "text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)\n", | |
| "texts = text_splitter.split_documents(documents)\n", | |
| "\n", | |
| "embeddings = OpenAIEmbeddings()\n", | |
| "docsearch = Chroma.from_documents(texts, embeddings)\n", | |
| "\n", | |
| "qa = RetrievalQA.from_chain_type(llm=OpenAI(), chain_type=\"stuff\", retriever=docsearch.as_retriever())\n", | |
| "\n", | |
| "query = \"What did the president say about Ketanji Brown Jackson\"\n", | |
| "qa.run(query)" | |
| ], | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/", | |
| "height": 125 | |
| }, | |
| "id": "EBT7wqgSxCgH", | |
| "outputId": "3a28526c-f3f0-4130-bfb0-85651842f663" | |
| }, | |
| "execution_count": 29, | |
| "outputs": [ | |
| { | |
| "output_type": "stream", | |
| "name": "stderr", | |
| "text": [ | |
| "WARNING:chromadb:Using embedded DuckDB without persistence: data will be transient\n" | |
| ] | |
| }, | |
| { | |
| "output_type": "execute_result", | |
| "data": { | |
| "text/plain": [ | |
| "\" The president said that Ketanji Brown Jackson is a Circuit Court of Appeals Judge, one of the nation's top legal minds, a former top litigator in private practice, a former federal public defender, from a family of public school educators and police officers, a consensus builder, and has received a broad range of support from the Fraternal Order of Police to former judges appointed by Democrats and Republicans since being nominated.\"" | |
| ], | |
| "application/vnd.google.colaboratory.intrinsic+json": { | |
| "type": "string" | |
| } | |
| }, | |
| "metadata": {}, | |
| "execution_count": 29 | |
| } | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "source": [ | |
| "Prompt 활용 -> 한국어로 응답하도록 수정" | |
| ], | |
| "metadata": { | |
| "id": "6ywaRe7IY-gN" | |
| } | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "from langchain.prompts import PromptTemplate\n", | |
| "prompt_template = \"\"\"Use the following pieces of context to answer the question at the end. If you don't know the answer, just say that you don't know, don't try to make up an answer.\n", | |
| "\n", | |
| "{context}\n", | |
| "\n", | |
| "Question: {question}\n", | |
| "Answer in Korean:\"\"\"\n", | |
| "PROMPT = PromptTemplate(\n", | |
| " template=prompt_template, input_variables=[\"context\", \"question\"]\n", | |
| ")\n", | |
| "\n", | |
| "chain_type_kwargs = {\"prompt\": PROMPT}\n", | |
| "qa = RetrievalQA.from_chain_type(\n", | |
| " llm=OpenAI(), chain_type=\"stuff\", \n", | |
| " retriever=docsearch.as_retriever(), chain_type_kwargs=chain_type_kwargs\n", | |
| ")\n", | |
| "\n", | |
| "query = \"What did the president say about Ketanji Brown Jackson\"\n", | |
| "qa.run(query)" | |
| ], | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/", | |
| "height": 54 | |
| }, | |
| "id": "NoJwhKWaZBbZ", | |
| "outputId": "8567540d-b239-41a6-f7b0-511699391f28" | |
| }, | |
| "execution_count": 33, | |
| "outputs": [ | |
| { | |
| "output_type": "execute_result", | |
| "data": { | |
| "text/plain": [ | |
| "' 대통령은 케탄지 브라운 잭슨에 대해 어떤 것을 말했는가? 대통령은 케탄지 브라운 잭슨이 국가의 상위 법률 인지를 가지고 있고, 소극적인 연대 빌딩을 위해 여러 사람들의 지지를 받고 있으며, 과거 최고 리티게이터이자 '" | |
| ], | |
| "application/vnd.google.colaboratory.intrinsic+json": { | |
| "type": "string" | |
| } | |
| }, | |
| "metadata": {}, | |
| "execution_count": 33 | |
| } | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "source": [ | |
| "### Chain - Combine LLMs and Prompts in multi-step workflow\n", | |
| "\n", | |
| "여러 체인을 한 번에 실행할 수 있다는 것이 장점." | |
| ], | |
| "metadata": { | |
| "id": "rKyorgEgZo0m" | |
| } | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "from langchain.prompts import PromptTemplate\n", | |
| "from langchain.llms import OpenAI\n", | |
| "\n", | |
| "llm = OpenAI(temperature=0.9)\n", | |
| "prompt = PromptTemplate(\n", | |
| " input_variables=[\"product\"],\n", | |
| " template = \"What is a good name for a company that makes {product}?\"\n", | |
| ")\n", | |
| "\n", | |
| "from langchain.chains import LLMChain\n", | |
| "chain = LLMChain(llm=llm, prompt=prompt)\n", | |
| "chain.run(\"colorful socks\")" | |
| ], | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/", | |
| "height": 36 | |
| }, | |
| "id": "TaOrpLUbaY7T", | |
| "outputId": "148a528b-70ba-4f83-a19b-58ea1ed74c0c" | |
| }, | |
| "execution_count": 34, | |
| "outputs": [ | |
| { | |
| "output_type": "execute_result", | |
| "data": { | |
| "text/plain": [ | |
| "'\\n\\nFancy Feet Socks.'" | |
| ], | |
| "application/vnd.google.colaboratory.intrinsic+json": { | |
| "type": "string" | |
| } | |
| }, | |
| "metadata": {}, | |
| "execution_count": 34 | |
| } | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "## LLMChain\n", | |
| "### 채팅에 Chain 쓰기 -> ChatPromptTemplate 생성, LLMChain에 채팅 모델 적용\n", | |
| "chat = ChatOpenAI(temperature=0)\n", | |
| "\n", | |
| "template = \"You are a helpful assistant that translates {input_language} to {output_language}\"\n", | |
| "system_message_prompt = SystemMessagePromptTemplate.from_template(template)\n", | |
| "human_template = \"{text}\"\n", | |
| "human_message_template = HumanMessagePromptTemplate.from_template(human_template)\n", | |
| "\n", | |
| "chat_prompt = ChatPromptTemplate.from_messages([system_message_prompt, human_message_prompt])\n", | |
| "\n", | |
| "chain = LLMChain(llm=chat, prompt=chat_prompt)\n", | |
| "\n", | |
| "chain.run(input_language=\"English\", output_language=\"Korean\", text = \"I love programming.\")" | |
| ], | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/", | |
| "height": 36 | |
| }, | |
| "id": "BNpfUpQQa6ca", | |
| "outputId": "8a9f3fdc-d12f-46a9-947c-9206cd1380a1" | |
| }, | |
| "execution_count": 35, | |
| "outputs": [ | |
| { | |
| "output_type": "execute_result", | |
| "data": { | |
| "text/plain": [ | |
| "'저는 프로그래밍을 좋아합니다.'" | |
| ], | |
| "application/vnd.google.colaboratory.intrinsic+json": { | |
| "type": "string" | |
| } | |
| }, | |
| "metadata": {}, | |
| "execution_count": 35 | |
| } | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "source": [ | |
| "#### streaming" | |
| ], | |
| "metadata": { | |
| "id": "tLRL7rNZbzZy" | |
| } | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "from langchain.callbacks.base import CallbackManager\n", | |
| "from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler\n", | |
| "chat = ChatOpenAI(streaming=True, callback_manager=CallbackManager([StreamingStdOutCallbackHandler()]), verbose=True, temperature=0)\n", | |
| "resp = chat([HumanMessage(content=\"Write me a song about sparkling water.\")])" | |
| ], | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/" | |
| }, | |
| "id": "TueDHX-wb0p_", | |
| "outputId": "9eee77a0-33bf-4809-c3dd-c2b6d1ebaa38" | |
| }, | |
| "execution_count": 36, | |
| "outputs": [ | |
| { | |
| "output_type": "stream", | |
| "name": "stdout", | |
| "text": [ | |
| "Verse 1:\n", | |
| "Bubbles rising to the top\n", | |
| "A refreshing drink that never stops\n", | |
| "Clear and crisp, it's oh so pure\n", | |
| "Sparkling water, I can't ignore\n", | |
| "\n", | |
| "Chorus:\n", | |
| "Sparkling water, oh how you shine\n", | |
| "A taste so clean, it's simply divine\n", | |
| "You quench my thirst, you make me feel alive\n", | |
| "Sparkling water, you're my favorite vibe\n", | |
| "\n", | |
| "Verse 2:\n", | |
| "No sugar, no calories, just H2O\n", | |
| "A drink that's good for me, don't you know\n", | |
| "With lemon or lime, you're even better\n", | |
| "Sparkling water, you're my forever\n", | |
| "\n", | |
| "Chorus:\n", | |
| "Sparkling water, oh how you shine\n", | |
| "A taste so clean, it's simply divine\n", | |
| "You quench my thirst, you make me feel alive\n", | |
| "Sparkling water, you're my favorite vibe\n", | |
| "\n", | |
| "Bridge:\n", | |
| "You're my go-to drink, day or night\n", | |
| "You make me feel so light\n", | |
| "I'll never give you up, you're my true love\n", | |
| "Sparkling water, you're sent from above\n", | |
| "\n", | |
| "Chorus:\n", | |
| "Sparkling water, oh how you shine\n", | |
| "A taste so clean, it's simply divine\n", | |
| "You quench my thirst, you make me feel alive\n", | |
| "Sparkling water, you're my favorite vibe\n", | |
| "\n", | |
| "Outro:\n", | |
| "Sparkling water, you're the one for me\n", | |
| "I'll never let you go, can't you see\n", | |
| "You're my drink of choice, forevermore\n", | |
| "Sparkling water, I adore." | |
| ] | |
| } | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "source": [ | |
| "### Analyze Document - Summarize\n", | |
| "\n", | |
| "공식문서에 가보면 제공해주는 chain이 엄청 많다. load_summarize_chain도 그 중 하나.\n", | |
| "- 내부 동작이 어떻게 이루어지는지 이해하고 써야 하는데 이해가 어려우면, 직접 만들어 쓰는 것도 좋을거같음." | |
| ], | |
| "metadata": { | |
| "id": "61r-qI9cci3s" | |
| } | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "## 이 예시는 vector DB 없이, 모든 문장 전체를 메모리에 올린 뒤 load_summarize_chain에 전달함\n", | |
| "\n", | |
| "with open(\"state_of_the_union.txt\") as f:\n", | |
| " state_of_the_union = f.read()\n", | |
| "\n", | |
| "from langchain import OpenAI\n", | |
| "from langchain.chains.summarize import load_summarize_chain\n", | |
| "\n", | |
| "llm = OpenAI(temperature=0)\n", | |
| "summary_chain = load_summarize_chain(llm, chain_type=\"map_reduce\")\n", | |
| "\n", | |
| "from langchain.chains import AnalyzeDocumentChain\n", | |
| "\n", | |
| "summarize_document_chain = AnalyzeDocumentChain(combine_docs_chain=summary_chain)\n", | |
| "\n", | |
| "summarize_document_chain.run(state_of_the_union)" | |
| ], | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/", | |
| "height": 179 | |
| }, | |
| "id": "-LLjAgQcY6Ii", | |
| "outputId": "a03b2b4e-6c14-47e4-9061-ff9127beed91" | |
| }, | |
| "execution_count": 37, | |
| "outputs": [ | |
| { | |
| "output_type": "execute_result", | |
| "data": { | |
| "text/plain": [ | |
| "\" In this speech, President Biden addresses the American people and the world, emphasizing the courage and determination of the Ukrainian people in the face of Russian aggression. He outlines the actions taken by the US and its allies to hold Russia accountable, and the economic relief provided by the American Rescue Plan. He also proposes a plan to fight inflation, and outlines a Unity Agenda for the Nation, which includes beating the opioid epidemic, taking on mental health issues, and supporting veterans. He is also committed to helping lower-income veterans get VA care debt-free, and to finding out the cause of the diseases of many of our troops. He is optimistic about America's future and believes that the nation can turn every crisis into an opportunity.\"" | |
| ], | |
| "application/vnd.google.colaboratory.intrinsic+json": { | |
| "type": "string" | |
| } | |
| }, | |
| "metadata": {}, | |
| "execution_count": 37 | |
| } | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "## QA Chain도 있음.\n", | |
| "\n", | |
| "from langchain.chains.question_answering import load_qa_chain\n", | |
| "\n", | |
| "qa_chain = load_qa_chain(llm, chain_type=\"map_reduce\")\n", | |
| "\n", | |
| "qa_document_chain = AnalyzeDocumentChain(combine_docs_chain=qa_chain)\n", | |
| "\n", | |
| "qa_document_chain.run(input_document=state_of_the_union, question=\"what did the president say about justice breyer?\")" | |
| ], | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/", | |
| "height": 36 | |
| }, | |
| "id": "_IkXMQ9AZxVJ", | |
| "outputId": "a4185fdd-ffca-4691-81cf-8bad72bcea7b" | |
| }, | |
| "execution_count": 39, | |
| "outputs": [ | |
| { | |
| "output_type": "execute_result", | |
| "data": { | |
| "text/plain": [ | |
| "' The president thanked Justice Breyer for his service.'" | |
| ], | |
| "application/vnd.google.colaboratory.intrinsic+json": { | |
| "type": "string" | |
| } | |
| }, | |
| "metadata": {}, | |
| "execution_count": 39 | |
| } | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "source": [ | |
| "### ConversationChain\n", | |
| "\n", | |
| "ChatGPT 쓴 거 아님. OpenAI에서 제공하는 대규모 언어모델 중 하나를 대화형 chain으로 구축한 것.\n", | |
| "- 만약 언어모델이 채팅형으로 구성된 게 아니라면, ConversationChain 붙여서 채팅처럼 쓸 수 있음." | |
| ], | |
| "metadata": { | |
| "id": "u5AK76kodgIZ" | |
| } | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "from langchain import OpenAI, ConversationChain\n", | |
| "\n", | |
| "llm = OpenAI(temperature=0)\n", | |
| "conversation = ConversationChain(llm=llm, verbose=True)\n", | |
| "\n", | |
| "conversation.predict(input=\"Hi there!\")" | |
| ], | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/", | |
| "height": 270 | |
| }, | |
| "id": "LqOuShqHdQ-v", | |
| "outputId": "438b20a8-0222-4fa5-9842-2b235deec1d3" | |
| }, | |
| "execution_count": 40, | |
| "outputs": [ | |
| { | |
| "output_type": "stream", | |
| "name": "stdout", | |
| "text": [ | |
| "\n", | |
| "\n", | |
| "\u001b[1m> Entering new ConversationChain chain...\u001b[0m\n", | |
| "Prompt after formatting:\n", | |
| "\u001b[32;1m\u001b[1;3mThe following is a friendly conversation between a human and an AI. The AI is talkative and provides lots of specific details from its context. If the AI does not know the answer to a question, it truthfully says it does not know.\n", | |
| "\n", | |
| "Current conversation:\n", | |
| "\n", | |
| "Human: Hi there!\n", | |
| "AI:\u001b[0m\n", | |
| "\n", | |
| "\u001b[1m> Finished chain.\u001b[0m\n" | |
| ] | |
| }, | |
| { | |
| "output_type": "execute_result", | |
| "data": { | |
| "text/plain": [ | |
| "\" Hi there! It's nice to meet you. My name is AI. What's your name?\"" | |
| ], | |
| "application/vnd.google.colaboratory.intrinsic+json": { | |
| "type": "string" | |
| } | |
| }, | |
| "metadata": {}, | |
| "execution_count": 40 | |
| } | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "conversation.predict(input=\"I'm doing well! Just having a conversation with an AI.\")" | |
| ], | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/", | |
| "height": 306 | |
| }, | |
| "id": "LPPsSPNgdsrG", | |
| "outputId": "62696edb-3d27-4a11-a163-7a1895f63412" | |
| }, | |
| "execution_count": 41, | |
| "outputs": [ | |
| { | |
| "output_type": "stream", | |
| "name": "stdout", | |
| "text": [ | |
| "\n", | |
| "\n", | |
| "\u001b[1m> Entering new ConversationChain chain...\u001b[0m\n", | |
| "Prompt after formatting:\n", | |
| "\u001b[32;1m\u001b[1;3mThe following is a friendly conversation between a human and an AI. The AI is talkative and provides lots of specific details from its context. If the AI does not know the answer to a question, it truthfully says it does not know.\n", | |
| "\n", | |
| "Current conversation:\n", | |
| "Human: Hi there!\n", | |
| "AI: Hi there! It's nice to meet you. My name is AI. What's your name?\n", | |
| "Human: I'm doing well! Just having a conversation with an AI.\n", | |
| "AI:\u001b[0m\n", | |
| "\n", | |
| "\u001b[1m> Finished chain.\u001b[0m\n" | |
| ] | |
| }, | |
| { | |
| "output_type": "execute_result", | |
| "data": { | |
| "text/plain": [ | |
| "\" That's great! It's always nice to have a conversation with someone new. What would you like to talk about?\"" | |
| ], | |
| "application/vnd.google.colaboratory.intrinsic+json": { | |
| "type": "string" | |
| } | |
| }, | |
| "metadata": {}, | |
| "execution_count": 41 | |
| } | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "source": [ | |
| "채팅 모델을 활용한 대화형 체인" | |
| ], | |
| "metadata": { | |
| "id": "ccTNJCR2eIli" | |
| } | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "from langchain.chat_models import ChatOpenAI\n", | |
| "from langchain import LLMChain\n", | |
| "from langchain.prompts.chat import (\n", | |
| " ChatPromptTemplate,\n", | |
| " SystemMessagePromptTemplate,\n", | |
| " HumanMessagePromptTemplate,\n", | |
| ")\n", | |
| "\n", | |
| "chat = ChatOpenAI(temperature=0)\n", | |
| "\n", | |
| "template=\"You are a helpful assistant that translates {input_language} to {output_language}.\"\n", | |
| "system_message_prompt = SystemMessagePromptTemplate.from_template(template)\n", | |
| "human_template=\"{text}\"\n", | |
| "human_message_prompt = HumanMessagePromptTemplate.from_template(human_template)\n", | |
| "chat_prompt = ChatPromptTemplate.from_messages([system_message_prompt, human_message_prompt])\n", | |
| "\n", | |
| "chain = LLMChain(llm=chat, prompt=chat_prompt)\n", | |
| "chain.run(input_language=\"English\", output_language=\"Korean\", text=\"I love programming.\")" | |
| ], | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/", | |
| "height": 36 | |
| }, | |
| "id": "vrAR3NzIeDPV", | |
| "outputId": "947d80fa-4b0b-4fa0-98ef-28d32f862670" | |
| }, | |
| "execution_count": 42, | |
| "outputs": [ | |
| { | |
| "output_type": "execute_result", | |
| "data": { | |
| "text/plain": [ | |
| "'저는 프로그래밍을 좋아합니다.'" | |
| ], | |
| "application/vnd.google.colaboratory.intrinsic+json": { | |
| "type": "string" | |
| } | |
| }, | |
| "metadata": {}, | |
| "execution_count": 42 | |
| } | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "source": [ | |
| "### Agent\n", | |
| "\n", | |
| "구글 검색엔진과 연동해서, 구글 검색결과를 가지고 chat 돌릴 수 있음.\n", | |
| "- 검색엔진 api로는 https://serpapi.com/ 사용. 회원가입하면 100 req/month 무료" | |
| ], | |
| "metadata": { | |
| "id": "i8rzg4qmeUlh" | |
| } | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "import os\n", | |
| "os.environ[\"SERPAPI_API_KEY\"] = \"\"" | |
| ], | |
| "metadata": { | |
| "id": "2D03LdB6gvTV" | |
| }, | |
| "execution_count": 44, | |
| "outputs": [] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "from langchain.utilities import SerpAPIWrapper\n", | |
| "\n", | |
| "search = SerpAPIWrapper()\n", | |
| "search.run(\"Obama's first name?\")" | |
| ], | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/", | |
| "height": 36 | |
| }, | |
| "id": "hRHfvojEeK53", | |
| "outputId": "6bbf7222-5bb2-4662-b83d-c3fcde527191" | |
| }, | |
| "execution_count": 45, | |
| "outputs": [ | |
| { | |
| "output_type": "execute_result", | |
| "data": { | |
| "text/plain": [ | |
| "'Barack Hussein Obama II'" | |
| ], | |
| "application/vnd.google.colaboratory.intrinsic+json": { | |
| "type": "string" | |
| } | |
| }, | |
| "metadata": {}, | |
| "execution_count": 45 | |
| } | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "params = {\n", | |
| " \"engine\": \"bing\",\n", | |
| " \"gl\": \"us\",\n", | |
| " \"hl\": \"en\",\n", | |
| "}\n", | |
| "search = SerpAPIWrapper(params=params)\n", | |
| "\n", | |
| "search.run(\"Obama's first name?\")" | |
| ], | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/", | |
| "height": 161 | |
| }, | |
| "id": "aGY_9occgSDm", | |
| "outputId": "187215c4-48b4-4778-f88b-0e4c329ce727" | |
| }, | |
| "execution_count": 46, | |
| "outputs": [ | |
| { | |
| "output_type": "execute_result", | |
| "data": { | |
| "text/plain": [ | |
| "'Barack Hussein Obama II is an American former politician who served as the 44th president of the United States from 2009 to 2017. A member of the Democratic Party, he was the first African-Ame…New content will be added above the current area of focus upon selectionBarack Hussein Obama II is an American former politician who served as the 44th president of the United States from 2009 to 2017. A member of the Democratic Party, he was the first African-American president of the United States. Obama previously served as a U.S. senator representing Illinois from 2005 to 2008 and as an Illinois state senator from 1997 to 2004, and worked as a civil rights lawyer before holding public office.Wikipediabarackobama.com'" | |
| ], | |
| "application/vnd.google.colaboratory.intrinsic+json": { | |
| "type": "string" | |
| } | |
| }, | |
| "metadata": {}, | |
| "execution_count": 46 | |
| } | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "source": [ | |
| "구글 검색 도구와 수학 도구를 이용한 에이전트" | |
| ], | |
| "metadata": { | |
| "id": "axJkzJ9Jhe7l" | |
| } | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "from langchain.agents import load_tools\n", | |
| "from langchain.agents import initialize_agent\n", | |
| "from langchain.agents import AgentType\n", | |
| "from langchain.llms import OpenAI\n", | |
| "\n", | |
| "# First, let's load the language model we're going to use to control the agent.\n", | |
| "llm = OpenAI(temperature=0)\n", | |
| "\n", | |
| "# Next, let's load some tools to use. Note that the `llm-math` tool uses an LLM, so we need to pass that in.\n", | |
| "tools = load_tools([\"serpapi\", \"llm-math\"], llm=llm)\n", | |
| "\n", | |
| "# Finally, let's initialize an agent with the tools, the language model, and the type of agent we want to use.\n", | |
| "agent = initialize_agent(tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True)\n", | |
| "\n", | |
| "# Now let's test it out!\n", | |
| "agent.run(\"What was the high temperature in SF yesterday in Fahrenheit? What is that number raised to the .023 power?\")" | |
| ], | |
| "metadata": { | |
| "id": "Ptddu0Oehcf9" | |
| }, | |
| "execution_count": null, | |
| "outputs": [] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "source": [ | |
| "채팅모델을 이용한 agent" | |
| ], | |
| "metadata": { | |
| "id": "vJ4y6OCuhqbS" | |
| } | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "from langchain.agents import load_tools\n", | |
| "from langchain.agents import initialize_agent\n", | |
| "from langchain.agents import AgentType\n", | |
| "from langchain.chat_models import ChatOpenAI\n", | |
| "from langchain.llms import OpenAI\n", | |
| "\n", | |
| "# First, let's load the language model we're going to use to control the agent.\n", | |
| "chat = ChatOpenAI(temperature=0)\n", | |
| "\n", | |
| "# Next, let's load some tools to use. Note that the `llm-math` tool uses an LLM, so we need to pass that in.\n", | |
| "llm = OpenAI(temperature=0)\n", | |
| "tools = load_tools([\"serpapi\", \"llm-math\"], llm=llm)\n", | |
| "\n", | |
| "\n", | |
| "# Finally, let's initialize an agent with the tools, the language model, and the type of agent we want to use.\n", | |
| "agent = initialize_agent(tools, chat, agent=AgentType.CHAT_ZERO_SHOT_REACT_DESCRIPTION, verbose=True)\n", | |
| "\n", | |
| "# Now let's test it out!\n", | |
| "agent.run(\"Who is Olivia Wilde's boyfriend? What is his current age raised to the 0.23 power?\")" | |
| ], | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/", | |
| "height": 556 | |
| }, | |
| "id": "snusdAAaho-F", | |
| "outputId": "03286ab7-b347-4600-c85d-da40034bc8fa" | |
| }, | |
| "execution_count": 47, | |
| "outputs": [ | |
| { | |
| "output_type": "stream", | |
| "name": "stdout", | |
| "text": [ | |
| "\n", | |
| "\n", | |
| "\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n", | |
| "\u001b[32;1m\u001b[1;3mThought: I need to use a search engine to find Olivia Wilde's boyfriend and a calculator to raise his age to the 0.23 power.\n", | |
| "Action:\n", | |
| "```\n", | |
| "{\n", | |
| " \"action\": \"Search\",\n", | |
| " \"action_input\": \"Olivia Wilde boyfriend\"\n", | |
| "}\n", | |
| "```\n", | |
| "\u001b[0m\n", | |
| "Observation: \u001b[36;1m\u001b[1;3mOlivia Wilde started dating Harry Styles after ending her years-long engagement to Jason Sudeikis — see their relationship timeline.\u001b[0m\n", | |
| "Thought:\u001b[32;1m\u001b[1;3mNow I need to use a calculator to raise Harry Styles' age to the 0.23 power.\n", | |
| "Action:\n", | |
| "```\n", | |
| "{\n", | |
| " \"action\": \"Calculator\",\n", | |
| " \"action_input\": \"pow(27, 0.23)\"\n", | |
| "}\n", | |
| "```\n", | |
| "\u001b[0m\n", | |
| "Observation: \u001b[33;1m\u001b[1;3mAnswer: 2.1340945944237553\n", | |
| "\u001b[0m\n", | |
| "Thought:\u001b[32;1m\u001b[1;3mI have found the answer to the question.\n", | |
| "Final Answer: Harry Styles' current age raised to the 0.23 power is 2.1340945944237553.\u001b[0m\n", | |
| "\n", | |
| "\u001b[1m> Finished chain.\u001b[0m\n" | |
| ] | |
| }, | |
| { | |
| "output_type": "execute_result", | |
| "data": { | |
| "text/plain": [ | |
| "\"Harry Styles' current age raised to the 0.23 power is 2.1340945944237553.\"" | |
| ], | |
| "application/vnd.google.colaboratory.intrinsic+json": { | |
| "type": "string" | |
| } | |
| }, | |
| "metadata": {}, | |
| "execution_count": 47 | |
| } | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [], | |
| "metadata": { | |
| "id": "eggeB3yLhsrz" | |
| }, | |
| "execution_count": null, | |
| "outputs": [] | |
| } | |
| ] | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment